Class: Strava::Web::Response

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from DeepCopyable

#deep_copy

Constructor Details

#initialize(http_response) ⇒ Response

Returns a new instance of Response.

Parameters:

  • http_response (Faraday::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.

Parameters:

  • method_symbol (Symbol)

    The method name to forward

  • args (Array)

    Arguments to pass to the method

Returns:

  • (Object)

    Result from the delegated method



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_responseObject (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

#responseObject (readonly)

Returns the value of attribute response.



12
13
14
# File 'lib/strava/web/response.rb', line 12

def response
  @response
end