class Aws::Rest::Request::QuerystringBuilder

Public Instance Methods

build(params) click to toggle source

Provide shape references and param values:

[
  [shape_ref1, 123],
  [shape_ref2, "text"]
]

Returns a querystring:

"Count=123&Words=text"

@param [Array<Array<Seahorse::Model::ShapeRef, Object>>] params An array of

model shape references and request parameter value pairs.

@return [String] Returns a built querystring

# File lib/aws-sdk-core/rest/request/querystring_builder.rb, line 25
def build(params)
  params.map do |(shape_ref, param_value)|
    build_part(shape_ref, param_value)
  end.join('&')
end

Private Instance Methods

build_part(shape_ref, param_value) click to toggle source
# File lib/aws-sdk-core/rest/request/querystring_builder.rb, line 33
def build_part(shape_ref, param_value)
  case shape_ref.shape
  # supported scalar types
  when StringShape, BooleanShape, FloatShape, IntegerShape, StringShape
    param_name = shape_ref.location_name
    "#{param_name}=#{escape(param_value.to_s)}"
  when TimestampShape
    param_name = shape_ref.location_name
    "#{param_name}=#{escape(timestamp(shape_ref, param_value))}"
  when MapShape
    if StringShape === shape_ref.shape.value.shape
      query_map_of_string(param_value)
    elsif ListShape === shape_ref.shape.value.shape
      query_map_of_string_list(param_value)
    else
      msg = "only map of string and string list supported"
      raise NotImplementedError, msg
    end
  when ListShape
    if StringShape === shape_ref.shape.member.shape
      list_of_strings(shape_ref.location_name, param_value)
    else
      msg = "Only list of strings supported, got "\
            "#{shape_ref.shape.member.shape.class.name}"
      raise NotImplementedError, msg
    end
  else
    raise NotImplementedError
  end
end
escape(string) click to toggle source
# File lib/aws-sdk-core/rest/request/querystring_builder.rb, line 98
def escape(string)
  Seahorse::Util.uri_escape(string)
end
list_of_strings(name, values) click to toggle source
# File lib/aws-sdk-core/rest/request/querystring_builder.rb, line 92
def list_of_strings(name, values)
  values.map do |value|
    "#{name}=#{escape(value)}"
  end
end
query_map_of_string(hash) click to toggle source
# File lib/aws-sdk-core/rest/request/querystring_builder.rb, line 74
def query_map_of_string(hash)
  list = []
  hash.each_pair do |key, value|
    list << "#{escape(key)}=#{escape(value)}"
  end
  list
end
query_map_of_string_list(hash) click to toggle source
# File lib/aws-sdk-core/rest/request/querystring_builder.rb, line 82
def query_map_of_string_list(hash)
  list = []
  hash.each_pair do |key, values|
    values.each do |value|
      list << "#{escape(key)}=#{escape(value)}"
    end
  end
  list
end
timestamp(ref, value) click to toggle source
# File lib/aws-sdk-core/rest/request/querystring_builder.rb, line 64
def timestamp(ref, value)
  case ref['timestampFormat'] || ref.shape['timestampFormat']
  when 'unixTimestamp' then value.to_i
  when 'rfc822' then value.utc.httpdate
  else
    # querystring defaults to iso8601
    value.utc.iso8601
  end
end