Sha256: 27ce1073000f0b87d37c964e02bf90247f8d88123564ed91523a58557f79b3c3

Contents?: true

Size: 1.46 KB

Versions: 190

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

module Aws
  module Rest
    module Response
      class Parser

        def apply(response)
          # TODO : remove this unless check once response stubbing is fixed
          if rules = response.context.operation.output
            response.data = rules.shape.struct_class.new
            extract_status_code(rules, response)
            extract_headers(rules, response)
            extract_body(rules, response)
          else
            response.data = EmptyStructure.new
          end
        end

        private

        def extract_status_code(rules, response)
          status_code = StatusCode.new(rules)
          status_code.apply(response.context.http_response, response.data)
        end

        def extract_headers(rules, response)
          headers = Headers.new(rules)
          headers.apply(response.context.http_response, response.data)
        end

        def extract_body(rules, response)
          Body.new(parser_class(response), rules).
            apply(
              response.context.http_response.body,
              response.data
            )
        end

        def parser_class(response)
          protocol = response.context.config.api.metadata['protocol']
          case protocol
          when 'rest-xml' then Xml::Parser
          when 'rest-json' then Json::Parser
          when 'api-gateway' then Json::Parser
          else raise "unsupported protocol #{protocol}"
          end
        end

      end
    end
  end
end

Version data entries

190 entries across 190 versions & 1 rubygems

Version Path
aws-sdk-core-3.214.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.213.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.212.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.211.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.210.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.209.1 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.209.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.208.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.207.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.206.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.205.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.204.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.203.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.202.2 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.202.1 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.202.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.201.5 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.201.4 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.201.3 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.201.2 lib/aws-sdk-core/rest/response/parser.rb