Sha256: 3498feede49a8feaeb384b46eb889d870cf5758917cc08f7f19208d04b66b8a5

Contents?: true

Size: 1.34 KB

Versions: 186

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

module Aws
  module Stubbing
    module Protocols
      class EC2

        def stub_data(api, operation, data)
          resp = Seahorse::Client::Http::Response.new
          resp.status_code = 200
          resp.body = build_body(api, operation, data) if operation.output
          resp.headers['Content-Length'] = resp.body.size
          resp.headers['Content-Type'] = 'text/xml;charset=UTF-8'
          resp.headers['Server'] = 'AmazonEC2'
          resp
        end

        def stub_error(error_code)
          http_resp = Seahorse::Client::Http::Response.new
          http_resp.status_code = 400
          http_resp.body = <<-XML.strip
<ErrorResponse>
  <Error>
    <Code>#{error_code}</Code>
    <Message>stubbed-response-error-message</Message>
  </Error>
</ErrorResponse>
          XML
          http_resp
        end

        private

        def build_body(api, operation, data)
          xml = []
          Xml::Builder.new(operation.output, target:xml).to_xml(data)
          xml.shift
          xml.pop
          xmlns = "http://ec2.amazonaws.com/doc/#{api.version}/".inspect
          xml.unshift("  <requestId>stubbed-request-id</requestId>")
          xml.unshift("<#{operation.name}Response xmlns=#{xmlns}>\n")
          xml.push("</#{operation.name}Response>\n")
          xml.join
        end

      end
    end
  end
end

Version data entries

186 entries across 186 versions & 1 rubygems

Version Path
aws-sdk-core-3.210.0 lib/aws-sdk-core/stubbing/protocols/ec2.rb
aws-sdk-core-3.209.1 lib/aws-sdk-core/stubbing/protocols/ec2.rb
aws-sdk-core-3.209.0 lib/aws-sdk-core/stubbing/protocols/ec2.rb
aws-sdk-core-3.208.0 lib/aws-sdk-core/stubbing/protocols/ec2.rb
aws-sdk-core-3.207.0 lib/aws-sdk-core/stubbing/protocols/ec2.rb
aws-sdk-core-3.206.0 lib/aws-sdk-core/stubbing/protocols/ec2.rb
aws-sdk-core-3.205.0 lib/aws-sdk-core/stubbing/protocols/ec2.rb
aws-sdk-core-3.204.0 lib/aws-sdk-core/stubbing/protocols/ec2.rb
aws-sdk-core-3.203.0 lib/aws-sdk-core/stubbing/protocols/ec2.rb
aws-sdk-core-3.202.2 lib/aws-sdk-core/stubbing/protocols/ec2.rb
aws-sdk-core-3.202.1 lib/aws-sdk-core/stubbing/protocols/ec2.rb
aws-sdk-core-3.202.0 lib/aws-sdk-core/stubbing/protocols/ec2.rb
aws-sdk-core-3.201.5 lib/aws-sdk-core/stubbing/protocols/ec2.rb
aws-sdk-core-3.201.4 lib/aws-sdk-core/stubbing/protocols/ec2.rb
aws-sdk-core-3.201.3 lib/aws-sdk-core/stubbing/protocols/ec2.rb
aws-sdk-core-3.201.2 lib/aws-sdk-core/stubbing/protocols/ec2.rb
aws-sdk-core-3.201.1 lib/aws-sdk-core/stubbing/protocols/ec2.rb
aws-sdk-core-3.201.0 lib/aws-sdk-core/stubbing/protocols/ec2.rb
aws-sdk-core-3.200.0 lib/aws-sdk-core/stubbing/protocols/ec2.rb
aws-sdk-core-3.199.0 lib/aws-sdk-core/stubbing/protocols/ec2.rb