Sha256: f697bc809638630b6dc19adeaa662b9d16487ed58f0721aedd67935811a79d09

Contents?: true

Size: 1.43 KB

Versions: 115

Compression:

Stored size: 1.43 KB

Contents

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

115 entries across 115 versions & 1 rubygems

Version Path
aws-sdk-core-3.100.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.99.2 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.99.1 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.99.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.98.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.97.1 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.97.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.96.1 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.96.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.95.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.94.1 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.94.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.93.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.92.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.91.1 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.91.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.90.1 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.90.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.89.1 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.89.0 lib/aws-sdk-core/rest/response/parser.rb