Class: LiveAPI::Search::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/live-search/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(response_body) ⇒ Response

Returns a new instance of Response.



4
5
6
# File 'lib/live-search/response.rb', line 4

def initialize(response_body)
  @body = response_body
end

Instance Method Details

#resultsObject

The result objects returned from the request



14
15
16
17
18
19
20
21
22
# File 'lib/live-search/response.rb', line 14

def results
  begin
    self.to_json["SearchResponse"]["Web"]["Results"].map do |result_hash|
      LiveAPI::Search::Result.new(result_hash)
    end
  rescue
    self.to_json["SearchResponse"]
  end
end

#to_jsonObject



24
25
26
# File 'lib/live-search/response.rb', line 24

def to_json
  @json = @json ||= JSON.parse(@body)
end

#totalObject

The number of URLs returned. This may be lower than the number of results requested if there were fewer total results available.



9
10
11
# File 'lib/live-search/response.rb', line 9

def total
  self.to_json["SearchResponse"]["Web"]["Total"].to_i
end