From a3132af799f2c88b43d85cdbeeecd969a0c92e47 Mon Sep 17 00:00:00 2001 From: Srivathsan MS Date: Wed, 23 Oct 2019 23:03:16 +0530 Subject: [PATCH] Bing API v13 upgrade --- lib/bing/ads.rb | 8 +-- lib/bing/ads/api/v11/constants.rb | 29 --------- lib/bing/ads/api/v11/constants/wsdl.yml | 10 ---- lib/bing/ads/api/v11/services/bulk.rb | 38 ------------ lib/bing/ads/api/{v11.rb => v13.rb} | 6 +- lib/bing/ads/api/v13/constants.rb | 31 ++++++++++ lib/bing/ads/api/v13/constants/bulk.yml | 5 ++ .../constants/campaign_management.yml | 4 -- .../api/{v11 => v13}/constants/languages.yml | 0 .../ads/api/{v11 => v13}/constants/limits.yml | 0 .../api/{v11 => v13}/constants/time_zones.yml | 8 +-- lib/bing/ads/api/v13/constants/wsdl.yml | 10 ++++ lib/bing/ads/api/{v11 => v13}/data.rb | 1 + .../ads/api/{v11 => v13}/data/ad_group.rb | 49 ++++++++------- lib/bing/ads/api/v13/data/bulk_request.rb | 52 ++++++++++++++++ .../ads/api/{v11 => v13}/data/campaign.rb | 14 +++-- .../api/{v11 => v13}/data/expanded_text_ad.rb | 39 ++++++------ lib/bing/ads/api/{v11 => v13}/data/keyword.rb | 12 ++-- .../api/{v11 => v13}/data/report_request.rb | 37 ++++++------ lib/bing/ads/api/{v11 => v13}/services.rb | 0 .../ads/api/{v11 => v13}/services/base.rb | 8 +-- lib/bing/ads/api/v13/services/bulk.rb | 59 +++++++++++++++++++ .../services/campaign_management.rb | 32 +++++----- .../services/customer_management.rb | 4 +- .../api/{v11 => v13}/services/reporting.rb | 9 ++- lib/bing/ads/version.rb | 2 +- 26 files changed, 271 insertions(+), 196 deletions(-) delete mode 100644 lib/bing/ads/api/v11/constants.rb delete mode 100644 lib/bing/ads/api/v11/constants/wsdl.yml delete mode 100644 lib/bing/ads/api/v11/services/bulk.rb rename lib/bing/ads/api/{v11.rb => v13.rb} (74%) create mode 100644 lib/bing/ads/api/v13/constants.rb create mode 100644 lib/bing/ads/api/v13/constants/bulk.yml rename lib/bing/ads/api/{v11 => v13}/constants/campaign_management.yml (97%) rename lib/bing/ads/api/{v11 => v13}/constants/languages.yml (100%) rename lib/bing/ads/api/{v11 => v13}/constants/limits.yml (100%) rename lib/bing/ads/api/{v11 => v13}/constants/time_zones.yml (92%) create mode 100644 lib/bing/ads/api/v13/constants/wsdl.yml rename lib/bing/ads/api/{v11 => v13}/data.rb (82%) rename lib/bing/ads/api/{v11 => v13}/data/ad_group.rb (64%) create mode 100644 lib/bing/ads/api/v13/data/bulk_request.rb rename lib/bing/ads/api/{v11 => v13}/data/campaign.rb (82%) rename lib/bing/ads/api/{v11 => v13}/data/expanded_text_ad.rb (52%) rename lib/bing/ads/api/{v11 => v13}/data/keyword.rb (90%) rename lib/bing/ads/api/{v11 => v13}/data/report_request.rb (82%) rename lib/bing/ads/api/{v11 => v13}/services.rb (100%) rename lib/bing/ads/api/{v11 => v13}/services/base.rb (97%) create mode 100644 lib/bing/ads/api/v13/services/bulk.rb rename lib/bing/ads/api/{v11 => v13}/services/campaign_management.rb (93%) rename lib/bing/ads/api/{v11 => v13}/services/customer_management.rb (92%) rename lib/bing/ads/api/{v11 => v13}/services/reporting.rb (86%) diff --git a/lib/bing/ads.rb b/lib/bing/ads.rb index 7f27a01..73dc34c 100644 --- a/lib/bing/ads.rb +++ b/lib/bing/ads.rb @@ -8,14 +8,14 @@ require 'bing/ads/api/errors' require 'bing/ads/api/soap_client' require 'bing/ads/api/http_client' -require 'bing/ads/api/v11' -require 'bing/ads/api/v11/constants' -require 'bing/ads/api/v11/data' -require 'bing/ads/api/v11/services' require 'bing/ads/api/v12' require 'bing/ads/api/v12/constants' require 'bing/ads/api/v12/data' require 'bing/ads/api/v12/services' +require 'bing/ads/api/v13' +require 'bing/ads/api/v13/constants' +require 'bing/ads/api/v13/data' +require 'bing/ads/api/v13/services' require 'bing/ads/utils' require 'bing/ads/version' diff --git a/lib/bing/ads/api/v11/constants.rb b/lib/bing/ads/api/v11/constants.rb deleted file mode 100644 index 8a85fe1..0000000 --- a/lib/bing/ads/api/v11/constants.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -module Bing - module Ads - module API - # Bing::Ads::API::V11::Constants - module Constants - root_v11_path = File.expand_path('../', __FILE__) - - campaign_management_path = File.join(root_v11_path, 'constants', 'campaign_management.yml') - languages_path = File.join(root_v11_path, 'constants', 'languages.yml') - limits_path = File.join(root_v11_path, 'constants', 'limits.yml') - time_zones_path = File.join(root_v11_path, 'constants', 'time_zones.yml') - wsdl_path = File.join(root_v11_path, 'constants', 'wsdl.yml') - - Persey.init(:default) do - source :yaml, campaign_management_path, :campaign_management - source :yaml, languages_path, :languages - source :yaml, limits_path, :limits - source :yaml, time_zones_path, :time_zones - source :yaml, wsdl_path, :wsdl - env :default - end - - Bing::Ads::API::V11.constants = Persey.config - end - end - end -end diff --git a/lib/bing/ads/api/v11/constants/wsdl.yml b/lib/bing/ads/api/v11/constants/wsdl.yml deleted file mode 100644 index 224bf79..0000000 --- a/lib/bing/ads/api/v11/constants/wsdl.yml +++ /dev/null @@ -1,10 +0,0 @@ -sandbox: - customer_management: https://clientcenter.api.sandbox.bingads.microsoft.com/Api/CustomerManagement/v11/CustomerManagementService.svc?singleWsdl - campaign_management: "https://campaign.api.sandbox.bingads.microsoft.com/Api/Advertiser/CampaignManagement/V11/CampaignManagementService.svc?singleWsdl" - reporting: "https://api.sandbox.bingads.microsoft.com/Api/Advertiser/Reporting/V11/ReportingService.svc?singleWsdl" - bulk: 'https://bulk.api.sandbox.bingads.microsoft.com/Api/Advertiser/CampaignManagement/V11/BulkService.svc?singleWsdl' -production: - customer_management: https://clientcenter.api.bingads.microsoft.com/Api/CustomerManagement/v11/CustomerManagementService.svc?singleWsdl - campaign_management: "https://campaign.api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/V11/CampaignManagementService.svc?singleWsdl" - reporting: "https://api.bingads.microsoft.com/Api/Advertiser/Reporting/V11/ReportingService.svc?singleWsdl" - bulk: 'https://bulk.api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/V11/BulkService.svc?singleWsdl' diff --git a/lib/bing/ads/api/v11/services/bulk.rb b/lib/bing/ads/api/v11/services/bulk.rb deleted file mode 100644 index c47322b..0000000 --- a/lib/bing/ads/api/v11/services/bulk.rb +++ /dev/null @@ -1,38 +0,0 @@ -module Bing - module Ads - module API - module V11 - module Services - # Bing::Ads::API::V11::Services::Bulk - class Bulk < Base - def initialize(options = {}) - super(options) - end - - def get_bulk_upload_url(account_id = nil, response_mode = 'ErrorsOnly') - account_id ||= @account_id - - response = call(__method__, response_mode: response_mode, account_id: account_id) - response_body = response_body(response, __method__) - response_body.slice(:request_id, :upload_url) - end - - def get_bulk_upload_status(request_id) - response = call(__method__, request_id: request_id) - response_body = response_body(response, __method__) - response_body.slice(:errors, :percent_complete, :request_status, :result_file_url) - end - - # TODO operations: https://msdn.microsoft.com/en-us/library/bing-ads-bulk-service-operations.aspx - - private - - def service_name - 'bulk' - end - end - end - end - end - end -end diff --git a/lib/bing/ads/api/v11.rb b/lib/bing/ads/api/v13.rb similarity index 74% rename from lib/bing/ads/api/v11.rb rename to lib/bing/ads/api/v13.rb index c9d1a57..2624f5b 100644 --- a/lib/bing/ads/api/v11.rb +++ b/lib/bing/ads/api/v13.rb @@ -1,9 +1,9 @@ module Bing module Ads module API - # Bing::Ads::API::V11 - module V11 - NAMESPACE_IDENTIFIER = :v11 + # Bing::Ads::API::V13 + module V13 + NAMESPACE_IDENTIFIER = :v13 def self.constants @_config || fail('Error loading bing ads gem') diff --git a/lib/bing/ads/api/v13/constants.rb b/lib/bing/ads/api/v13/constants.rb new file mode 100644 index 0000000..e1590f1 --- /dev/null +++ b/lib/bing/ads/api/v13/constants.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module Bing + module Ads + module API + # Bing::Ads::API::V13::Constants + module Constants + root_v13_path = File.expand_path('../', __FILE__) + + campaign_management_path = File.join(root_v13_path, 'constants', 'campaign_management.yml') + bulk_path = File.join(root_v13_path, 'constants', 'bulk.yml') + languages_path = File.join(root_v13_path, 'constants', 'languages.yml') + limits_path = File.join(root_v13_path, 'constants', 'limits.yml') + time_zones_path = File.join(root_v13_path, 'constants', 'time_zones.yml') + wsdl_path = File.join(root_v13_path, 'constants', 'wsdl.yml') + + Persey.init(:default) do + source :yaml, campaign_management_path, :campaign_management + source :yaml, bulk_path, :bulk + source :yaml, languages_path, :languages + source :yaml, limits_path, :limits + source :yaml, time_zones_path, :time_zones + source :yaml, wsdl_path, :wsdl + env :default + end + + Bing::Ads::API::V13.constants = Persey.config + end + end + end +end diff --git a/lib/bing/ads/api/v13/constants/bulk.yml b/lib/bing/ads/api/v13/constants/bulk.yml new file mode 100644 index 0000000..c1cf0d5 --- /dev/null +++ b/lib/bing/ads/api/v13/constants/bulk.yml @@ -0,0 +1,5 @@ +download_entities: + campaigns: 1 + ad_groups: 2 + ads: 3 + keywords: 4 diff --git a/lib/bing/ads/api/v11/constants/campaign_management.yml b/lib/bing/ads/api/v13/constants/campaign_management.yml similarity index 97% rename from lib/bing/ads/api/v11/constants/campaign_management.yml rename to lib/bing/ads/api/v13/constants/campaign_management.yml index 47cf1db..a92256d 100644 --- a/lib/bing/ads/api/v11/constants/campaign_management.yml +++ b/lib/bing/ads/api/v13/constants/campaign_management.yml @@ -52,9 +52,6 @@ campaign_status: budget_paused: BudgetPaused budget_and_manual_paused: BudgetAndManualPaused deleted: Deleted -pricing_model: - cpc: Cpc - cpm: Cpm keyword_editorial_statuses: active: Active disapproved: Disapproved @@ -66,7 +63,6 @@ keyword_statuses: inactive: Inactive match_types: broad: Broad - content: Content exact: Exact phrase: Phrase network: diff --git a/lib/bing/ads/api/v11/constants/languages.yml b/lib/bing/ads/api/v13/constants/languages.yml similarity index 100% rename from lib/bing/ads/api/v11/constants/languages.yml rename to lib/bing/ads/api/v13/constants/languages.yml diff --git a/lib/bing/ads/api/v11/constants/limits.yml b/lib/bing/ads/api/v13/constants/limits.yml similarity index 100% rename from lib/bing/ads/api/v11/constants/limits.yml rename to lib/bing/ads/api/v13/constants/limits.yml diff --git a/lib/bing/ads/api/v11/constants/time_zones.yml b/lib/bing/ads/api/v13/constants/time_zones.yml similarity index 92% rename from lib/bing/ads/api/v11/constants/time_zones.yml rename to lib/bing/ads/api/v13/constants/time_zones.yml index e7bd987..30f7374 100644 --- a/lib/bing/ads/api/v11/constants/time_zones.yml +++ b/lib/bing/ads/api/v13/constants/time_zones.yml @@ -1,7 +1,7 @@ abu_dhabi_muscat: 'AbuDhabiMuscat' adelaide: 'Adelaide' alaska: 'Alaska' -almaty_novosibirsk: 'Almaty_Novosibirsk' +almaty_novosibirsk: 'AlmatyNovosibirsk' amsterdam_berlin_bern_rome_stockholm_vienna: 'AmsterdamBerlinBernRomeStockholmVienna' arizona: 'Arizona' astana_dhaka: 'AstanaDhaka' @@ -51,11 +51,11 @@ kathmandu: 'Kathmandu' krasnoyarsk: 'Krasnoyarsk' kuala_lumpur_singapore: 'KualaLumpurSingapore' kuwait_riyadh: 'KuwaitRiyadh' -magadan_solomon_island_new_caledonia: 'MagadanSolomonIslandNewCaledonia' +solomon_island_new_caledonia: 'SolomonIslandNewCaledonia' mid_atlantic: 'MidAtlantic' -midway_islandand_samoa: 'MidwayIslandand_Samoa' +midway_islandand_samoa: 'MidwayIslandAndSamoa' moscow_st_petersburg_volgograd: 'MoscowStPetersburgVolgograd' -mountain_time_u_s_canada: 'MountainTime_US_Canada' +mountain_time_u_s_canada: 'MountainTimeUSCanada' nairobi: 'Nairobi' newfoundland: 'Newfoundland' nukualofa: 'Nukualofa' diff --git a/lib/bing/ads/api/v13/constants/wsdl.yml b/lib/bing/ads/api/v13/constants/wsdl.yml new file mode 100644 index 0000000..774499a --- /dev/null +++ b/lib/bing/ads/api/v13/constants/wsdl.yml @@ -0,0 +1,10 @@ +sandbox: + customer_management: "https://clientcenter.api.sandbox.bingads.microsoft.com/Api/CustomerManagement/v13/CustomerManagementService.svc?singleWsdl" + campaign_management: "https://campaign.api.sandbox.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v13/CampaignManagementService.svc?singleWsdl" + reporting: "https://reporting.api.sandbox.bingads.microsoft.com/Api/Advertiser/Reporting/v13/ReportingService.svc?singleWsdl" + bulk: 'https://bulk.api.sandbox.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v13/BulkService.svc?singleWsdl' +production: + customer_management: "https://clientcenter.api.bingads.microsoft.com/Api/CustomerManagement/v13/CustomerManagementService.svc?singleWsdl" + campaign_management: "https://campaign.api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v13/CampaignManagementService.svc?singleWsdl" + reporting: "https://reporting.api.bingads.microsoft.com/Api/Advertiser/Reporting/v13/ReportingService.svc?singleWsdl" + bulk: 'https://bulk.api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v13/BulkService.svc?singleWsdl' diff --git a/lib/bing/ads/api/v11/data.rb b/lib/bing/ads/api/v13/data.rb similarity index 82% rename from lib/bing/ads/api/v11/data.rb rename to lib/bing/ads/api/v13/data.rb index c44234d..9971057 100644 --- a/lib/bing/ads/api/v11/data.rb +++ b/lib/bing/ads/api/v13/data.rb @@ -3,3 +3,4 @@ require_relative './data/campaign' require_relative './data/keyword' require_relative './data/report_request' +require_relative './data/bulk_request' diff --git a/lib/bing/ads/api/v11/data/ad_group.rb b/lib/bing/ads/api/v13/data/ad_group.rb similarity index 64% rename from lib/bing/ads/api/v11/data/ad_group.rb rename to lib/bing/ads/api/v13/data/ad_group.rb index f3959ba..e6f9db2 100644 --- a/lib/bing/ads/api/v11/data/ad_group.rb +++ b/lib/bing/ads/api/v13/data/ad_group.rb @@ -1,35 +1,34 @@ module Bing module Ads module API - module V11 + module V13 module Data - # Bing::Ads::API::V11::Data::AdGroup + # Bing::Ads::API::V13::Data::AdGroup class AdGroup # @order # https://msdn.microsoft.com/en-us/library/bing-ads-campaign-management-adgroup.aspx - KEYS_ORDER = [ - :ad_distribution, - :ad_rotation, - :bidding_scheme, - :content_match_bid, - :end_date, - :forward_compatibility_map, - :id, - :language, - :name, - :native_bid_adjustment, - :network, - :pricing_model, - :remarketing_targeting_setting, - :search_bid, - :settings, - :start_date, - :status, - :tracking_url_template, - :url_custom_parameters - # Alphabetical - ] + # Alphabetical + KEYS_ORDER = %i[ + ad_distribution + ad_rotation + bidding_scheme + content_match_bid + end_date + forward_compatibility_map + id + language + name + native_bid_adjustment + network + remarketing_targeting_setting + search_bid + settings + start_date + status + tracking_url_template + url_custom_parameter + ].freeze def self.prepare(ad_group_raw) ad_group_raw[:ad_rotation] = { type: ad_group_raw[:ad_rotation] } if ad_group_raw[:ad_rotation] @@ -37,7 +36,7 @@ def self.prepare(ad_group_raw) # TODO support MaxClicksBiddingScheme, MaxConversionsBiddingScheme and TargetCpaBiddingScheme ad_group_raw[:bidding_scheme] = { type: ad_group_raw[:bidding_scheme], - '@xsi:type' => "#{Bing::Ads::API::V11::NAMESPACE_IDENTIFIER}:#{ad_group_raw[:bidding_scheme]}" + '@xsi:type' => "#{Bing::Ads::API::V13::NAMESPACE_IDENTIFIER}:#{ad_group_raw[:bidding_scheme]}" } end ad_group_raw[:content_match_bid] = { amount: ad_group_raw[:content_match_bid] } if ad_group_raw[:content_match_bid] diff --git a/lib/bing/ads/api/v13/data/bulk_request.rb b/lib/bing/ads/api/v13/data/bulk_request.rb new file mode 100644 index 0000000..ff7bfb4 --- /dev/null +++ b/lib/bing/ads/api/v13/data/bulk_request.rb @@ -0,0 +1,52 @@ +module Bing + module Ads + module API + module V13 + module Data + class BulkRequest + + KEYS_ORDER = %i[ + account_ids + compression_type + data_scope + download_entities + download_file_type + format_version + last_sync_time_in_utc + ].freeze + + class << self + def prepare(bulk_request_row) + bulk_request_row[:account_ids] = prepare_account_ids( + account_ids: bulk_request_row[:account_ids] + ) + bulk_request_row[:download_entities] = + prepare_download_entities( + levels: bulk_request_row.delete(:levels) + ) + bulk_request_row.except!(:levels) + bulk_request = Bing::Ads::Utils.sort_keys(bulk_request_row, KEYS_ORDER) + Bing::Ads::Utils.camelcase_keys(bulk_request) + end + + private + + def prepare_account_ids(account_ids:) + { + 'a1:long' => account_ids, + '@xmlns:a1' => 'http://schemas.microsoft.com/2003/10/Serialization/Arrays' + } + end + + def prepare_download_entities(levels:) + levels = %w[campaign] if levels.nil? || levels.empty? + entities = levels.map(&:pluralize).map(&:camelcase) + { download_entity: entities } + end + end + end + end + end + end + end +end diff --git a/lib/bing/ads/api/v11/data/campaign.rb b/lib/bing/ads/api/v13/data/campaign.rb similarity index 82% rename from lib/bing/ads/api/v11/data/campaign.rb rename to lib/bing/ads/api/v13/data/campaign.rb index ea80a3c..8f76764 100644 --- a/lib/bing/ads/api/v11/data/campaign.rb +++ b/lib/bing/ads/api/v13/data/campaign.rb @@ -1,23 +1,25 @@ module Bing module Ads module API - module V11 + module V13 module Data - # Bing::Ads::API::V11::Data::Campaign + # Bing::Ads::API::V13::Data::Campaign class Campaign # @order # https://msdn.microsoft.com/en-us/library/bing-ads-campaign-management-campaign.aspx KEYS_ORDER = [ + :audience_bid_adjustment, :bidding_scheme, :budget_type, :daily_budget, - :description, + :experiment_id, + :final_suffix_url, :forward_compatibility_map, :id, :name, - :native_bid_adjustment, :status, + :sub_type, :time_zone, :tracking_url_template, :url_custom_parameters, @@ -26,14 +28,14 @@ class Campaign :settings, :budget_id, :languages - ] + ].freeze def self.prepare(campaign_raw) if campaign_raw[:bidding_scheme] campaign_raw[:bidding_scheme] = { # TODO support MaxClicksBiddingScheme, MaxConversionsBiddingScheme and TargetCpaBiddingScheme type: campaign_raw[:bidding_scheme], - '@xsi:type' => "#{Bing::Ads::API::V11::NAMESPACE_IDENTIFIER}:#{campaign_raw[:bidding_scheme]}" + '@xsi:type' => "#{Bing::Ads::API::V13::NAMESPACE_IDENTIFIER}:#{campaign_raw[:bidding_scheme]}" } end # TODO UrlCustomParameters diff --git a/lib/bing/ads/api/v11/data/expanded_text_ad.rb b/lib/bing/ads/api/v13/data/expanded_text_ad.rb similarity index 52% rename from lib/bing/ads/api/v11/data/expanded_text_ad.rb rename to lib/bing/ads/api/v13/data/expanded_text_ad.rb index bcdf3e8..8e72bad 100644 --- a/lib/bing/ads/api/v11/data/expanded_text_ad.rb +++ b/lib/bing/ads/api/v13/data/expanded_text_ad.rb @@ -1,35 +1,30 @@ module Bing module Ads module API - module V11 + module V13 module Data - # Bing::Ads::API::V11::Data::ExpandedTextAd + # Bing::Ads::API::V13::Data::ExpandedTextAd class ExpandedTextAd # @order # https://msdn.microsoft.com/en-us/library/bing-ads-campaign-management-ad.aspx - KEYS_ORDER = [ - :ad_format_preference, - :device_preference, - :editorial_status, - :final_app_urls, - :final_mobile_urls, - :final_urls, - :forward_compatibility_map, - :id, - :status, - :tracking_url_template, - :url_custom_parameters, - :path_1, - :path_2, - :text, - :title_part_1, - :title_part_2, - :type - ] + KEYS_ORDER = %i[ + ad_format_preference + device_preference + editorial_status + final_app_urls + final_mobile_urls + final_urls + forward_compatibility_map + id + status + tracking_url_template + type + url_custom_parameters + ].freeze def self.prepare(ad_raw) - ad_raw['@xsi:type'] = "#{Bing::Ads::API::V11::NAMESPACE_IDENTIFIER}:#{ad_raw[:type]}" + ad_raw['@xsi:type'] = "#{Bing::Ads::API::V13::NAMESPACE_IDENTIFIER}:#{ad_raw[:type]}" # TODO FinalAppUrls ad_raw[:final_mobile_urls] = { 'ins1:string' => ad_raw[:final_mobile_urls] } if ad_raw[:final_mobile_urls] ad_raw[:final_urls] = { 'ins1:string' => ad_raw[:final_urls] } if ad_raw[:final_urls] diff --git a/lib/bing/ads/api/v11/data/keyword.rb b/lib/bing/ads/api/v13/data/keyword.rb similarity index 90% rename from lib/bing/ads/api/v11/data/keyword.rb rename to lib/bing/ads/api/v13/data/keyword.rb index e8f7438..07ec6d7 100644 --- a/lib/bing/ads/api/v11/data/keyword.rb +++ b/lib/bing/ads/api/v13/data/keyword.rb @@ -1,20 +1,21 @@ module Bing module Ads module API - module V11 + module V13 module Data - # Bing::Ads::API::V11::Data::Keyword + # Bing::Ads::API::V13::Data::Keyword class Keyword # @order # https://msdn.microsoft.com/en-us/library/bing-ads-campaign-management-keyword.aspx KEYS_ORDER = [ - :bidding_scheme, :bid, + :bidding_scheme, :destination_url, :editorial_status, :final_app_urls, :final_mobile_urls, + :final_url_suffix, :final_urls, :forward_compatibility_map, :id, @@ -26,8 +27,7 @@ class Keyword :text, :tracking_url_template, :url_custom_parameters - # Alphabetical - ] + ].freeze def self.prepare(keyword_raw) # To use the AdGroup default match type bid, @@ -37,7 +37,7 @@ def self.prepare(keyword_raw) # TODO support MaxClicksBiddingScheme, MaxConversionsBiddingScheme and TargetCpaBiddingScheme keyword_raw[:bidding_scheme] = { type: keyword_raw[:bidding_scheme], - '@xsi:type' => "#{Bing::Ads::API::V11::NAMESPACE_IDENTIFIER}:#{keyword_raw[:bidding_scheme]}" + '@xsi:type' => "#{Bing::Ads::API::V13::NAMESPACE_IDENTIFIER}:#{keyword_raw[:bidding_scheme]}" } end keyword_raw[:final_mobile_urls] = { 'ins1:string' => keyword_raw[:final_mobile_urls] } if keyword_raw[:final_mobile_urls] diff --git a/lib/bing/ads/api/v11/data/report_request.rb b/lib/bing/ads/api/v13/data/report_request.rb similarity index 82% rename from lib/bing/ads/api/v11/data/report_request.rb rename to lib/bing/ads/api/v13/data/report_request.rb index d6a4995..3a2ea53 100644 --- a/lib/bing/ads/api/v11/data/report_request.rb +++ b/lib/bing/ads/api/v13/data/report_request.rb @@ -1,33 +1,32 @@ module Bing module Ads module API - module V11 + module V13 module Data - # Bing::Ads::API::V11::Data::ReportRequest + # Bing::Ads::API::V13::Data::ReportRequest class ReportRequest # @order # https://msdn.microsoft.com/en-us/library/bing-ads-reporting-reportrequest.aspx - KEYS_ORDER = [ - :exclude_column_headers, - :exclude_report_footer, - :exclude_report_header, - :format, - :language, - :report_name, - :return_only_complete_data, - :aggregation, - :columns, - :filter, - :scope, - :time - ] + KEYS_ORDER = %i[ + exclude_column_headers + exclude_report_footer + exclude_report_header + format + report_name + return_only_complete_data + aggregation + columns + filter + scope + time + ].freeze class << self def prepare(type, report_request_raw) report_request_raw[:columns] = prepare_columns( columns: report_request_raw[:columns], - type: type.to_s.classify + type: type.to_s.camelcase ) report_request_raw[:scope] = prepare_scope( @@ -42,13 +41,13 @@ def prepare(type, report_request_raw) report_request_raw.except!(:from_date, :to_date, :account_ids) report_request = Bing::Ads::Utils.sort_keys(report_request_raw, KEYS_ORDER) - namespace_identifier = Bing::Ads::API::V11::NAMESPACE_IDENTIFIER + namespace_identifier = Bing::Ads::API::V13::NAMESPACE_IDENTIFIER { report_request: Bing::Ads::Utils.camelcase_keys(report_request), :attributes! => { report_request: { "xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance", - "i:type" => "#{namespace_identifier}:#{type.to_s.classify}ReportRequest" + "i:type" => "#{namespace_identifier}:#{type.to_s.camelcase}ReportRequest" } } } diff --git a/lib/bing/ads/api/v11/services.rb b/lib/bing/ads/api/v13/services.rb similarity index 100% rename from lib/bing/ads/api/v11/services.rb rename to lib/bing/ads/api/v13/services.rb diff --git a/lib/bing/ads/api/v11/services/base.rb b/lib/bing/ads/api/v13/services/base.rb similarity index 97% rename from lib/bing/ads/api/v11/services/base.rb rename to lib/bing/ads/api/v13/services/base.rb index 89f7492..f9f3aab 100644 --- a/lib/bing/ads/api/v11/services/base.rb +++ b/lib/bing/ads/api/v13/services/base.rb @@ -1,9 +1,9 @@ module Bing module Ads module API - module V11 + module V13 module Services - # Bing::Ads::API::V11::Base + # Bing::Ads::API::V13::Base class Base attr_accessor :soap_client, :environment, :retry_attempts @@ -27,7 +27,7 @@ def initialize(options = {}) @customer_id = options[:customer_id] raise 'You must set the service environment' unless @environment options[:wsdl_url] = service_wsdl_url - options[:namespace_identifier] = Bing::Ads::API::V11::NAMESPACE_IDENTIFIER + options[:namespace_identifier] = Bing::Ads::API::V13::NAMESPACE_IDENTIFIER @soap_client = Bing::Ads::API::SOAPClient.new(options) end @@ -112,7 +112,7 @@ def service_name # # @return String with the Service url def service_wsdl_url - Bing::Ads::API::V11.constants.wsdl.send(environment).send(service_name) + Bing::Ads::API::V13.constants.wsdl.send(environment).send(service_name) end def handle_soap_fault(operation, fault_detail, key) diff --git a/lib/bing/ads/api/v13/services/bulk.rb b/lib/bing/ads/api/v13/services/bulk.rb new file mode 100644 index 0000000..e9bb80b --- /dev/null +++ b/lib/bing/ads/api/v13/services/bulk.rb @@ -0,0 +1,59 @@ +module Bing + module Ads + module API + module V13 + module Services + # Bing::Ads::API::V13::Services::Bulk + class Bulk < Base + def initialize(options = {}) + super(options) + end + + def get_bulk_upload_url(account_id = nil, response_mode = 'ErrorsOnly') + account_id ||= @account_id + + response = call(__method__, response_mode: response_mode, account_id: account_id) + response_body = response_body(response, __method__) + response_body.slice(:request_id, :upload_url) + end + + def get_bulk_upload_status(request_id) + response = call(__method__, request_id: request_id) + response_body = response_body(response, __method__) + response_body.slice(:errors, :percent_complete, :request_status, :result_file_url) + end + + def download_campaigns_by_account_ids(options) + payload = Bing::Ads::API::V13::Data::BulkRequest.prepare(options) + response = call(__method__, payload) + response_body = response_body(response, __method__) + response_body.slice(:download_request_id) + end + + # def download_campaigns_by_campaign_ids(options) + # options[:account_ids] ||= [@account_id] + # options[:download_entities] ||= [] + # response = call(__method__, response_mode: response_mode, account_id: account_id) + # response_body = response_body(response, __method__) + # response_body.slice(:request_id, :download_url) + # end + + def get_bulk_download_status(request_id) + response = call(__method__, request_id: request_id) + response_body = response_body(response, __method__) + response_body.slice(:errors, :percent_complete, :request_status, :result_file_url) + end + + # TODO operations: https://msdn.microsoft.com/en-us/library/bing-ads-bulk-service-operations.aspx + + private + + def service_name + 'bulk' + end + end + end + end + end + end +end diff --git a/lib/bing/ads/api/v11/services/campaign_management.rb b/lib/bing/ads/api/v13/services/campaign_management.rb similarity index 93% rename from lib/bing/ads/api/v11/services/campaign_management.rb rename to lib/bing/ads/api/v13/services/campaign_management.rb index 6587391..e785a4a 100644 --- a/lib/bing/ads/api/v11/services/campaign_management.rb +++ b/lib/bing/ads/api/v13/services/campaign_management.rb @@ -1,9 +1,9 @@ module Bing module Ads module API - module V11 + module V13 module Services - # Bing::Ads::API::V11::Services::CampaignManagement + # Bing::Ads::API::V13::Services::CampaignManagement class CampaignManagement < Base def initialize(options = {}) super(options) @@ -29,7 +29,7 @@ def get_campaigns_by_ids(account_id, campaign_ids) def add_campaigns(account_id, campaigns) validate_limits!(:campaign, :add, campaigns) - campaigns = campaigns.map { |campaign| Bing::Ads::API::V11::Data::Campaign.prepare(campaign) } + campaigns = campaigns.map { |campaign| Bing::Ads::API::V13::Data::Campaign.prepare(campaign) } payload = { account_id: account_id, campaigns: { campaign: campaigns } @@ -40,7 +40,7 @@ def add_campaigns(account_id, campaigns) def update_campaigns(account_id, campaigns) validate_limits!(:campaign, :update, campaigns) - campaigns = campaigns.map { |campaign| Bing::Ads::API::V11::Data::Campaign.prepare(campaign) } + campaigns = campaigns.map { |campaign| Bing::Ads::API::V13::Data::Campaign.prepare(campaign) } payload = { account_id: account_id, campaigns: { campaign: campaigns } @@ -78,7 +78,7 @@ def get_ad_groups_by_ids(campaign_id, ad_groups_ids) def add_ad_groups(campaign_id, ad_groups) validate_limits!(:ad_group, :add, ad_groups) - ad_groups = ad_groups.map { |ad_group| Bing::Ads::API::V11::Data::AdGroup.prepare(ad_group) } + ad_groups = ad_groups.map { |ad_group| Bing::Ads::API::V13::Data::AdGroup.prepare(ad_group) } payload = { campaign_id: campaign_id, ad_groups: { ad_group: ad_groups } @@ -89,7 +89,7 @@ def add_ad_groups(campaign_id, ad_groups) def update_ad_groups(campaign_id, ad_groups) validate_limits!(:ad_group, :update, ad_groups) - ad_groups = ad_groups.map { |ad_group| Bing::Ads::API::V11::Data::AdGroup.prepare(ad_group) } + ad_groups = ad_groups.map { |ad_group| Bing::Ads::API::V13::Data::AdGroup.prepare(ad_group) } payload = { campaign_id: campaign_id, ad_groups: { ad_group: ad_groups } @@ -142,7 +142,7 @@ def get_ads_by_ids(ad_group_id, ad_ids) def add_ads(ad_group_id, ads) validate_limits!(:ad, :add, ads) - ads = ads.map { |ad| Bing::Ads::API::V11::Data::ExpandedTextAd.prepare(ad) } + ads = ads.map { |ad| Bing::Ads::API::V13::Data::ExpandedTextAd.prepare(ad) } payload = { ad_group_id: ad_group_id, ads: { ad: ads } @@ -153,7 +153,7 @@ def add_ads(ad_group_id, ads) def update_ads(ad_group_id, ads) validate_limits!(:ad, :update, ads) - ads = ads.map { |ad| Bing::Ads::API::V11::Data::ExpandedTextAd.prepare(ad) } + ads = ads.map { |ad| Bing::Ads::API::V13::Data::ExpandedTextAd.prepare(ad) } payload = { ad_group_id: ad_group_id, ads: { ad: ads } @@ -190,7 +190,7 @@ def get_keywords_by_ids(ad_group_id, keyword_ids) def add_keywords(ad_group_id, keywords) validate_limits!(:keyword, :add, keywords) - keywords = keywords.map { |keyword| Bing::Ads::API::V11::Data::Keyword.prepare(keyword) } + keywords = keywords.map { |keyword| Bing::Ads::API::V13::Data::Keyword.prepare(keyword) } payload = { ad_group_id: ad_group_id, keywords: { keyword: keywords } @@ -201,7 +201,7 @@ def add_keywords(ad_group_id, keywords) def update_keywords(ad_group_id, keywords) validate_limits!(:keyword, :update, keywords) - keywords = keywords.map { |keyword| Bing::Ads::API::V11::Data::Keyword.prepare(keyword) } + keywords = keywords.map { |keyword| Bing::Ads::API::V13::Data::Keyword.prepare(keyword) } payload = { ad_group_id: ad_group_id, keywords: { keyword: keywords } @@ -310,7 +310,7 @@ def service_name end def validate_limits!(type, operation, array) - limit = Bing::Ads::API::V11.constants.limits.per_call.send(type) + limit = Bing::Ads::API::V13.constants.limits.per_call.send(type) if array.size > limit raise Bing::Ads::API::Errors::LimitError.new(operation, limit, type) end @@ -319,11 +319,11 @@ def validate_limits!(type, operation, array) def all_ad_types { ad_type: [ - Bing::Ads::API::V11.constants.campaign_management.ad_types_for_get.text, - Bing::Ads::API::V11.constants.campaign_management.ad_types_for_get.expanded_text, - Bing::Ads::API::V11.constants.campaign_management.ad_types_for_get.image, - Bing::Ads::API::V11.constants.campaign_management.ad_types_for_get.product, - Bing::Ads::API::V11.constants.campaign_management.ad_types_for_get.app_install + Bing::Ads::API::V13.constants.campaign_management.ad_types_for_get.text, + Bing::Ads::API::V13.constants.campaign_management.ad_types_for_get.expanded_text, + Bing::Ads::API::V13.constants.campaign_management.ad_types_for_get.image, + Bing::Ads::API::V13.constants.campaign_management.ad_types_for_get.product, + Bing::Ads::API::V13.constants.campaign_management.ad_types_for_get.app_install ] } end diff --git a/lib/bing/ads/api/v11/services/customer_management.rb b/lib/bing/ads/api/v13/services/customer_management.rb similarity index 92% rename from lib/bing/ads/api/v11/services/customer_management.rb rename to lib/bing/ads/api/v13/services/customer_management.rb index 0aab941..6ce6e87 100644 --- a/lib/bing/ads/api/v11/services/customer_management.rb +++ b/lib/bing/ads/api/v13/services/customer_management.rb @@ -1,9 +1,9 @@ module Bing module Ads module API - module V11 + module V13 module Services - # Bing::Ads::API::V11::Services::CustomerManagement + # Bing::Ads::API::V13::Services::CustomerManagement class CustomerManagement < Base def initialize(options = {}) super(options) diff --git a/lib/bing/ads/api/v11/services/reporting.rb b/lib/bing/ads/api/v13/services/reporting.rb similarity index 86% rename from lib/bing/ads/api/v11/services/reporting.rb rename to lib/bing/ads/api/v13/services/reporting.rb index 82922da..3ac52df 100644 --- a/lib/bing/ads/api/v11/services/reporting.rb +++ b/lib/bing/ads/api/v13/services/reporting.rb @@ -1,16 +1,16 @@ module Bing module Ads module API - module V11 + module V13 module Services - # Bing::Ads::API::V11::Services::CampaignManagement + # Bing::Ads::API::V13::Services::CampaignManagement class Reporting < Base def initialize(options = {}) super(options) end def submit_generate_report(type, report_options) - payload = Bing::Ads::API::V11::Data::ReportRequest.prepare(type, report_options) + payload = Bing::Ads::API::V13::Data::ReportRequest.prepare(type, report_options) response = call(:submit_generate_report, payload) response_body = response_body(response, __method__) response_body @@ -35,6 +35,9 @@ def report_url(report_request_id) end def report_body(report_request_id) + report_url = report_url(report_request_id) + return if report_url.nil? + HttpClient.download(report_url(report_request_id)) end diff --git a/lib/bing/ads/version.rb b/lib/bing/ads/version.rb index b2ead12..c5ab5f7 100644 --- a/lib/bing/ads/version.rb +++ b/lib/bing/ads/version.rb @@ -1,5 +1,5 @@ module Bing module Ads - VERSION = '12.0.0'.freeze + VERSION = '13.0.0'.freeze end end