module Aws::ClientStubs

def api_requests(options = {})

Raises:
  • (NotImplementedError) - Raises `NotImplementedError` when the client

Returns:
  • (Array) - Returns an array of the api requests made. Each request

Options Hash: (**options)
  • :exclude_presign (Boolean) -- Set to true to filter

Parameters:
  • options (Hash) -- The options for the api requests.
def api_requests(options = {})
  if config.stub_responses
    if options[:exclude_presign]
      @api_requests.reject {|req| req[:context][:presigned_url] }
    else
      @api_requests
    end
  else
    msg = 'This method is only implemented for stubbed clients, and is '\
          'available when you enable stubbing in the constructor with `stub_responses: true`'
    raise NotImplementedError.new(msg)
  end
end

def apply_stubs(operation_name, stubs)

during response handling.
plugin to provide a HTTP response that triggers all normal events
HTTP response (when possible). This enables the response stubbing
This method converts the given stub data and converts it to a
def apply_stubs(operation_name, stubs)
  @stub_mutex.synchronize do
    @stubs[operation_name.to_sym] = stubs.map do |stub|
      convert_stub(operation_name, stub)
    end
  end
end

def convert_stub(operation_name, stub)

def convert_stub(operation_name, stub)
  stub = case stub
  when Proc then stub
  when Exception, Class then { error: stub }
  when String then service_error_stub(stub)
  when Hash then http_response_stub(operation_name, stub)
  else { data: stub }
  end
  if Hash === stub
    stub[:mutex] = Mutex.new
  end
  stub
end

def data_to_http_resp(operation_name, data)

def data_to_http_resp(operation_name, data)
  api = config.api
  operation = api.operation(operation_name)
  ParamValidator.new(operation.output, input: false).validate!(data)
  protocol_helper.stub_data(api, operation, data)
end

def default_stub(operation_name)

def default_stub(operation_name)
  stub = stub_data(operation_name)
  http_response_stub(operation_name, stub)
end

def hash_to_http_resp(data)

def hash_to_http_resp(data)
  http_resp = Seahorse::Client::Http::Response.new
  http_resp.status_code = data[:status_code]
  http_resp.headers.update(data[:headers])
  http_resp.body = data[:body]
  http_resp
end

def http_response_stub(operation_name, data)

def http_response_stub(operation_name, data)
  if Hash === data && data.keys.sort == [:body, :headers, :status_code]
    { http: hash_to_http_resp(data) }
  else
    { http: data_to_http_resp(operation_name, data) }
  end
end

def next_stub(context)

Other tags:
    Api: - private
def next_stub(context)
  operation_name = context.operation_name.to_sym
  stub = @stub_mutex.synchronize do
    stubs = @stubs[operation_name] || []
    case stubs.length
    when 0 then default_stub(operation_name)
    when 1 then stubs.first
    else stubs.shift
    end
  end
  Proc === stub ? convert_stub(operation_name, stub.call(context)) : stub
end

def protocol_helper

def protocol_helper
  case config.api.metadata['protocol']
  when 'json'        then Stubbing::Protocols::Json
  when 'query'       then Stubbing::Protocols::Query
  when 'ec2'         then Stubbing::Protocols::EC2
  when 'rest-json'   then Stubbing::Protocols::RestJson
  when 'rest-xml'    then Stubbing::Protocols::RestXml
  when 'api-gateway' then Stubbing::Protocols::ApiGateway
  else raise "unsupported protocol"
  end.new
end

def service_error_stub(error_code)

def service_error_stub(error_code)
  { http: protocol_helper.stub_error(error_code) }
end

def setup_stubbing

Other tags:
    Api: - private
def setup_stubbing
  @stubs = {}
  @stub_mutex = Mutex.new
  if Hash === @config.stub_responses
    @config.stub_responses.each do |operation_name, stubs|
      apply_stubs(operation_name, Array === stubs ? stubs : [stubs])
    end
  end
  # When a client is stubbed allow the user to access the requests made
  @api_requests = []
  requests = @api_requests
  self.handle do |context|
    requests << {
      operation_name: context.operation_name,
      params: context.params,
      context: context
    }
    @handler.call(context)
  end
end

def stub_data(operation_name, data = {})

Returns:
  • (Structure) - Returns a stubbed response data structure. The

Parameters:
  • data (Hash) --
  • operation_name (Symbol) --
def stub_data(operation_name, data = {})
  Stubbing::StubData.new(config.api.operation(operation_name)).stub(data)
end

def stub_responses(operation_name, *stubs)

Raises:
  • (RuntimeError) - Raises a runtime error when called

Returns:
  • (void) -

Parameters:
  • stubs (Mixed) -- One or more responses to return from the named
  • operation_name (Symbol) --
def stub_responses(operation_name, *stubs)
  if config.stub_responses
    apply_stubs(operation_name, stubs.flatten)
  else
    msg = 'stubbing is not enabled; enable stubbing in the constructor '\
          'with `:stub_responses => true`'
    raise msg
  end
end