Sha256: 107153743858ec62f3f845b925bc0b90e940ac09ea665aca9f266fdc162f9143

Contents?: true

Size: 1.7 KB

Versions: 1043

Compression:

Stored size: 1.7 KB

Contents

require 'base64'

module Aws
  module Query
    class EC2ParamBuilder

      include Seahorse::Model::Shapes

      def initialize(param_list)
        @params = param_list
      end

      attr_reader :params

      def apply(ref, params)
        structure(ref, params, '')
      end

      private

      def structure(ref, values, prefix)
        shape = ref.shape
        values.each_pair do |name, value|
          unless value.nil?
            member_ref = shape.member(name)
            format(member_ref, value, prefix + query_name(member_ref))
          end
        end
      end

      def list(ref, values, prefix)
        if values.empty?
          set(prefix, '')
        else
          member_ref = ref.shape.member
          values.each.with_index do |value, n|
            format(member_ref, value, "#{prefix}.#{n+1}")
          end
        end
      end

      def format(ref, value, prefix)
        case ref.shape
        when StructureShape then structure(ref, value, prefix + '.')
        when ListShape      then list(ref, value, prefix)
        when MapShape       then raise NotImplementedError
        when BlobShape      then set(prefix, blob(value))
        when TimestampShape then set(prefix, timestamp(value))
        else
          set(prefix, value.to_s)
        end
      end

      def query_name(ref)
        ref['queryName'] || ucfirst(ref.location_name)
      end

      def set(name, value)
        params.set(name, value)
      end

      def ucfirst(str)
        str[0].upcase + str[1..-1]
      end

      def blob(value)
        value = value.read unless String === value
        Base64.strict_encode64(value)
      end

      def timestamp(value)
        value.utc.iso8601
      end

    end
  end
end

Version data entries

1,043 entries across 1,043 versions & 2 rubygems

Version Path
aws-sdk-core-2.11.632 lib/aws-sdk-core/query/ec2_param_builder.rb
aws-sdk-core-2.11.631 lib/aws-sdk-core/query/ec2_param_builder.rb
aws-sdk-core-2.11.630 lib/aws-sdk-core/query/ec2_param_builder.rb
aws-sdk-core-2.11.629 lib/aws-sdk-core/query/ec2_param_builder.rb
aws-sdk-core-2.11.628 lib/aws-sdk-core/query/ec2_param_builder.rb
aws-sdk-core-2.11.627 lib/aws-sdk-core/query/ec2_param_builder.rb
aws-sdk-core-2.11.626 lib/aws-sdk-core/query/ec2_param_builder.rb
aws-sdk-core-2.11.625 lib/aws-sdk-core/query/ec2_param_builder.rb
aws-sdk-core-2.11.624 lib/aws-sdk-core/query/ec2_param_builder.rb
aws-sdk-core-2.11.623 lib/aws-sdk-core/query/ec2_param_builder.rb
aws-sdk-core-2.11.622 lib/aws-sdk-core/query/ec2_param_builder.rb
aws-sdk-core-2.11.621 lib/aws-sdk-core/query/ec2_param_builder.rb
aws-sdk-core-2.11.620 lib/aws-sdk-core/query/ec2_param_builder.rb
aws-sdk-core-2.11.619 lib/aws-sdk-core/query/ec2_param_builder.rb
aws-sdk-core-2.11.618 lib/aws-sdk-core/query/ec2_param_builder.rb
aws-sdk-core-2.11.617 lib/aws-sdk-core/query/ec2_param_builder.rb
aws-sdk-core-2.11.616 lib/aws-sdk-core/query/ec2_param_builder.rb
aws-sdk-core-2.11.615 lib/aws-sdk-core/query/ec2_param_builder.rb
aws-sdk-core-2.11.614 lib/aws-sdk-core/query/ec2_param_builder.rb
aws-sdk-core-2.11.613 lib/aws-sdk-core/query/ec2_param_builder.rb