Class: Seahorse::Client::Response

Inherits:
Object
  • Object
show all
Defined in:
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.

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: ''


9
10
11
12
13
14
15
# File '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
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



70
71
72
73
74
75
76
# File 'lib/seahorse/client/response.rb', line 70

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)

Returns:



18
19
20
# File 'lib/seahorse/client/response.rb', line 18

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.



22
23
24
# File 'lib/seahorse/client/response.rb', line 22

def data
  @data
end

#errorStandardError?

Returns:

  • (StandardError, nil)


25
26
27
# File 'lib/seahorse/client/response.rb', line 25

def error
  @error
end

Instance Method Details

#inspectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



56
57
58
59
60
61
62
# File 'lib/seahorse/client/response.rb', line 56

def inspect
  if @data
    @data.respond_to?(:pretty_inspect) ? @data.pretty_inspect : super
  else
    super
  end
end

#on(status_code_range) {|_self| ... } ⇒ self

Parameters:

  • status_code_range (Integer, Range<Integer>)

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

Yields:

  • (_self)

Yield Parameters:

Returns:

  • (self)


31
32
33
34
35
36
# File 'lib/seahorse/client/response.rb', line 31

def on(status_code_range, &block)
  range = status_code_range
  range = range..range if range.is_a?(Integer)
  yield(self) if range.include?(status_code)
  self
end

#on_success(&block) ⇒ self

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

Returns:

  • (self)


40
41
42
# File 'lib/seahorse/client/response.rb', line 40

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

#respond_to?(*args) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


51
52
53
# File 'lib/seahorse/client/response.rb', line 51

def respond_to?(*args)
  @data.respond_to?(args.first, false) || super
end

#successful?Boolean

Parameters:

  • Returns (Boolean)

    ‘true` if the http response status is a 200 level status code.

Returns:

  • (Boolean)


46
47
48
# File 'lib/seahorse/client/response.rb', line 46

def successful?
  (200..299).include?(status_code)
end