Class: FriendlyShipping::ApiResult
- Inherits:
-
Object
- Object
- FriendlyShipping::ApiResult
- Defined in:
- lib/friendly_shipping/api_result.rb
Overview
Wraps an API result (a response body, for example) along with the original request and response objects.
Instance Attribute Summary collapse
-
#data ⇒ Object
(also: #failure)
readonly
The API failure (typically an exception).
-
#original_request ⇒ Request
readonly
The original API request (if debugging is enabled).
-
#original_response ⇒ Response
readonly
The original API response (if debugging is enabled).
Instance Method Summary collapse
-
#initialize(data, original_request: nil, original_response: nil) ⇒ ApiResult
constructor
Returns a new instance of
ApiResult
. -
#to_s ⇒ #to_s
A string representation of the data.
Constructor Details
#initialize(data, original_request: nil, original_response: nil) ⇒ ApiResult
Returns a new instance of ApiResult
. The original request and response are only attached
to this object if debugging is enabled. See Request#debug
27 28 29 30 31 32 33 34 35 |
# File 'lib/friendly_shipping/api_result.rb', line 27 def initialize(data, original_request: nil, original_response: nil) @data = data # We do not want to attach debugging information in every single response to save memory in production return unless original_request&.debug @original_request = original_request @original_response = original_response end |
Instance Attribute Details
#data ⇒ Object (readonly) Also known as: failure
The API failure (typically an exception). This is here to maintain backwards compatibility with the deprecated FriendlyShipping::ApiResult class.
8 9 10 |
# File 'lib/friendly_shipping/api_result.rb', line 8 def data @data end |
#original_request ⇒ Request (readonly)
Returns the original API request (if debugging is enabled).
16 17 18 |
# File 'lib/friendly_shipping/api_result.rb', line 16 def original_request @original_request end |
#original_response ⇒ Response (readonly)
Returns the original API response (if debugging is enabled).
19 20 21 |
# File 'lib/friendly_shipping/api_result.rb', line 19 def original_response @original_response end |
Instance Method Details
#to_s ⇒ #to_s
Returns a string representation of the data.
38 39 40 |
# File 'lib/friendly_shipping/api_result.rb', line 38 def to_s data.to_s end |