Class: MicrosoftAds::CampaignManagementClient
- Inherits:
-
Object
- Object
- MicrosoftAds::CampaignManagementClient
- Defined in:
- app/services/microsoft_ads/campaign_management_client.rb
Overview
Minimal SOAP client for the Microsoft Advertising (Bing Ads) Campaign
Management API v13 — just the one read operation we need,
GetCampaignsByAccountId, which MicrosoftAdsCampaignSyncWorker uses to
mirror campaigns into the sources table. The direct parallel to
OpenaiAds::AdvertiserApiClient#list_campaigns, but SOAP rather than REST.
Why hand-rolled SOAP: the Microsoft Advertising API is SOAP-only (v13)
and ships no Ruby SDK (C#/Java/PHP/Python only). Rather than pull in a
generic SOAP gem for a single fixed operation, we POST a static envelope
and parse the response with Nokogiri.
Every call carries the four credentials Microsoft requires as SOAP header
elements: the developer token, an OAuth access token from
OauthService (the AuthenticationToken), the CustomerId
(cid), and the CustomerAccountId (aid).
Constant Summary collapse
- SERVICE_URL =
Production Campaign Management v13 service endpoint. (Sandbox swaps
campaign.api.bingads→campaign.api.sandbox.bingads.) 'https://campaign.api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v13/CampaignManagementService.svc'- NS =
XML namespace for the v13 Campaign Management service.
'https://bingads.microsoft.com/CampaignManagement/v13'- CAMPAIGN_TYPES =
Space-delimited CampaignType flags. GetCampaignsByAccountId requires an
explicit type filter; this covers every campaign type a search
advertiser like WarmlyYours might run. Types the account isn't entitled
to simply return nothing rather than erroring. 'Search Shopping DynamicSearchAds Audience PerformanceMax'
Instance Method Summary collapse
-
#initialize(developer_token:, access_token:, customer_id:, account_id:) ⇒ CampaignManagementClient
constructor
A new instance of CampaignManagementClient.
-
#list_campaigns ⇒ Array<Hash>
Fetch every campaign on the account.
Constructor Details
#initialize(developer_token:, access_token:, customer_id:, account_id:) ⇒ CampaignManagementClient
Returns a new instance of CampaignManagementClient.
41 42 43 44 45 46 |
# File 'app/services/microsoft_ads/campaign_management_client.rb', line 41 def initialize(developer_token:, access_token:, customer_id:, account_id:) @developer_token = developer_token @access_token = access_token @customer_id = customer_id @account_id = account_id end |
Instance Method Details
#list_campaigns ⇒ Array<Hash>
Fetch every campaign on the account.
52 53 54 55 56 57 58 59 60 61 |
# File 'app/services/microsoft_ads/campaign_management_client.rb', line 52 def list_campaigns response = post(get_campaigns_envelope) unless response.success? raise "MicrosoftAds::CampaignManagementClient: GetCampaignsByAccountId failed " \ "(HTTP #{response.status}): #{(response.body)}" end parse_campaigns(response.body) end |