diff --git a/README.md b/README.md index bcf0912..52c945b 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,15 @@ [![Gem Version](https://img.shields.io/gem/v/bing-ads.svg)](https://rubygems.org/gems/bing-ads) [![Build Status](https://travis-ci.org/FindHotel/bing-ads.svg?branch=master)](https://travis-ci.org/FindHotel/bing-ads) +## We have not tested all pieces of functionality for this gem! +Please look [here](https://docs.microsoft.com/en-us/bingads/guides/migration-guide?view=bingads-13) if you're using this gem to make sure that the functionality you're looking for didn't experience a breaking change + # Bing::Ads +## An ezcater fork of a Bing Ads API client + +We forked this repo in order to upgrade to API V12 (and now V13). + A Ruby client for Bing Ads API that includes a proxy to all Bing Ads API web services and abstracts low level details of authentication with OAuth. ## Installation @@ -37,7 +44,7 @@ options = { # client_settings: { logger: LOGGER::STDOUT } } -service = Bing::Ads::API::V11::Services::CustomerManagement.new(options) +service = Bing::Ads::API::V13::Services::CustomerManagement.new(options) ``` #### Getting accounts info @@ -60,7 +67,7 @@ options = { # client_settings: { logger: LOGGER::STDOUT } } -service = Bing::Ads::API::V11::Services::CampaignManagement.new(options) +service = Bing::Ads::API::V13::Services::CampaignManagement.new(options) ``` #### Getting campaigns @@ -81,12 +88,12 @@ response = service.get_campaigns_by_ids(account_id, campaign_ids) account_id = 5278183 campaigns = [ { - budget_type: Bing::Ads::API::V11.constants.campaign_management.budget_limit_type.daily_budget_standard, + budget_type: Bing::Ads::API::V13.constants.campaign_management.budget_limit_type.daily_budget_standard, daily_budget: 2000, description: 'Amsterdam-based global campaign', name: '51 - Global - Chain - Mixed - N -en- Amsterdam - 100 - 26479', - status: Bing::Ads::API::V11.constants.campaign_management.campaign_status.paused, - time_zone: Bing::Ads::API::V11.constants.time_zones.amsterdam_berlin_bern_rome_stockholm_vienna + status: Bing::Ads::API::V13.constants.campaign_management.campaign_status.paused, + time_zone: Bing::Ads::API::V13.constants.time_zones.amsterdam_berlin_bern_rome_stockholm_vienna }, # ... ] @@ -100,11 +107,11 @@ account_id = 5278183 campaigns = [ { id: 813721838, - budget_type: Bing::Ads::API::V11.constants.campaign_management.budget_limit_type.daily_budget_standard, + budget_type: Bing::Ads::API::V13.constants.campaign_management.budget_limit_type.daily_budget_standard, }, { id: 813721849, - budget_type: Bing::Ads::API::V11.constants.campaign_management.budget_limit_type.daily_budget_standard, + budget_type: Bing::Ads::API::V13.constants.campaign_management.budget_limit_type.daily_budget_standard, }, # ... ] @@ -141,16 +148,16 @@ response = service.get_ad_groups_by_ids(campaign_id, ad_group_ids) campaign_id = 813721838 ad_groups = [ { - ad_distribution: Bing::Ads::API::V11.constants.campaign_management.ad_distribution.search, # required - ad_rotation: Bing::Ads::API::V11.constants.campaign_management.ad_rotation.optimize_for_clicks, # optional - bidding_scheme: Bing::Ads::API::V11.constants.campaign_management.bidding_scheme.inherit_from_parent, # optional + ad_distribution: Bing::Ads::API::V13.constants.campaign_management.ad_distribution.search, # required + ad_rotation: Bing::Ads::API::V13.constants.campaign_management.ad_rotation.optimize_for_clicks, # optional + bidding_scheme: Bing::Ads::API::V13.constants.campaign_management.bidding_scheme.inherit_from_parent, # optional content_match_bid: 100, # optional end_date: '31/12/2020', - status: Bing::Ads::API::V11.constants.campaign_management.ad_group_status.paused, - language: Bing::Ads::API::V11.constants.languages.english, + status: Bing::Ads::API::V13.constants.campaign_management.ad_group_status.paused, + language: Bing::Ads::API::V13.constants.languages.english, name: 'H=WHotelAmsterdam&AG=1723812002', native_bid_adjustment: -50, # optional (-100 to 900) - remarketing_targeting_setting: Bing::Ads::API::V11.constants.campaign_management.remarketing_target_setting.bid_only, # optional + remarketing_targeting_setting: Bing::Ads::API::V13.constants.campaign_management.remarketing_target_setting.bid_only, # optional search_bid: 100, # optional start_date: '5/7/2017', }, @@ -169,7 +176,7 @@ campaign_id = 813721838 ad_groups = [ { id: 9866221838, - status: Bing::Ads::API::V11.constants.campaign_management.ad_group_status.active + status: Bing::Ads::API::V13.constants.campaign_management.ad_group_status.active }, # ... ] @@ -205,7 +212,7 @@ response = service.get_ads_by_ids(ad_group_id, ad_ids) ad_group_id = 9866221838 expanded_text_ads = [ { - type: Bing::Ads::API::V11.constants.campaign_management.ad_types.expanded_text_ad, # ExpandedTextAd + type: Bing::Ads::API::V13.constants.campaign_management.ad_types.expanded_text_ad, # ExpandedTextAd path_1: 'Amsterdam', path_2: 'Hotels', text: 'Compare over 150 booking sites! Find guaranteed low hotel rates.', @@ -270,14 +277,14 @@ response = service.get_keywords_by_ids(ad_group_id, keyword_ids) ad_group_id = 9866221838 keywords = [ { - bidding_scheme: Bing::Ads::API::V11.constants.campaign_management.bidding_scheme.inherit_from_parent, + bidding_scheme: Bing::Ads::API::V13.constants.campaign_management.bidding_scheme.inherit_from_parent, bid: 5, # optional, ad final urls used if this is not set final_urls: [ 'https://www.findhotel.net/Places/Amsterdam.htm?attrs=pet-friendly' ], - match_type: Bing::Ads::API::V11.constants.campaign_management.match_types.exact, # also broad, content, phrase - status: Bing::Ads::API::V11.constants.campaign_management.keyword_statuses.active, + match_type: Bing::Ads::API::V13.constants.campaign_management.match_types.exact, # also broad, content, phrase + status: Bing::Ads::API::V13.constants.campaign_management.keyword_statuses.active, text: 'Pet-friendly Hotels in Amsterdam' }, # ... @@ -296,6 +303,11 @@ ad_group_id = 9866221838 updated_keywords = [ { id: 234873284248, + final_urls: [ '...' ], + tracking_url_template: '', + url_custom_parameters: { + foo: 'bar' + } # updated attributes }, # ... @@ -326,7 +338,7 @@ options = { # client_settings: { logger: LOGGER::STDOUT } } -service = Bing::Ads::API::V11::Services::Bulk.new(options) +service = Bing::Ads::API::V13::Services::Bulk.new(options) ``` #### Submit a request for a URL where a bulk upload file may be posted. @@ -368,7 +380,7 @@ options = { # client_settings: { logger: LOGGER::STDOUT } } -service = Bing::Ads::API::V11::Services::Reporting.new(options) +service = Bing::Ads::API::V13::Services::Reporting.new(options) ``` #### Submit Generate Report @@ -400,7 +412,7 @@ The required options depend on the report type you are using. Response example: ```ruby -{:report_request_id=>"30000000999745662", :@xmlns=>"https://bingads.microsoft.com/Reporting/v11"} +{:report_request_id=>"30000000999745662", :@xmlns=>"https://bingads.microsoft.com/Reporting/v13"} ``` #### Poll Generate Report diff --git a/bing-ads.gemspec b/bing-ads.gemspec index b67662f..2fbb0fa 100644 --- a/bing-ads.gemspec +++ b/bing-ads.gemspec @@ -8,7 +8,7 @@ Gem::Specification.new do |spec| spec.version = Bing::Ads::VERSION spec.authors = ["oss92"] spec.email = ["mohamed.o.alnagdy@gmail.com", "oss@findhotel.net"] - spec.license = 'MIT' + spec.license = "MIT" spec.summary = %q{Enhances the experience of developing Bing Ads applications with Ruby} spec.description = %q{A Ruby client for Bing Ads API that includes a proxy to all Bing Ads API web services and abstracts low level details of authentication with OAuth2.} @@ -21,11 +21,11 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_dependency 'savon', '~> 2.11' - spec.add_dependency 'activesupport', '~> 5.0' - spec.add_dependency 'persey', '~> 0.0.11' + spec.add_dependency "savon", "~> 2.13" + spec.add_dependency "activesupport", ">= 7.0", "< 8.1" + spec.add_dependency "persey", "~> 1.0.0" - spec.add_development_dependency "bundler", "~> 1.15" - spec.add_development_dependency "rake", "~> 10.0" - spec.add_development_dependency "rspec", "~> 3.0" + spec.add_development_dependency "bundler", "~> 2.5" + spec.add_development_dependency "rake", "~> 13.0" + spec.add_development_dependency "rspec", "~> 3.12" end diff --git a/lib/bing/ads.rb b/lib/bing/ads.rb index 1984d6a..4a2c5ff 100644 --- a/lib/bing/ads.rb +++ b/lib/bing/ads.rb @@ -8,10 +8,10 @@ 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/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/http_client.rb b/lib/bing/ads/api/http_client.rb index b28caee..08cb4e1 100644 --- a/lib/bing/ads/api/http_client.rb +++ b/lib/bing/ads/api/http_client.rb @@ -7,7 +7,12 @@ class HttpClient def self.download(url, retry_count = API_CALL_RETRY_COUNT) 1.upto(retry_count + 1) do |retry_index| - response = Net::HTTP.get_response(URI(url)) + http = Net::HTTP.new(URI(url)) + http.use_ssl = true + http.ssl_version = :TLSv1 + http.ciphers = ['RC4-SHA'] + http.get(uri.request_uri) + response = http.get_response(URI(url)) if response.is_a?(Net::HTTPSuccess) break response.body else 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/v11/constants.rb b/lib/bing/ads/api/v13/constants.rb similarity index 53% rename from lib/bing/ads/api/v11/constants.rb rename to lib/bing/ads/api/v13/constants.rb index 8a85fe1..268a4ac 100644 --- a/lib/bing/ads/api/v11/constants.rb +++ b/lib/bing/ads/api/v13/constants.rb @@ -3,15 +3,15 @@ module Bing module Ads module API - # Bing::Ads::API::V11::Constants + # Bing::Ads::API::V13::Constants module Constants - root_v11_path = File.expand_path('../', __FILE__) + root_v13_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') + campaign_management_path = File.join(root_v13_path, 'constants', 'campaign_management.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 @@ -22,7 +22,7 @@ module Constants env :default end - Bing::Ads::API::V11.constants = Persey.config + Bing::Ads::API::V13.constants = Persey.config end end end diff --git a/lib/bing/ads/api/v11/constants/campaign_management.yml b/lib/bing/ads/api/v13/constants/campaign_management.yml similarity index 100% rename from lib/bing/ads/api/v11/constants/campaign_management.yml rename to lib/bing/ads/api/v13/constants/campaign_management.yml 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 100% rename from lib/bing/ads/api/v11/constants/time_zones.yml rename to lib/bing/ads/api/v13/constants/time_zones.yml diff --git a/lib/bing/ads/api/v11/constants/wsdl.yml b/lib/bing/ads/api/v13/constants/wsdl.yml similarity index 50% rename from lib/bing/ads/api/v11/constants/wsdl.yml rename to lib/bing/ads/api/v13/constants/wsdl.yml index 224bf79..b2f0543 100644 --- a/lib/bing/ads/api/v11/constants/wsdl.yml +++ b/lib/bing/ads/api/v13/constants/wsdl.yml @@ -1,10 +1,10 @@ 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' + 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://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/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' + 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 100% rename from lib/bing/ads/api/v11/data.rb rename to lib/bing/ads/api/v13/data.rb diff --git a/lib/bing/ads/api/v11/data/ad_group.rb b/lib/bing/ads/api/v13/data/ad_group.rb similarity index 94% rename from lib/bing/ads/api/v11/data/ad_group.rb rename to lib/bing/ads/api/v13/data/ad_group.rb index f3959ba..42f8375 100644 --- a/lib/bing/ads/api/v11/data/ad_group.rb +++ b/lib/bing/ads/api/v13/data/ad_group.rb @@ -1,9 +1,9 @@ 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 @@ -37,7 +37,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/v11/data/campaign.rb b/lib/bing/ads/api/v13/data/campaign.rb similarity index 91% rename from lib/bing/ads/api/v11/data/campaign.rb rename to lib/bing/ads/api/v13/data/campaign.rb index ea80a3c..c44bd24 100644 --- a/lib/bing/ads/api/v11/data/campaign.rb +++ b/lib/bing/ads/api/v13/data/campaign.rb @@ -1,9 +1,9 @@ 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 @@ -33,7 +33,7 @@ def self.prepare(campaign_raw) 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 90% 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..9f77779 100644 --- a/lib/bing/ads/api/v11/data/expanded_text_ad.rb +++ b/lib/bing/ads/api/v13/data/expanded_text_ad.rb @@ -1,9 +1,9 @@ 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 @@ -29,7 +29,7 @@ class ExpandedTextAd ] 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 53% rename from lib/bing/ads/api/v11/data/keyword.rb rename to lib/bing/ads/api/v13/data/keyword.rb index e8f7438..2f0e644 100644 --- a/lib/bing/ads/api/v11/data/keyword.rb +++ b/lib/bing/ads/api/v13/data/keyword.rb @@ -1,9 +1,9 @@ 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 @@ -32,20 +32,40 @@ class Keyword def self.prepare(keyword_raw) # To use the AdGroup default match type bid, # set the Amount element of the Bid object to null. - keyword_raw[:bid] = { amount: keyword_raw[:bid] } + keyword_raw[:bid] = { amount: keyword_raw[:bid] } if keyword_raw.has_key? :bid if keyword_raw[:bidding_scheme] # 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 + + if keyword_raw[:final_mobile_urls] + keyword_raw[:final_mobile_urls] = { + 'a1:string' => keyword_raw[:final_mobile_urls], + '@xmlns:a1' => 'http://schemas.microsoft.com/2003/10/Serialization/Arrays' + } + end + if keyword_raw[:final_urls] + keyword_raw[:final_urls] = { + 'a1:string' => keyword_raw[:final_urls], + '@xmlns:a1' => 'http://schemas.microsoft.com/2003/10/Serialization/Arrays' } end - keyword_raw[:final_mobile_urls] = { 'ins1:string' => keyword_raw[:final_mobile_urls] } if keyword_raw[:final_mobile_urls] - keyword_raw[:final_urls] = { 'ins1:string' => keyword_raw[:final_urls] } if keyword_raw[:final_urls] # TODO FinalAppUrls - # TODO UrlCustomParameters + keyword_raw = Bing::Ads::Utils.sort_keys(keyword_raw) Bing::Ads::Utils.camelcase_keys(keyword_raw) + if keyword_raw.has_key? :url_custom_parameters + keyword_raw['UrlCustomParameters'] = { 'Parameters' => {'CustomParameter' => []} } + keyword_raw[:url_custom_parameters].each do |k,v| + keyword_raw['UrlCustomParameters']['Parameters']['CustomParameter'].push({ 'Key' => k, 'Value' => v}) + end + keyword_raw.delete :url_custom_parameters + end + + keyword_raw end end end diff --git a/lib/bing/ads/api/v11/data/report_request.rb b/lib/bing/ads/api/v13/data/report_request.rb similarity index 95% rename from lib/bing/ads/api/v11/data/report_request.rb rename to lib/bing/ads/api/v13/data/report_request.rb index d6a4995..87a9153 100644 --- a/lib/bing/ads/api/v11/data/report_request.rb +++ b/lib/bing/ads/api/v13/data/report_request.rb @@ -1,9 +1,9 @@ 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 @@ -19,6 +19,7 @@ class ReportRequest :aggregation, :columns, :filter, + :max_rows, :scope, :time ] @@ -42,7 +43,7 @@ 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! => { 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 96% rename from lib/bing/ads/api/v11/services/base.rb rename to lib/bing/ads/api/v13/services/base.rb index 89f7492..1c04a95 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 @@ -49,7 +49,7 @@ def call(operation, payload) raise 'You must provide an operation' if operation.nil? begin response = soap_client.call(operation: operation.to_sym, payload: payload) - return response.hash + return response.full_hash rescue Savon::SOAPFault => error fault = error.to_hash[:fault] @@ -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/v11/services/bulk.rb b/lib/bing/ads/api/v13/services/bulk.rb similarity index 94% rename from lib/bing/ads/api/v11/services/bulk.rb rename to lib/bing/ads/api/v13/services/bulk.rb index c47322b..414d1a5 100644 --- a/lib/bing/ads/api/v11/services/bulk.rb +++ b/lib/bing/ads/api/v13/services/bulk.rb @@ -1,9 +1,9 @@ module Bing module Ads module API - module V11 + module V13 module Services - # Bing::Ads::API::V11::Services::Bulk + # Bing::Ads::API::V13::Services::Bulk class Bulk < Base def initialize(options = {}) super(options) diff --git a/lib/bing/ads/api/v11/services/campaign_management.rb b/lib/bing/ads/api/v13/services/campaign_management.rb similarity index 86% rename from lib/bing/ads/api/v11/services/campaign_management.rb rename to lib/bing/ads/api/v13/services/campaign_management.rb index 6587391..be5a214 100644 --- a/lib/bing/ads/api/v11/services/campaign_management.rb +++ b/lib/bing/ads/api/v13/services/campaign_management.rb @@ -1,26 +1,49 @@ 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) end + + def get_experiments_by_ids(experiments=[]) + account_id ||= @account_id + payload = { + experiment_ids: { + 'a1:long' => experiments, + '@xmlns:a1' => 'http://schemas.microsoft.com/2003/10/Serialization/Arrays' + } + } + response = call(:get_experiments_by_ids, payload) + response_body = response_body(response, __method__) + [response_body[:experiments][:experiment]].flatten.compact + end - def get_campaigns_by_account_id(account_id=nil) + def get_campaigns_by_account_id(account_id=nil, campaign_type: "Search") account_id ||= @account_id - response = call(:get_campaigns_by_account_id, account_id: account_id) + response = call(:get_campaigns_by_account_id, account_id: account_id, campaign_type: campaign_type) response_body = response_body(response, __method__) [response_body[:campaigns][:campaign]].flatten.compact end def get_campaigns_by_ids(account_id, campaign_ids) account_id ||= @account_id + campaign_ids_elements = + if campaign_ids.nil? + nil + else + { + 'a1:long' => campaign_ids, + '@xmlns:a1' => 'http://schemas.microsoft.com/2003/10/Serialization/Arrays' + } + end + payload = { account_id: account_id, - campaign_ids: { 'ins1:long' => campaign_ids } + campaign_ids: campaign_ids_elements } response = call(:get_campaigns_by_ids, payload) response_body = response_body(response, __method__) @@ -29,7 +52,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 +63,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 +101,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 +112,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 +165,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 +176,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 +213,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 +224,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 +333,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 +342,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 91% rename from lib/bing/ads/api/v11/services/reporting.rb rename to lib/bing/ads/api/v13/services/reporting.rb index 82922da..5db8071 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 diff --git a/lib/bing/ads/version.rb b/lib/bing/ads/version.rb index 8707b80..07d721f 100644 --- a/lib/bing/ads/version.rb +++ b/lib/bing/ads/version.rb @@ -1,5 +1,5 @@ module Bing module Ads - VERSION = '0.2.0' + VERSION = '0.4.0' end end