Class: Seahorse::Client::Response
- Inherits:
-
Object
- Object
- Seahorse::Client::Response
show all
- Defined in:
- lib/seahorse/client/response.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Response
Returns a new instance of Response.
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
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
18
19
20
|
# File 'lib/seahorse/client/response.rb', line 18
def context
@context
end
|
#data ⇒ Object
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
|
#error ⇒ StandardError?
25
26
27
|
# File 'lib/seahorse/client/response.rb', line 25
def error
@error
end
|
Instance Method Details
#inspect ⇒ Object
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
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.
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.
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
46
47
48
|
# File 'lib/seahorse/client/response.rb', line 46
def successful?
(200..299).include?(status_code)
end
|