Class: Elmas::Parser
- Inherits:
-
Object
- Object
- Elmas::Parser
- Defined in:
- lib/elmas/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.
5 6 7 8 9 10 11 |
# File 'lib/elmas/parser.rb', line 5 def initialize(json) @parsed_json = JSON.parse(json) rescue JSON::ParserError => e Elmas.error "There was an error parsing the response" Elmas.error "#{e.class}: #{e.}" @error_message = "#{e.class}: #{e.}" end |
Instance Attribute Details
#parsed_json ⇒ Object
Returns the value of attribute parsed_json.
3 4 5 |
# File 'lib/elmas/parser.rb', line 3 def parsed_json @parsed_json end |
Instance Method Details
#error_message ⇒ Object
29 30 31 32 33 |
# File 'lib/elmas/parser.rb', line 29 def @error_message ||= begin parsed_json["error"]["message"]["value"] if parsed_json["error"] end end |
#first_result ⇒ Object
35 36 37 |
# File 'lib/elmas/parser.rb', line 35 def first_result results[0] end |
#metadata ⇒ Object
17 18 19 |
# File 'lib/elmas/parser.rb', line 17 def result["__metadata"] if result && result["__metadata"] end |
#next_page_url ⇒ Object
25 26 27 |
# File 'lib/elmas/parser.rb', line 25 def next_page_url result && result["__next"] end |
#result ⇒ Object
21 22 23 |
# File 'lib/elmas/parser.rb', line 21 def result parsed_json["d"] end |
#results ⇒ Object
13 14 15 |
# File 'lib/elmas/parser.rb', line 13 def results result["results"] if result && result["results"] end |