diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rbot/core/utils/httputil.rb | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/rbot/core/utils/httputil.rb b/lib/rbot/core/utils/httputil.rb index f7871e5b..e629becb 100644 --- a/lib/rbot/core/utils/httputil.rb +++ b/lib/rbot/core/utils/httputil.rb @@ -29,6 +29,12 @@ rescue LoadError => e EOC end +begin + require 'nokogiri' +rescue LoadError => e + error "No nokogiri library found, some features might not be available!" +end + # To handle Gzipped pages require 'stringio' require 'zlib' @@ -163,6 +169,15 @@ module ::Net return self.body_to_utf(self.decompress_body(partial)) end + + def xpath(path) + document = Nokogiri::HTML.parse(self.body) + document.xpath(path) + end + + def to_json + JSON::parse(self.body) + end end end @@ -649,7 +664,11 @@ class HttpUtil resp = get_response(uri, options, &block) raise "http error: #{resp}" unless Net::HTTPOK === resp || Net::HTTPPartialContent === resp - return resp.body + if options[:resp] + return resp + else + return resp.body + end rescue Exception => e error e end |