Class: LiveAPI::Search::Response
- Inherits:
-
Object
- Object
- LiveAPI::Search::Response
- Defined in:
- lib/live-search/response.rb
Instance Method Summary collapse
-
#initialize(response_body) ⇒ Response
constructor
A new instance of Response.
-
#results ⇒ Object
The result objects returned from the request.
- #to_json ⇒ Object
-
#total ⇒ Object
The number of URLs returned.
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
#results ⇒ Object
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_json ⇒ Object
24 25 26 |
# File 'lib/live-search/response.rb', line 24 def to_json @json = @json ||= JSON.parse(@body) end |
#total ⇒ Object
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 |