Sha256: d9782f021a6e8ce165a810074fbf87fd5f990b2299a95cfa482e962c26c223ca

Contents?: true

Size: 1.49 KB

Versions: 1160

Compression:

Stored size: 1.49 KB

Contents

module Aws
  module Rest
    module Request
      class Body

        include Seahorse::Model::Shapes

        # @param [Class] serializer_class
        # @param [Seahorse::Model::ShapeRef] rules
        def initialize(serializer_class, rules)
          @serializer_class = serializer_class
          @rules = rules
        end

        # @param [Seahorse::Client::Http::Request] http_req
        # @param [Hash] params
        def apply(http_req, params)
          http_req.body = build_body(params)
        end

        private

        def build_body(params)
          if streaming?
            params[@rules[:payload]]
          elsif @rules[:payload]
            params = params[@rules[:payload]]
            serialize(@rules[:payload_member], params) if params
          else
            params = body_params(params)
            serialize(@rules, params) unless params.empty?
          end
        end

        def streaming?
          @rules[:payload] && (
            BlobShape === @rules[:payload_member].shape ||
            StringShape === @rules[:payload_member].shape
          )
        end

        def serialize(rules, params)
          @serializer_class.new(rules).serialize(params)
        end

        def body_params(params)
          @rules.shape.members.inject({}) do |hash, (member_name, member_ref)|
            if !member_ref.location && params.key?(member_name)
              hash[member_name] = params[member_name]
            end
            hash
          end
        end

      end
    end
  end
end

Version data entries

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

Version Path
aws-sdk-core-2.11.592 lib/aws-sdk-core/rest/request/body.rb
aws-sdk-core-2.11.591 lib/aws-sdk-core/rest/request/body.rb
aws-sdk-core-2.11.590 lib/aws-sdk-core/rest/request/body.rb
aws-sdk-core-2.11.589 lib/aws-sdk-core/rest/request/body.rb
aws-sdk-core-2.11.588 lib/aws-sdk-core/rest/request/body.rb
aws-sdk-core-2.11.587 lib/aws-sdk-core/rest/request/body.rb
aws-sdk-core-2.11.586 lib/aws-sdk-core/rest/request/body.rb
aws-sdk-core-2.11.585 lib/aws-sdk-core/rest/request/body.rb
aws-sdk-core-2.11.584 lib/aws-sdk-core/rest/request/body.rb
aws-sdk-core-2.11.583 lib/aws-sdk-core/rest/request/body.rb
aws-sdk-core-2.11.582 lib/aws-sdk-core/rest/request/body.rb
aws-sdk-core-2.11.581 lib/aws-sdk-core/rest/request/body.rb
aws-sdk-core-2.11.580 lib/aws-sdk-core/rest/request/body.rb
aws-sdk-core-2.11.579 lib/aws-sdk-core/rest/request/body.rb
aws-sdk-core-2.11.578 lib/aws-sdk-core/rest/request/body.rb
aws-sdk-core-2.11.577 lib/aws-sdk-core/rest/request/body.rb
aws-sdk-core-2.11.576 lib/aws-sdk-core/rest/request/body.rb
aws-sdk-core-2.11.575 lib/aws-sdk-core/rest/request/body.rb
aws-sdk-core-2.11.574 lib/aws-sdk-core/rest/request/body.rb
aws-sdk-core-2.11.573 lib/aws-sdk-core/rest/request/body.rb