Sha256: 6779342fea09181230e696caad539d4ef0d6ceadf66abd0c03938ad418ae6d20

Contents?: true

Size: 808 Bytes

Versions: 1

Compression:

Stored size: 808 Bytes

Contents

require "mws/query_string/uri_encoder"

module MWS
  class QueryString < ::String
    class RequestString < ::String
      def initialize(args)
        @method   = args[:method]
        @endpoint = args[:endpoint]
        @path     = args[:path]
        @params   = args[:params]

        super(request_string)
      end

      private

      def sorted_params
        Hash[@params.sort_by{|param| param[0] }]
      end

      def encoded_params
        encoder = MWS::QueryString::UriEncoder.new
        Hash[sorted_params.map{|pair| pair.map{|elm| encoder.encode(elm.to_s) } } ]
      end

      def request_string
        [
          @method.to_s.upcase,
          @endpoint,
          @path,
          encoded_params.map{|pair| pair.join("=") }.join("&")
        ].join("\n")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
marketplace_web_service-0.0.3 lib/mws/query_string/request_string.rb