Class: RFb::Parser
- Inherits:
-
Object
- Object
- RFb::Parser
- Defined in:
- lib/r_fb/parser.rb
Instance Attribute Summary collapse
-
#doc ⇒ Object
Returns the value of attribute doc.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(response) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(response) ⇒ Parser
Returns a new instance of Parser.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/r_fb/parser.rb', line 16 def initialize(response) @doc = JSON.parse(response.body) case response when Net::HTTPSuccess else raise "Parser - Net::HTTP - not yet handled error: #{@doc.inspect}" #raise( { code: error_code, message: @doc.xpath("//error_msg").text }.inspect ) end end |
Instance Attribute Details
#doc ⇒ Object
Returns the value of attribute doc.
4 5 6 |
# File 'lib/r_fb/parser.rb', line 4 def doc @doc end |
Class Method Details
.parse(response) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/r_fb/parser.rb', line 6 def self.parse(response) parser = Parser.new(response) if parser.doc.is_a?(Hash) && !parser.doc["error_code"].nil? raise( { code: parser.doc["error_code"], message: parser.doc["error_msg"] }.inspect ) end parser.doc.first end |