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, *args, &block) ⇒ Object (private)



78
79
80
81
82
83
84
85
# File 'lib/strava/web/response.rb', line 78

def method_missing(method_symbol, *args, &block)
  case @response
  when Array
    @response.send(method_symbol, *args, &block)
  else
    operate_on_response_body!(method_symbol, *args, &block)
  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