Class: Pinterest::ApiClient
- Inherits:
-
BaseService
- Object
- BaseService
- Pinterest::ApiClient
- Defined in:
- app/services/pinterest/api_client.rb
Constant Summary collapse
- BASE_URL =
'https://api.pinterest.com/v5'
Instance Method Summary collapse
-
#send_events(ad_account_id:, token:, events:) ⇒ Hash
Send one or more conversion events to a Pinterest ad account.
Methods inherited from BaseService
#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #options, #process, #tagged_logger
Constructor Details
This class inherits a constructor from BaseService
Instance Method Details
#send_events(ad_account_id:, token:, events:) ⇒ Hash
Send one or more conversion events to a Pinterest ad account.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/services/pinterest/api_client.rb', line 21 def send_events(ad_account_id:, token:, events:) response = connection(token).post("ad_accounts/#{ad_account_id}/events") do |req| req.body = { data: events }.to_json end case response.status when 200 Rails.logger.info 'Pinterest::ApiClient: Events accepted (HTTP 200)' { status: :reported, http_status: 200 } when 429 error_msg = 'Rate limited (HTTP 429)' Rails.logger.warn "Pinterest::ApiClient: #{error_msg}" { status: :rate_limited, http_status: 429, error: error_msg } else body = safe_parse(response.body) error_msg = body['message'] || "HTTP #{response.status}" Rails.logger.error "Pinterest::ApiClient: Failed -- #{error_msg}" { status: :failed, http_status: response.status, error: error_msg } end rescue Faraday::TimeoutError => e { status: :failed, http_status: nil, error: "Timeout: #{e.}" } rescue Faraday::Error => e { status: :failed, http_status: nil, error: e. } end |