Class: Strava::Web::Response
- Inherits:
-
Object
- Object
- Strava::Web::Response
- Includes:
- DeepCopyable
- Defined in:
- lib/strava/web/response.rb
Overview
wrapper class as abstraction for API response returned from the Faraday Adapter working with a deep copy, in order to not mutate the original request itself
Instance Attribute Summary collapse
-
#http_response ⇒ Object
readonly
Returns the value of attribute http_response.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(http_response) ⇒ Response
constructor
A new instance of Response.
Methods included from DeepCopyable
Constructor Details
#initialize(http_response) ⇒ Response
Returns a new instance of Response.
17 18 19 20 |
# File 'lib/strava/web/response.rb', line 17 def initialize(http_response) @http_response = deep_copy(http_response) @response = conditional_response_upgrade!(http_response) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_symbol) ⇒ Object (private)
Delegates missing methods to the response body or array.
If the response is an array, delegates methods to the array. Otherwise, delegates to the response body hash, allowing access to response fields as if they were methods.
89 90 91 92 93 94 95 96 |
# File 'lib/strava/web/response.rb', line 89 def method_missing(method_symbol, ...) case @response when Array @response.send(method_symbol, ...) else operate_on_response_body!(method_symbol, ...) end end |
Instance Attribute Details
#http_response ⇒ Object (readonly)
Returns the value of attribute http_response.
12 13 14 |
# File 'lib/strava/web/response.rb', line 12 def http_response @http_response end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
12 13 14 |
# File 'lib/strava/web/response.rb', line 12 def response @response end |