Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #12 from adwyze/bing-v12
Browse files Browse the repository at this point in the history
Upgrade bing api to V12
  • Loading branch information
zzet authored Mar 4, 2019
2 parents d990a4e + b55c103 commit f1a36e7
Show file tree
Hide file tree
Showing 26 changed files with 1,223 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# rspec failure tracking
.rspec_status
.idea/

# built gem files
*.gem
1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

2 changes: 1 addition & 1 deletion bing-ads.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Gem::Specification.new do |spec|

spec.add_dependency 'savon', '~> 2.11'
spec.add_dependency 'activesupport', '~> 5.0'
spec.add_dependency 'persey', '~> 0.0.11'
spec.add_dependency 'persey', '~> 1.0.0'

spec.add_development_dependency "bundler", "~> 1.15"
spec.add_development_dependency "rake", "~> 10.0"
Expand Down
4 changes: 4 additions & 0 deletions lib/bing/ads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
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/utils'
require 'bing/ads/version'
Expand Down
18 changes: 18 additions & 0 deletions lib/bing/ads/api/v12.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Bing
module Ads
module API
# Bing::Ads::API::V11
module V12
NAMESPACE_IDENTIFIER = :v12

def self.constants
@_config || fail('Error loading bing ads gem')
end

def self.constants=(config)
@_config = config
end
end
end
end
end
31 changes: 31 additions & 0 deletions lib/bing/ads/api/v12/constants.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

module Bing
module Ads
module API
# Bing::Ads::API::V12::Constants
module Constants
root_v12_path = File.expand_path('../', __FILE__)

campaign_management_path = File.join(root_v12_path, 'constants', 'campaign_management.yml')
bulk_path = File.join(root_v12_path, 'constants', 'bulk.yml')
languages_path = File.join(root_v12_path, 'constants', 'languages.yml')
limits_path = File.join(root_v12_path, 'constants', 'limits.yml')
time_zones_path = File.join(root_v12_path, 'constants', 'time_zones.yml')
wsdl_path = File.join(root_v12_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::V12.constants = Persey.config
end
end
end
end
5 changes: 5 additions & 0 deletions lib/bing/ads/api/v12/constants/bulk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
download_entities:
campaigns: 1
ad_groups: 2
ads: 3
keywords: 4
74 changes: 74 additions & 0 deletions lib/bing/ads/api/v12/constants/campaign_management.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
ad_distribution:
search: Search
content: Content
ad_rotation:
optimize_for_clicks: OptimizeForClicks
rotate_ads_evenly: RotateAdsEvenly
ad_group_status:
draft: Draft
active: Active
paused: Paused
deleted: Deleted
ad_editorial_status:
active: Active
disapproved: Disapproved
inactive: Inactive
active_limited: ActiveLimited
ad_status:
inactive: Inactive
active: Active
paused: Paused
deleted: Deleted
ad_types:
text_ad: TextAd
image_ad: ImageAd
product_ad: ProductAd
app_install_ad: AppInstallAd
expanded_text_ad: ExpandedTextAd
dynamic_search_ad: DynamicSearchAd
ad_types_for_get:
text: Text
image: Image
product: Product
app_install: AppInstall
expanded_text: ExpandedText
dynamic_search: DynamicSearch
bidding_model:
keyword: Keyword
site_placement: SitePlacement
bidding_scheme:
manual_cpc: ManualCpcBiddingScheme
enhanced_cpc: EnhancedCpcBiddingScheme
inherit_from_parent: InheritFromParentBiddingScheme
max_clicks: MaxClicksBiddingScheme
max_conversions: MaxConversionsBiddingScheme
target_cpa: TargetCpaBiddingScheme
budget_limit_type:
daily_budget_accelerated: DailyBudgetAccelerated
daily_budget_standard: DailyBudgetStandard
campaign_status:
active: Active
paused: Paused
budget_paused: BudgetPaused
budget_and_manual_paused: BudgetAndManualPaused
deleted: Deleted
keyword_editorial_statuses:
active: Active
disapproved: Disapproved
inactive: Inactive
keyword_statuses:
active: Active
paused: Paused
deleted: Deleted
inactive: Inactive
match_types:
broad: Broad
exact: Exact
phrase: Phrase
network:
owned_and_operated_and_syndicated_search: OwnedAndOperatedAndSyndicatedSearch
owned_and_operated_only: OwnedAndOperatedOnly
syndicated_search_only: SyndicatedSearchOnly
remarketing_target_setting:
bid_only: BidOnly
target_and_bid: TargetAndBid
12 changes: 12 additions & 0 deletions lib/bing/ads/api/v12/constants/languages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
danish: 'Danish'
dutch: 'Dutch'
english: 'English'
finnish: 'Finnish'
french: 'French'
german: 'German'
italian: 'Italian'
norwegian: 'Norwegian'
portuguese: 'Portuguese'
spanish: 'Spanish'
swedish: 'Swedish'
traditional_chinese: 'TraditionalChinese'
5 changes: 5 additions & 0 deletions lib/bing/ads/api/v12/constants/limits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
per_call:
campaign: 100
ad_group: 1000
ad: 50
keyword: 1000
75 changes: 75 additions & 0 deletions lib/bing/ads/api/v12/constants/time_zones.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
abu_dhabi_muscat: 'AbuDhabiMuscat'
adelaide: 'Adelaide'
alaska: 'Alaska'
almaty_novosibirsk: 'AlmatyNovosibirsk'
amsterdam_berlin_bern_rome_stockholm_vienna: 'AmsterdamBerlinBernRomeStockholmVienna'
arizona: 'Arizona'
astana_dhaka: 'AstanaDhaka'
athens_buckarest_istanbul: 'AthensBuckarestIstanbul'
atlantic_time_canada: 'AtlanticTimeCanada'
auckland_wellington: 'AucklandWellington'
azores: 'Azores'
baghdad: 'Baghdad'
baku_tbilisi_yerevan: 'BakuTbilisiYerevan'
bangkok_hanoi_jakarta: 'BangkokHanoiJakarta'
beijing_chongqing_hong_kong_urumqi: 'BeijingChongqingHongKongUrumqi'
belgrade_bratislava_budapest_ljubljana_prague: 'BelgradeBratislavaBudapestLjubljanaPrague'
bogota_lima_quito: 'BogotaLimaQuito'
brasilia: 'Brasilia'
brisbane: 'Brisbane'
brussels_copenhagen_madrid_paris: 'BrusselsCopenhagenMadridParis'
bucharest: 'Bucharest'
buenos_aires_georgetown: 'BuenosAiresGeorgetown'
cairo: 'Cairo'
canberra_melbourne_sydney: 'CanberraMelbourneSydney'
cape_verde_island: 'CapeVerdeIsland'
caracas_la_paz: 'CaracasLaPaz'
casablanca_monrovia: 'CasablancaMonrovia'
central_america: 'CentralAmerica'
central_time_u_s_canada: 'CentralTimeUSCanada'
chennai_kolkata_mumbai_new_delhi: 'ChennaiKolkataMumbaiNewDelhi'
chihuahua_la_paz_mazatlan: 'ChihuahuaLaPazMazatlan'
darwin: 'Darwin'
eastern_time_u_s_canada: 'EasternTimeUSCanada'
ekaterinburg: 'Ekaterinburg'
fiji_kamchatka_marshall_island: 'FijiKamchatkaMarshallIsland'
greenland: 'Greenland'
greenwich_mean_time_dublin_edinburgh_lisbon_london: 'GreenwichMeanTimeDublinEdinburghLisbonLondon'
guadalajara_mexico_city_monterrey: 'GuadalajaraMexicoCityMonterrey'
guam_port_moresby: 'GuamPortMoresby'
harare_pretoria: 'HararePretoria'
hawaii: 'Hawaii'
helsinki_kyiv_riga_sofia_tallinn_vilnius: 'HelsinkiKyivRigaSofiaTallinnVilnius'
hobart: 'Hobart'
indiana_east: 'IndianaEast'
international_date_line_west: 'InternationalDateLineWest'
irkutsk_ulaan_bataar: 'IrkutskUlaanBataar'
islandamabad_karachi_tashkent: 'IslandamabadKarachiTashkent'
jerusalem: 'Jerusalem'
kabul: 'Kabul'
kathmandu: 'Kathmandu'
krasnoyarsk: 'Krasnoyarsk'
kuala_lumpur_singapore: 'KualaLumpurSingapore'
kuwait_riyadh: 'KuwaitRiyadh'
solomon_island_new_caledonia: 'SolomonIslandNewCaledonia'
mid_atlantic: 'MidAtlantic'
midway_islandand_samoa: 'MidwayIslandAndSamoa'
moscow_st_petersburg_volgograd: 'MoscowStPetersburgVolgograd'
mountain_time_u_s_canada: 'MountainTimeUSCanada'
nairobi: 'Nairobi'
newfoundland: 'Newfoundland'
nukualofa: 'Nukualofa'
osaka_sapporo_tokyo: 'OsakaSapporoTokyo'
pacific_time_u_s_canada_tijuana: 'PacificTimeUSCanadaTijuana'
perth: 'Perth'
rangoon: 'Rangoon'
santiago: 'Santiago'
sarajevo_skopje_warsaw_zagreb: 'SarajevoSkopjeWarsawZagreb'
saskatchewan: 'Saskatchewan'
seoul: 'Seoul'
sri_jayawardenepura: 'SriJayawardenepura'
taipei: 'Taipei'
tehran: 'Tehran'
vladivostok: 'Vladivostok'
west_central_africa: 'WestCentralAfrica'
yakutsk: 'Yakutsk'
10 changes: 10 additions & 0 deletions lib/bing/ads/api/v12/constants/wsdl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sandbox:
customer_management: "https://clientcenter.api.bingads.microsoft.com/Api/CustomerManagement/v12/CustomerManagementService.svc?singleWsdl"
campaign_management: "https://campaign.api.sandbox.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v12/CampaignManagementService.svc?singleWsdl"
reporting: "https://reporting.api.sandbox.bingads.microsoft.com/Api/Advertiser/Reporting/v12/ReportingService.svc?singleWsdl"
bulk: 'https://bulk.api.sandbox.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v12/BulkService.svc?singleWsdl'
production:
customer_management: "https://clientcenter.api.sandbox.bingads.microsoft.com/Api/CustomerManagement/v12/CustomerManagementService.svc?singleWsdl"
campaign_management: "https://campaign.api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v12/CampaignManagementService.svc?singleWsdl"
reporting: "https://reporting.api.bingads.microsoft.com/Api/Advertiser/Reporting/v12/ReportingService.svc?singleWsdl"
bulk: 'https://bulk.api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v12/BulkService.svc?singleWsdl'
6 changes: 6 additions & 0 deletions lib/bing/ads/api/v12/data.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require_relative './data/ad_group'
require_relative './data/expanded_text_ad'
require_relative './data/campaign'
require_relative './data/keyword'
require_relative './data/report_request'
require_relative './data/bulk_request'
55 changes: 55 additions & 0 deletions lib/bing/ads/api/v12/data/ad_group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
module Bing
module Ads
module API
module V12
module Data
# Bing::Ads::API::V12::Data::AdGroup
class AdGroup

# @order
# https://msdn.microsoft.com/en-us/library/bing-ads-campaign-management-adgroup.aspx
# 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]
if ad_group_raw[:bidding_scheme]
# TODO support MaxClicksBiddingScheme, MaxConversionsBiddingScheme and TargetCpaBiddingScheme
ad_group_raw[:bidding_scheme] = {
type: ad_group_raw[:bidding_scheme],
'@xsi:type' => "#{Bing::Ads::API::V12::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]
ad_group_raw[:end_date] = Bing::Ads::Utils.date_hash(ad_group_raw[:end_date]) if ad_group_raw[:end_date]
ad_group_raw[:search_bid] = { amount: ad_group_raw[:search_bid] } if ad_group_raw[:search_bid]
ad_group_raw[:start_date] = Bing::Ads::Utils.date_hash(ad_group_raw[:start_date]) if ad_group_raw[:start_date]
# TODO UrlCustomParameters
ad_group_raw = Bing::Ads::Utils.sort_keys(ad_group_raw)
Bing::Ads::Utils.camelcase_keys(ad_group_raw)
end
end
end
end
end
end
end
52 changes: 52 additions & 0 deletions lib/bing/ads/api/v12/data/bulk_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
module Bing
module Ads
module API
module V12
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
Loading

0 comments on commit f1a36e7

Please sign in to comment.