Class: Eol::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/eol/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
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.message}"
  @parsed_json = ""
  @error_message = ""
end

Instance Attribute Details

#parsed_jsonObject

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_messageObject



32
33
34
35
36
# File 'lib/eol/parser.rb', line 32

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

#first_resultObject



38
39
40
# File 'lib/eol/parser.rb', line 38

def first_result
  results[0]
end

#metadataObject



20
21
22
# File 'lib/eol/parser.rb', line 20

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

#next_page_urlObject



28
29
30
# File 'lib/eol/parser.rb', line 28

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

#resultObject



24
25
26
# File 'lib/eol/parser.rb', line 24

def result
  parsed_json["d"]
end

#resultsObject



16
17
18
# File 'lib/eol/parser.rb', line 16

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