Sha256: bb6e165874396228b788ea3efd471046a6e3c0957a2da2629639d2d6351a798d

Contents?: true

Size: 1.35 KB

Versions: 30

Compression:

Stored size: 1.35 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
          else raise "unsupported protocol #{protocol}"
          end
        end

      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
aws-sdk-core-3.7.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.6.1 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.6.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.5.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.4.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.3.1 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.3.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.2.1 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.2.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.1.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.0.0 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.0.0.rc20 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.0.0.rc19 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.0.0.rc18 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.0.0.rc17 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.0.0.rc16 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.0.0.rc15 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.0.0.rc14 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.0.0.rc13 lib/aws-sdk-core/rest/response/parser.rb
aws-sdk-core-3.0.0.rc12 lib/aws-sdk-core/rest/response/parser.rb