Class: APIClientBuilder::Response
- Inherits:
-
Object
- Object
- APIClientBuilder::Response
- Defined in:
- lib/api_client_builder/response.rb
Overview
The default page object to be used to hold the response from the API in your response handler object. Any response object that will replace this must response to #success?, and #items
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#status_code ⇒ Object
Returns the value of attribute status_code.
Instance Method Summary collapse
-
#initialize(body, status_code, success_range) ⇒ Response
constructor
A new instance of Response.
-
#mark_failed(reason) ⇒ Object
Used to mark why the response failed.
-
#success? ⇒ Boolean
Defines the success conditional for a response by determining whether or not the status code of the response is within the defined success range.
Constructor Details
#initialize(body, status_code, success_range) ⇒ Response
Returns a new instance of Response.
11 12 13 14 15 16 |
# File 'lib/api_client_builder/response.rb', line 11 def initialize(body, status_code, success_range) @body = body @status_code = status_code @success_range = success_range @failed_reason = nil end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
6 7 8 |
# File 'lib/api_client_builder/response.rb', line 6 def body @body end |
#status_code ⇒ Object
Returns the value of attribute status_code.
6 7 8 |
# File 'lib/api_client_builder/response.rb', line 6 def status_code @status_code end |
Instance Method Details
#mark_failed(reason) ⇒ Object
Used to mark why the response failed
19 20 21 |
# File 'lib/api_client_builder/response.rb', line 19 def mark_failed(reason) @failed_reason = reason end |
#success? ⇒ Boolean
Defines the success conditional for a response by determining whether or not the status code of the response is within the defined success range
28 29 30 |
# File 'lib/api_client_builder/response.rb', line 28 def success? @failed_reason.nil? && @success_range.include?(@status_code) end |