Class: Chimps::QueryRequest
- Defined in:
- lib/chimps/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_if_necessary! ⇒ Object
Authenticate this request by stuffing the
:requested_atand:apikeyproperties into its:query_paramshash. -
#host ⇒ String
The host to send requests to.
-
#sign(string) ⇒ String
Sign
stringby concatenting it with the secret and computing the MD5 digest of the whole thing. -
#signed_query_string ⇒ String
Append the signature to the unsigned query string.
Methods inherited from Request
#authenticate?, #delete, #get, #initialize, #post, #put, #query_string, #url_with_query_string
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)?
252 253 254 |
# File 'lib/chimps/request.rb', line 252 def authenticable? !Chimps::CONFIG[:query][:key].blank? && !Chimps::CONFIG[:query][:secret].blank? 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.
269 270 271 272 273 274 |
# File 'lib/chimps/request.rb', line 269 def authenticate_if_necessary! return unless authenticate? raise Chimps::AuthenticationError.new("API key or secret missing from #{CONFIG[:identity_file]}") unless (authenticable? || @forgive_authentication_error) 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.
259 260 261 |
# File 'lib/chimps/request.rb', line 259 def host @host ||= Chimps::CONFIG[:query][:host] end |
#sign(string) ⇒ String
Sign string by concatenting it with the secret and computing the MD5 digest of the whole thing.
281 282 283 284 285 |
# File 'lib/chimps/request.rb', line 281 def sign string raise Chimps::AuthenticationError.new("No API secret stored in #{CONFIG[:identity_file]}.") unless (authenticable? || @forgive_authentication_error) require 'digest/md5' Digest::MD5.hexdigest(string + CONFIG[:key][:secret]) 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.
295 296 297 |
# File 'lib/chimps/request.rb', line 295 def signed_query_string unsigned_query_string end |