Class: Seahorse::Client::Response
- Inherits:
-
Delegator
- Object
- Delegator
- Seahorse::Client::Response
- Defined in:
- lib/seahorse/client/response.rb
Instance Attribute Summary collapse
- #context ⇒ RequestContext readonly
-
#data ⇒ Object
The response data.
- #error ⇒ StandardError?
Instance Method Summary collapse
-
#__getobj__ ⇒ Object
private
Necessary to define as a subclass of Delegator.
-
#__setobj__(obj) ⇒ Object
private
Necessary to define as a subclass of Delegator.
-
#initialize(options = {}) ⇒ Response
constructor
A new instance of Response.
- #on(range, &block) ⇒ self
- #on_complete(&block) ⇒ Object private
-
#on_success(&block) ⇒ self
Yields to the block if the response has a 200 level status code.
-
#successful? ⇒ Boolean
Returns ‘true` if the response is complete with a ~ 200 level http status code.
Constructor Details
#initialize(options = {}) ⇒ Response
Returns a new instance of Response.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/seahorse/client/response.rb', line 11 def initialize( = {}) @context = [:context] || RequestContext.new @data = [:data] @error = [:error] @http_request = @context.http_request @http_response = @context.http_response @http_response.on_error do |error| @error = error end end |
Instance Attribute Details
#context ⇒ RequestContext (readonly)
23 24 25 |
# File 'lib/seahorse/client/response.rb', line 23 def context @context end |
#data ⇒ Object
Returns The response data. This may be ‘nil` if the response contains an #error.
27 28 29 |
# File 'lib/seahorse/client/response.rb', line 27 def data @data end |
#error ⇒ StandardError?
30 31 32 |
# File 'lib/seahorse/client/response.rb', line 30 def error @error end |
Instance Method Details
#__getobj__ ⇒ 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.
Necessary to define as a subclass of Delegator
70 71 72 |
# File 'lib/seahorse/client/response.rb', line 70 def __getobj__ @data end |
#__setobj__(obj) ⇒ 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.
Necessary to define as a subclass of Delegator
76 77 78 |
# File 'lib/seahorse/client/response.rb', line 76 def __setobj__(obj) @data = obj end |
#on(status_code, &block) ⇒ self #on(status_code_range, &block) ⇒ self
42 43 44 45 46 47 48 |
# File '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_complete(&block) ⇒ 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.
63 64 65 66 |
# File 'lib/seahorse/client/response.rb', line 63 def on_complete(&block) @context.http_response.on_done(&block) self end |
#on_success(&block) ⇒ self
Yields to the block if the response has a 200 level status code.
52 53 54 |
# File '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.
58 59 60 |
# File 'lib/seahorse/client/response.rb', line 58 def successful? (200..299).include?(@context.http_response.status_code) && @error.nil? end |