Class: Chimps::QueryRequest
- Defined in:
- lib/chimps/query_request.rb
Overview
A class to encapsulate requests made against the Infochimps paid query API.
Constant Summary
Constants inherited from Request
Instance Attribute Summary
Attributes inherited from Request
Instance Method Summary collapse
-
#authenticable? ⇒ true, false
Is this request authentiable (has the Chimps user specified an API key and secret in their configuration file)?.
-
#authenticate? ⇒ true
All Query API requests must be signed.
-
#authenticate_if_necessary! ⇒ Object
Authenticate this request by stuffing the
:requested_at
and:apikey
properties into its:query_params
hash. -
#host ⇒ String
The host to send requests to.
-
#signed_query_string ⇒ String
Append the signature to the unsigned query string.
- #url_with_query_string ⇒ Object
Methods inherited from Request
#base_url, #delete, #encode, #encoded_body, #get, #handle_exceptions, #initialize, #obj_to_stripped_string, #post, #put, #query_string, #raw?, #should_encode?, #sign, #unsigned_query_string, #unsigned_query_string_stripped
Constructor Details
This class inherits a constructor from Chimps::Request
Instance Method Details
#authenticable? ⇒ true, false
Is this request authentiable (has the Chimps user specified an API key and secret in their configuration file)?
11 12 13 |
# File 'lib/chimps/query_request.rb', line 11 def authenticable? Chimps.config[:query][:key] end |
#authenticate? ⇒ true
All Query API requests must be signed.
37 38 39 |
# File 'lib/chimps/query_request.rb', line 37 def authenticate? return true end |
#authenticate_if_necessary! ⇒ Object
Authenticate this request by stuffing the :requested_at
and :apikey
properties into its :query_params
hash.
Will do nothing at all if Chimps::Request#authenticate? returns false.
47 48 49 50 51 52 |
# File 'lib/chimps/query_request.rb', line 47 def authenticate_if_necessary! return unless authenticate? && should_encode? raise Chimps::AuthenticationError.new("Query API key (Chimps.config[:query][:key]) from #{Chimps.config[:config]} or #{Chimps.config[:site_config]}") unless authenticable? query_params[:requested_at] = Time.now.to_i.to_s query_params[:apikey] = Chimps.config[:query][:key] end |
#host ⇒ String
The host to send requests to.
30 31 32 |
# File 'lib/chimps/query_request.rb', line 30 def host @host ||= Chimps.config[:query][:host] end |
#signed_query_string ⇒ String
Append the signature to the unsigned query string.
The signature made from the Chimps user’s API secret and either the query string text (stripped of &
and =
) for GET and DELETE requests or the request body for POST and PUT requests.
62 63 64 |
# File 'lib/chimps/query_request.rb', line 62 def signed_query_string unsigned_query_string end |
#url_with_query_string ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/chimps/query_request.rb', line 15 def url_with_query_string qs = (query_string && query_string.size > 0 ? query_string : nil) case when qs.nil? base_url when base_url.include?("?") base_url + "&#{qs}" else base_url + "?#{qs}" end end |