Method: Bone::API::HTTP.canonical_sig_string
- Defined in:
- lib/bone/api.rb
.canonical_sig_string(host, meth, path, query, body = nil) ⇒ Object
Builds the canonical string for signing requests. This strips out all ‘&’, ‘?’, and ‘=’ from the query string to be signed. The parameters in the path passed in must already be sorted in case-insensitive alphabetical order and must not be url encoded.
Based on / stolen from: github.com/grempe/amazon-ec2/blob/master/lib/AWS.rb
See also: docs.amazonwebservices.com/AWSEC2/2009-04-04/DeveloperGuide/index.html?using-query-api.html
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/bone/api.rb', line 215 def canonical_sig_string host, meth, path, query, body=nil # Sort, and encode parameters into a canonical string. sorted_params = query.sort {|x,y| x[0].to_s <=> y[0].to_s } encoded_params = sorted_params.collect do |p| encoded = [Bone.uri_escape(p[0]), Bone.uri_escape(p[1])].join '=' # Ensure spaces are encoded as '%20', not '+' encoded = encoded.gsub '+', '%20' # According to RFC3986 (the scheme for values expected # by signing requests), '~' should not be encoded encoded = encoded.gsub '%7E', '~' end querystr = encoded_params.join '&' parts = [meth.to_s.downcase, canonical_host(host), path, querystr] parts << body unless body.to_s.empty? parts.join "\n" end |