Class: UriSigner::QueryHashParser
- Inherits:
-
Object
- Object
- UriSigner::QueryHashParser
- Defined in:
- lib/uri_signer/query_hash_parser.rb
Overview
This object takes in a hash, most likely from Rack::Utils.parse_query, and transforms it into a query string that’s used for signing requests. It takes a hash, transforms the hash into a query string that has it’s parts ordered accordingly.
Instance Method Summary collapse
-
#initialize(query_hash) ⇒ void
constructor
Creates a new QueryHashParser instance.
-
#to_s ⇒ String
Returns the hash (key/values) as an ordered query string.
Constructor Details
#initialize(query_hash) ⇒ void
Creates a new QueryHashParser instance
18 19 20 21 22 |
# File 'lib/uri_signer/query_hash_parser.rb', line 18 def initialize(query_hash) @query_hash = query_hash raise UriSigner::Errors::MissingQueryHashError.new('Please provide a query string hash') unless query_hash? end |
Instance Method Details
#to_s ⇒ String
Returns the hash (key/values) as an ordered query string. This joins the keys and values, and then joins it all with the ampersand. This is not escaped
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/uri_signer/query_hash_parser.rb', line 28 def to_s parts = @query_hash.sort.inject([]) do |arr, (key,value)| if value.kind_of?(Array) value.each do |nested| arr << "%s=%s" % [key, nested] end else arr << "%s=%s" % [key, value] end arr end parts.join('&') end |