You are viewing documentation for version 2 of the AWS SDK for Ruby. Version 3 documentation can be found here.

Class: Aws::Plugins::StubResponses::Handler

Inherits:
Seahorse::Client::Handler show all
Defined in:
aws-sdk-core/lib/aws-sdk-core/plugins/stub_responses.rb

Instance Attribute Summary

Attributes inherited from Seahorse::Client::Handler

#handler

Instance Method Summary collapse

Methods inherited from Seahorse::Client::Handler

#initialize, #inspect

Constructor Details

This class inherits a constructor from Seahorse::Client::Handler

Instance Method Details

#apply_stub(stub, response) ⇒ Object



47
48
49
50
51
52
53
54
# File 'aws-sdk-core/lib/aws-sdk-core/plugins/stub_responses.rb', line 47

def apply_stub(stub, response)
  http_resp = response.context.http_response
  case
  when stub[:error] then signal_error(stub[:error], http_resp)
  when stub[:http] then signal_http(stub[:http], http_resp)
  when stub[:data] then response.data = stub[:data]
  end
end

#call(context) ⇒ Object



40
41
42
43
44
45
# File 'aws-sdk-core/lib/aws-sdk-core/plugins/stub_responses.rb', line 40

def call(context)
  stub = context.client.next_stub(context)
  resp = Seahorse::Client::Response.new(context: context)
  apply_stub(stub, resp)
  resp
end

#signal_error(error, http_resp) ⇒ Object



56
57
58
59
60
61
62
# File 'aws-sdk-core/lib/aws-sdk-core/plugins/stub_responses.rb', line 56

def signal_error(error, http_resp)
  if Exception === error
    http_resp.signal_error(error)
  else
    http_resp.signal_error(error.new)
  end
end

#signal_http(stub, http_resp) ⇒ Object



66
67
68
69
70
71
72
73
# File 'aws-sdk-core/lib/aws-sdk-core/plugins/stub_responses.rb', line 66

def signal_http(stub, http_resp)
  http_resp.signal_headers(stub.status_code, stub.headers.to_h)
  while chunk = stub.body.read(1024 * 1024)
    http_resp.signal_data(chunk)
  end
  stub.body.rewind
  http_resp.signal_done
end