Class: Seahorse::Client::Response

Inherits:
Object
  • Object
show all
Defined in:
aws-sdk-core/lib/seahorse/client/response.rb

Direct Known Subclasses

Aws::PageableResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Response

Returns a new instance of Response

Options Hash (options):

  • :context (RequestContext) — default: nil
  • :status_code (Integer) — default: nil
  • :headers (Http::Headers) — default: Http::Headers.new
  • :body (String) — default: ''

9
10
11
12
13
14
15
16
17
18
# File 'aws-sdk-core/lib/seahorse/client/response.rb', line 9

def initialize(options = {})
  @context = options[:context] || RequestContext.new
  @data = options[:data]
  @error = options[:error]
  @http_request = @context.http_request
  @http_response = @context.http_response
  @http_response.on_error do |error|
    @error = error
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object (private)


76
77
78
79
80
81
82
# File 'aws-sdk-core/lib/seahorse/client/response.rb', line 76

def method_missing(*args, &block)
  if @data.respond_to?(args.first, false)
    @data.send(*args, &block)
  else
    super
  end
end

Instance Attribute Details

#contextRequestContext (readonly)


21
22
23
# File 'aws-sdk-core/lib/seahorse/client/response.rb', line 21

def context
  @context
end

#dataObject


25
26
27
# File 'aws-sdk-core/lib/seahorse/client/response.rb', line 25

def data
  @data
end

#errorStandardError?


28
29
30
# File 'aws-sdk-core/lib/seahorse/client/response.rb', line 28

def error
  @error
end

Instance Method Details

#on(status_code, &block) ⇒ self #on(status_code_range, &block) ⇒ self


40
41
42
43
44
45
46
# File 'aws-sdk-core/lib/seahorse/client/response.rb', line 40

def on(range, &block)
  response = self
  @context.http_response.on_success(range) do
    block.call(response)
  end
  self
end

#on_success(&block) ⇒ self

Yields to the block if the response has a 200 level status code.


50
51
52
# File 'aws-sdk-core/lib/seahorse/client/response.rb', line 50

def on_success(&block)
  on(200..299, &block)
end

#successful?Boolean


56
57
58
# File 'aws-sdk-core/lib/seahorse/client/response.rb', line 56

def successful?
  (200..299).include?(@context.http_response.status_code) && @error.nil?
end