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

Class: Seahorse::Client::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Response

Returns a new instance of Response

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

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


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

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

Instance Attribute Details

#contextRequestContext (readonly)

Returns:



23
24
25
# File 'gems/aws-sdk-core/lib/seahorse/client/response.rb', line 23

def context
  @context
end

#dataObject

Returns The response data. This may be nil if the response contains an #error.

Returns:

  • The response data. This may be nil if the response contains an #error.



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

def data
  @data
end

#errorStandardError?

Returns:

  • (StandardError, nil)


30
31
32
# File 'gems/aws-sdk-core/lib/seahorse/client/response.rb', line 30

def error
  @error
end

Instance Method Details

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

Overloads:

  • #on(status_code, &block) ⇒ self

    Parameters:

    • status_code (Integer)

      The block will be triggered only for responses with the given status code.

  • #on(status_code_range, &block) ⇒ self

    Parameters:

    • status_code_range (Range<Integer>)

      The block will be triggered only for responses with a status code that falls witin the given range.

Returns:

  • (self)


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

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.

Returns:

  • (self)


52
53
54
# File 'gems/aws-sdk-core/lib/seahorse/client/response.rb', line 52

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

#successful?Boolean

Returns true if the response is complete with a ~ 200 level http status code.

Returns:

  • (Boolean)

    Returns true if the response is complete with a ~ 200 level http status code.



58
59
60
# File 'gems/aws-sdk-core/lib/seahorse/client/response.rb', line 58

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