Class: RestClient::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/FbRuby/utils.rb

Instance Method Summary collapse

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

#jsonObject



58
59
60
# File 'lib/FbRuby/utils.rb', line 58

def json
  return JSON.parse(body)
end

#ok?Boolean

Returns:

  • (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_htmlObject



50
51
52
# File 'lib/FbRuby/utils.rb', line 50

def parse_html
  return Nokogiri::HTML(body)
end

#parse_xmlObject



54
55
56
# File 'lib/FbRuby/utils.rb', line 54

def parse_xml
  return Nokogiri::XML(body)
end

#to_sObject



38
39
40
# File 'lib/FbRuby/utils.rb', line 38

def to_s
  return body
end