Skip to content

Commit

Permalink
added ability to send arrays as param values to create duplicate keys…
Browse files Browse the repository at this point in the history
… when generating the REST url
  • Loading branch information
zachhale committed Jul 26, 2010
1 parent 66ef655 commit 44f34f8
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions lib/rturk/requester.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Requester

class << self
include RTurk::Utilities

# @param [Hash] params
# @option [String] 'Operation' The operation - Required
# @option [String] Any Pass any other params and they will be included in the request
Expand All @@ -29,22 +29,33 @@ def request(params = {})
params.merge!(base_params)
signature = sign(credentials.secret_key, params['Service'], params['Operation'], params["Timestamp"])
params['Signature'] = signature
querystring = params.collect { |key, value| [CGI.escape(key.to_s), CGI.escape(value.to_s)].join('=') }.join('&') # order doesn't matter for the actual request

querystring = params.inject([]) do |pairs, (key, value)|
if value.respond_to?(:each)
value.each do |multi_value|
pairs << [CGI.escape(key.to_s), CGI.escape(multi_value.to_s)].join('=')
end
else
pairs << [CGI.escape(key.to_s), CGI.escape(value.to_s)].join('=')
end
pairs
end.join('&') # order doesn't matter for the actual request

RTurk.logger.debug "Sending request:\n\t #{credentials.host}?#{querystring}"
RestClient.get("#{credentials.host}?#{querystring}")
end

def sign(secret_key, service,method,time)
msg = "#{service}#{method}#{time}"
return hmac_sha1(secret_key, msg )
end


private

def credentials
RTurk
end

def sign(secret_key, service,method,time)
msg = "#{service}#{method}#{time}"
return hmac_sha1(secret_key, msg )
end

def hmac_sha1(key, s)
ipad = [].fill(0x36, 0, 64)
opad = [].fill(0x5C, 0, 64)
Expand All @@ -64,7 +75,7 @@ def hmac_sha1(key, s)
end
end
end

def self.Request(*args)
RTurk::Requester.request(*args)
end
Expand Down

0 comments on commit 44f34f8

Please sign in to comment.