Class: Amazon::Coral::QueryStringMap

Inherits:
Hash show all
Defined in:
lib/amazon/coral/querystringmap.rb

Overview

A hash containing query string parameters that produces a query string via to_s. Also consumes hashes representing hierarchies of data to encode as query parameters.

Instance Method Summary collapse

Methods inherited from Hash

#from_json, #to_json

Constructor Details

#initialize(hash = {}) ⇒ QueryStringMap

Instantiate a QueryStringMap with the contents of the specified hash. If no hash is provided, an empty map is created.



16
17
18
# File 'lib/amazon/coral/querystringmap.rb', line 16

def initialize(hash = {})
  add_flattened(hash)
end

Instance Method Details

#to_sObject

Returns the query string representation of this map by collapsing its key-value pairs into URL parameters.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/amazon/coral/querystringmap.rb', line 22

def to_s
  qstr = ''
  isFirst = true
  each_pair { |k,v|
    if isFirst then
      isFirst = false
    else
      qstr << '&'
    end
    qstr << UrlEncoding.encode(k.to_s)
    unless(v.nil?) then
      qstr << '='
      qstr << UrlEncoding.encode(v.to_s)
    end
  }
  return qstr
end