Sha256: 67313cdd057915821fb18cce0c06c83bbf8cc907c10bc9990bacf0510a03ea96

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

require 'delegate'
require 'time'

require 'peddler/request/structured_list'

module Peddler
  class Request
    class Parameters < SimpleDelegator
      def initialize(action)
        super({ 'Action' => camelize(action) })
      end

      def timestamp!
        each do |key, value|
          store(key, value.iso8601) if value.respond_to?(:iso8601)
        end

        self
      end

      def format_structured_lists!
        lists = {}

        each do |key, value|
          if StructuredList.handle?(key)
            list = StructuredList.new(key).build(delete(key))
            lists.update(list)
          end
        end

        update(lists)
      end

      def camelize_keys!
        keys.each do |key|
          if key.is_a?(Symbol)
            new_key = camelize(key)
            store(new_key, delete(key))
          end
        end

        self
      end

      def update(hsh)
        __getobj__.update(hsh)
        self
      end

      private

      def camelize(sym)
        sym.to_s.split('_').map(&:capitalize).join
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
peddler-0.6.5 lib/peddler/request/parameters.rb
peddler-0.6.4 lib/peddler/request/parameters.rb