Class: Yahoo::SE::Request
- Inherits:
-
Object
- Object
- Yahoo::SE::Request
- Defined in:
- lib/yahoo-se/request.rb
Class Method Summary collapse
-
.hash_to_query(hash) ⇒ Object
Converts a hash to a query string.
Instance Method Summary collapse
-
#initialize(service_path, options) ⇒ Request
constructor
A new instance of Request.
-
#path ⇒ Object
The API URL call.
-
#response ⇒ Object
The response object of the request.
-
#response_body ⇒ Object
The response body of the request.
-
#results ⇒ Object
The results from the response object.
Constructor Details
#initialize(service_path, options) ⇒ Request
Returns a new instance of Request.
13 14 15 16 17 18 19 |
# File 'lib/yahoo-se/request.rb', line 13 def initialize(service_path, ) @service_path = service_path @options = @options[:appid] = Yahoo::SE.application_id @options[:output] = "json" @query_string = self.class.hash_to_query(@options) end |
Class Method Details
.hash_to_query(hash) ⇒ Object
Converts a hash to a query string
9 10 11 |
# File 'lib/yahoo-se/request.rb', line 9 def self.hash_to_query(hash) hash.map {|key, value| "#{key}=#{value}"}.join("&") end |
Instance Method Details
#path ⇒ Object
The API URL call
22 23 24 |
# File 'lib/yahoo-se/request.rb', line 22 def path "#{@service_path}?#{@query_string}" end |
#response ⇒ Object
The response object of the request
27 28 29 |
# File 'lib/yahoo-se/request.rb', line 27 def response @response ||= Yahoo::SE::Response.new(response_body) end |
#response_body ⇒ Object
The response body of the request
32 33 34 35 36 37 38 |
# File 'lib/yahoo-se/request.rb', line 32 def response_body begin @response_body = open(path,"User-Agent" => "Ruby/Yahoo Site Explorer Gem v#{Yahoo::SE::VERSION}").readlines.join rescue OpenURI::HTTPError => @errors raise ResponseError, @errors end end |
#results ⇒ Object
The results from the response object
41 42 43 |
# File 'lib/yahoo-se/request.rb', line 41 def results response.results end |