File: json.rb

package info (click to toggle)
ruby-aws-sdk-core 3.212.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,232 kB
  • sloc: ruby: 17,533; makefile: 4
file content (43 lines) | stat: -rw-r--r-- 1,058 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true

module Aws
  module Stubbing
    module Protocols
      # @api private
      class Json

        def stub_data(api, operation, data)
          resp = Seahorse::Client::Http::Response.new
          resp.status_code = 200
          resp.headers['Content-Type'] = content_type(api)
          resp.headers['x-amzn-RequestId'] = 'stubbed-request-id'
          resp.body = build_body(operation, data)
          resp
        end

        def stub_error(error_code)
          resp = Seahorse::Client::Http::Response.new
          resp.status_code = 400
          resp.body = <<~JSON.strip
            {
              "code": #{error_code.inspect},
              "message": "stubbed-response-error-message"
            }
          JSON
          resp
        end

        private

        def content_type(api)
          "application/x-amz-json-#{api.metadata['jsonVersion']}"
        end

        def build_body(operation, data)
          Aws::Json::Builder.new(operation.output).to_json(data)
        end

      end
    end
  end
end