Class: RestClient::Response
- Inherits:
-
Object
- Object
- RestClient::Response
- Defined in:
- lib/FbRuby/utils.rb
Instance Method Summary collapse
-
#body(decompress = true) ⇒ Object
include RestClient::AbstractResponse.
- #json ⇒ Object
- #ok? ⇒ Boolean
- #parse_html ⇒ Object
- #parse_xml ⇒ Object
- #to_s ⇒ Object
Instance Method Details
#body(decompress = true) ⇒ Object
include RestClient::AbstractResponse
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/FbRuby/utils.rb', line 25 def body(decompress = true) encoding = self.headers[:content_encoding] response = String.new(self) if encoding == "gzip" and decompress and !response.empty? return Zlib::GzipReader.new(StringIO.new(response)).read elsif encoding == "deflate" and decompress and !response.empty? return Zlib::Inflate.inflate(response) else return response end end |
#json ⇒ Object
58 59 60 |
# File 'lib/FbRuby/utils.rb', line 58 def json return JSON.parse(body) end |
#ok? ⇒ Boolean
42 43 44 45 46 47 48 |
# File 'lib/FbRuby/utils.rb', line 42 def ok? if (400..500).to_a.member? (code) return false else return true end end |
#parse_html ⇒ Object
50 51 52 |
# File 'lib/FbRuby/utils.rb', line 50 def parse_html return Nokogiri::HTML(body) end |
#parse_xml ⇒ Object
54 55 56 |
# File 'lib/FbRuby/utils.rb', line 54 def parse_xml return Nokogiri::XML(body) end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/FbRuby/utils.rb', line 38 def to_s return body end |