Class: Eol::Parser
- Inherits:
-
Object
- Object
- Eol::Parser
- Defined in:
- lib/eol/parser.rb
Instance Attribute Summary collapse
-
#parsed_json ⇒ Object
Returns the value of attribute parsed_json.
Instance Method Summary collapse
- #error_message ⇒ Object
- #first_result ⇒ Object
-
#initialize(json) ⇒ Parser
constructor
A new instance of Parser.
- #metadata ⇒ Object
- #next_page_url ⇒ Object
- #result ⇒ Object
- #results ⇒ Object
Constructor Details
#initialize(json) ⇒ Parser
Returns a new instance of Parser.
7 8 9 10 11 12 13 14 |
# File 'lib/eol/parser.rb', line 7 def initialize(json) @parsed_json = JSON.parse(json) rescue JSON::ParserError => e Eol.error "There was an error parsing the response" Eol.error "#{e.class}: #{e.}" @parsed_json = "" @error_message = "" end |
Instance Attribute Details
#parsed_json ⇒ Object
Returns the value of attribute parsed_json.
5 6 7 |
# File 'lib/eol/parser.rb', line 5 def parsed_json @parsed_json end |
Instance Method Details
#error_message ⇒ Object
32 33 34 35 36 |
# File 'lib/eol/parser.rb', line 32 def @error_message ||= begin parsed_json["error"]["message"]["value"] if parsed_json["error"] end end |
#first_result ⇒ Object
38 39 40 |
# File 'lib/eol/parser.rb', line 38 def first_result results[0] end |
#metadata ⇒ Object
20 21 22 |
# File 'lib/eol/parser.rb', line 20 def result["__metadata"] if result && result["__metadata"] end |
#next_page_url ⇒ Object
28 29 30 |
# File 'lib/eol/parser.rb', line 28 def next_page_url result && result["__next"] end |
#result ⇒ Object
24 25 26 |
# File 'lib/eol/parser.rb', line 24 def result parsed_json["d"] end |
#results ⇒ Object
16 17 18 |
# File 'lib/eol/parser.rb', line 16 def results result["results"] if result && result["results"] end |