Class: Marketing::DataManager::Client

Inherits:
Object
  • Object
show all
Defined in:
app/services/marketing/data_manager/client.rb

Overview

Shared REST transport for the Google Data Manager API: mints an OAuth access
token from a refresh token (no developer token, unlike the Google Ads API)
and POSTs/GETs the v1 endpoints. Subclassed by the audience
(CustomerMatch::Client) and conversion (EventsClient)
specializations, which add their ingest methods.

Credentials come from Heatwave::Configuration.fetch(:google_data_manager):
{ client_id:, client_secret:, refresh_token:, operating_account_id: }
where operating_account_id is the Google Ads customer id (digits only).

Direct Known Subclasses

CustomerMatch::Client, EventsClient

Defined Under Namespace

Classes: ConfigurationError, Error

Constant Summary collapse

OAUTH_TOKEN_URL =

Google OAuth2 token-exchange endpoint.

'https://oauth2.googleapis.com/token'
API_HOST =

Data Manager API host.

'https://datamanager.googleapis.com'
API_BASE =

Versioned API base path.

"#{API_HOST}/v1".freeze
'GOOGLE_ADS'
HTTP_OPEN_TIMEOUT =

HTTP timeouts (seconds) so a hung Google connection can't stall a Sidekiq
worker — matches the codebase convention for OAuth API clients.

5
HTTP_TIMEOUT =

Read timeout (seconds) for Data Manager API calls.

30
REQUIRED_KEYS =

Required config keys.

%i[client_id client_secret refresh_token operating_account_id].freeze

Instance Method Summary collapse

Constructor Details

#initialize(config: Heatwave::Configuration.fetch(:google_data_manager)) ⇒ Client

Returns a new instance of Client.

Parameters:

  • config (Hash, nil) (defaults to: Heatwave::Configuration.fetch(:google_data_manager))

    overrides the credentials lookup (for tests)



44
45
46
47
48
49
# File 'app/services/marketing/data_manager/client.rb', line 44

def initialize(config: Heatwave::Configuration.fetch(:google_data_manager))
  @config = (config || {}).symbolize_keys
  REQUIRED_KEYS.each do |key|
    raise ConfigurationError, "missing :google_data_manager #{key}" if @config[key].blank?
  end
end

Instance Method Details

#request_status(request_id) ⇒ Hash

Returns RetrieveRequestStatusResponse.

Parameters:

  • request_id (String)

Returns:

  • (Hash)

    RetrieveRequestStatusResponse



53
54
55
# File 'app/services/marketing/data_manager/client.rb', line 53

def request_status(request_id)
  get('/v1/requestStatus:retrieve', requestId: request_id)
end