Class: Elmas::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/elmas/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Parser

Returns a new instance of Parser.



7
8
9
10
11
12
13
# File 'lib/elmas/parser.rb', line 7

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.message}"
  @error_message = "#{e.class}: #{e.message}"
end

Instance Attribute Details

#parsed_jsonObject

Returns the value of attribute parsed_json.



5
6
7
# File 'lib/elmas/parser.rb', line 5

def parsed_json
  @parsed_json
end

Instance Method Details

#error_messageObject



31
32
33
34
35
# File 'lib/elmas/parser.rb', line 31

def error_message
  @error_message ||= begin
    parsed_json["error"]["message"]["value"] if parsed_json["error"]
  end
end

#first_resultObject



37
38
39
# File 'lib/elmas/parser.rb', line 37

def first_result
  results[0]
end

#metadataObject



19
20
21
# File 'lib/elmas/parser.rb', line 19

def 
  result["__metadata"] if result && result["__metadata"]
end

#next_page_urlObject



27
28
29
# File 'lib/elmas/parser.rb', line 27

def next_page_url
  result && result["__next"]
end

#resultObject



23
24
25
# File 'lib/elmas/parser.rb', line 23

def result
  parsed_json["d"]
end

#resultsObject



15
16
17
# File 'lib/elmas/parser.rb', line 15

def results
  result["results"] if result && result["results"]
end