Sha256: f80c17f417329034b0075431870b00e0490dc3ae2ffb9e8863ecb5b6d4d91966

Contents?: true

Size: 1.69 KB

Versions: 88

Compression:

Stored size: 1.69 KB

Contents

module Aws
  module Rest
    module Response
      class Headers

        include Seahorse::Model::Shapes

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

        # @param [Seahorse::Client::Http::Response] http_resp
        # @param [Hash, Struct] target
        def apply(http_resp, target)
          headers = http_resp.headers
          @rules.shape.members.each do |name, ref|
            case ref.location
            when 'header' then extract_header_value(headers, name, ref, target)
            when 'headers' then extract_header_map(headers, name, ref, target)
            end
          end
        end

        def extract_header_value(headers, name, ref, data)
          if headers.key?(ref.location_name)
            data[name] = cast_value(ref, headers[ref.location_name])
          end
        end

        def cast_value(ref, value)
          case ref.shape
          when StringShape then value
          when IntegerShape then value.to_i
          when FloatShape then value.to_f
          when BooleanShape then value == 'true'
          when TimestampShape
            if value =~ /\d+(\.\d*)/
              Time.at(value.to_f)
            else
              Time.parse(value)
            end
          else raise "unsupported shape #{ref.shape.class}"
          end
        end

        def extract_header_map(headers, name, ref, data)
          data[name] = {}
          prefix = ref.location_name || ''
          headers.each do |header_name, header_value|
            if match = header_name.match(/^#{prefix}(.+)/i)
              data[name][match[1]] = header_value
            end
          end
        end

      end
    end
  end
end

Version data entries

88 entries across 88 versions & 1 rubygems

Version Path
aws-sdk-core-2.3.14 lib/aws-sdk-core/rest/response/headers.rb
aws-sdk-core-2.3.13 lib/aws-sdk-core/rest/response/headers.rb
aws-sdk-core-2.3.12 lib/aws-sdk-core/rest/response/headers.rb
aws-sdk-core-2.3.11 lib/aws-sdk-core/rest/response/headers.rb
aws-sdk-core-2.3.10 lib/aws-sdk-core/rest/response/headers.rb
aws-sdk-core-2.3.9 lib/aws-sdk-core/rest/response/headers.rb
aws-sdk-core-2.3.8 lib/aws-sdk-core/rest/response/headers.rb
aws-sdk-core-2.3.7 lib/aws-sdk-core/rest/response/headers.rb
aws-sdk-core-2.3.6 lib/aws-sdk-core/rest/response/headers.rb
aws-sdk-core-2.3.5 lib/aws-sdk-core/rest/response/headers.rb
aws-sdk-core-2.3.4 lib/aws-sdk-core/rest/response/headers.rb
aws-sdk-core-2.3.3 lib/aws-sdk-core/rest/response/headers.rb
aws-sdk-core-2.3.2 lib/aws-sdk-core/rest/response/headers.rb
aws-sdk-core-2.3.1 lib/aws-sdk-core/rest/response/headers.rb
aws-sdk-core-2.3.0 lib/aws-sdk-core/rest/response/headers.rb
aws-sdk-core-2.2.37 lib/aws-sdk-core/rest/response/headers.rb
aws-sdk-core-2.2.36 lib/aws-sdk-core/rest/response/headers.rb
aws-sdk-core-2.2.35 lib/aws-sdk-core/rest/response/headers.rb
aws-sdk-core-2.2.34 lib/aws-sdk-core/rest/response/headers.rb
aws-sdk-core-2.2.33 lib/aws-sdk-core/rest/response/headers.rb