Class: AmazonAds::ApiClient::Request

Inherits:
Object
  • Object
show all
Defined in:
app/services/amazon_ads/api_client/request.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection:, oauth:, method:, path:, profile_id:, content_type:, body:, params:) ⇒ Request

Returns a new instance of Request.

Parameters:

  • connection (Faraday::Connection)
  • oauth (AmazonAds::OauthService)
  • method (Symbol)
  • path (String)
  • profile_id (Integer, String, nil)
  • content_type (String)
  • body (Hash, nil)
  • params (Hash, nil)


19
20
21
22
23
# File 'app/services/amazon_ads/api_client/request.rb', line 19

def initialize(connection:, oauth:, method:, path:, profile_id:, content_type:, body:, params:)
  @connection = connection
  @oauth = oauth
  @request = { method:, path:, profile_id:, content_type:, body:, params: }.freeze
end

Class Method Details

.callHash, Array

Returns:

  • (Hash, Array)


6
7
8
# File 'app/services/amazon_ads/api_client/request.rb', line 6

def call(**)
  new(**).call
end

Instance Method Details

#callHash, Array

Executes one authenticated request, retrying once after a 401 forces an
OAuth refresh. Throttling is returned as typed retry state; this object
never sleeps on the calling Sidekiq thread.

Returns:

  • (Hash, Array)


29
30
31
32
33
34
# File 'app/services/amazon_ads/api_client/request.rb', line 29

def call
  response = execute
  response = refresh_and_retry if response.status == 401

  AmazonAds::ApiClient::Response.call(response:, method: @request[:method], path: @request[:path])
end