Class: Yahoo::SE::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/yahoo-se/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(response_body) ⇒ Response

Returns a new instance of Response.



4
5
6
# File 'lib/yahoo-se/response.rb', line 4

def initialize(response_body)
  @body = response_body
end

Instance Method Details

#errorsObject



31
32
33
34
35
36
# File 'lib/yahoo-se/response.rb', line 31

def errors
  @errors = self.to_json["Error"]
  if @errors
    raise ResponseError, @errors
  end
end

#resultsObject

The result objects returned from the request



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/yahoo-se/response.rb', line 19

def results
  unless errors
    if total_results_available == 1
      [Yahoo::SE::Result.new(self.to_json["ResultSet"]["Result"])]
    else
      self.to_json["ResultSet"]["Result"].map do |result_hash|
        Yahoo::SE::Result.new(result_hash)
      end
    end
  end
end

#to_jsonObject



38
39
40
# File 'lib/yahoo-se/response.rb', line 38

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

#total_results_availableObject

The number of URLs in the database that link to the domain or page.



14
15
16
# File 'lib/yahoo-se/response.rb', line 14

def total_results_available
  self.to_json["ResultSet"]["totalResultsAvailable"].to_i
end

#total_results_returnedObject

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/yahoo-se/response.rb', line 9

def total_results_returned
  self.to_json["ResultSet"]["totalResultsReturned"].to_i
end