Class: Seahorse::Client::Response
- Inherits:
-
Object
- Object
- 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
-
#initialize(options = {}) ⇒ Response
constructor
A new instance of Response.
- #inspect ⇒ Object private
- #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.
- #pretty_print(q) ⇒ Object private
- #respond_to?(*args) ⇒ Boolean private
-
#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.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/seahorse/client/response.rb', line 9 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object (private)
83 84 85 86 87 88 89 |
# File 'lib/seahorse/client/response.rb', line 83 def method_missing(*args, &block) if @data.respond_to?(args.first, false) @data.send(*args, &block) else super end end |
Instance Attribute Details
#context ⇒ RequestContext (readonly)
21 22 23 |
# File 'lib/seahorse/client/response.rb', line 21 def context @context end |
#data ⇒ Object
Returns The response data. This may be ‘nil` if the response contains an #error.
25 26 27 |
# File 'lib/seahorse/client/response.rb', line 25 def data @data end |
#error ⇒ StandardError?
28 29 30 |
# File 'lib/seahorse/client/response.rb', line 28 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.
67 68 69 |
# File 'lib/seahorse/client/response.rb', line 67 def inspect @data.inspect end |
#on(status_code, &block) ⇒ self #on(status_code_range, &block) ⇒ self
40 41 42 43 44 45 46 |
# File '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_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.
61 62 63 64 |
# File 'lib/seahorse/client/response.rb', line 61 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.
50 51 52 |
# File 'lib/seahorse/client/response.rb', line 50 def on_success(&block) on(200..299, &block) end |
#pretty_print(q) ⇒ 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.
72 73 74 |
# File 'lib/seahorse/client/response.rb', line 72 def pretty_print(q) @data.pretty_print(q) 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.
77 78 79 |
# File 'lib/seahorse/client/response.rb', line 77 def respond_to?(*args) @data.respond_to?(args.first, false) || super end |
#successful? ⇒ Boolean
Returns ‘true` if the response is complete with a ~ 200 level http status code.
56 57 58 |
# File 'lib/seahorse/client/response.rb', line 56 def successful? (200..299).include?(@context.http_response.status_code) && @error.nil? end |