Module: AmazonFlexPay::Util
Constant Summary collapse
- UNSAFE =
:nodoc:
/[^A-Za-z0-9_.~-]/
Instance Method Summary collapse
-
#escape(value) ⇒ Object
Amazon is very specific about which chars should be escaped, and which should not.
-
#query_string(params, prefix = nil) ⇒ Object
Flattens a possibly-nested hash into a query string for Amazon.
Instance Method Details
#escape(value) ⇒ Object
Amazon is very specific about which chars should be escaped, and which should not.
23 24 25 26 |
# File 'lib/amazon_flex_pay/util.rb', line 23 def escape(value) #:nodoc: # note that URI.escape(' ') => '%20', and CGI.escape(' ') => '+' URI.escape(value.to_s, UNSAFE) end |
#query_string(params, prefix = nil) ⇒ Object
Flattens a possibly-nested hash into a query string for Amazon. With Amazon, nested hashes are flattened with a period, as follows:
AmazonFlexPay::Util.query_string(:foo => {:hello => 'world'})
=> "foo.hello=world"
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/amazon_flex_pay/util.rb', line 9 def query_string(params, prefix = nil) #:nodoc: prefix = "#{prefix}." if prefix params.keys.sort { |a, b| a.to_s <=> b.to_s }.collect do |key| case val = params[key] when Hash query_string(val, key) else "#{prefix}#{key}=#{escape val}" end end.join('&') end |