bing-ads 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc31748b139decf28fde91e23bf470f2074cdf58
4
- data.tar.gz: 6bb1b477c35b26f665b29a9d293e524ad41b24ce
3
+ metadata.gz: 6090b37bc8ba04c730ccdaf96396de0867517f9e
4
+ data.tar.gz: 1c4dd6e7269c5f0bc7f5a134bb03c01f6d99048f
5
5
  SHA512:
6
- metadata.gz: 6ae2cae5856504d061d40f7f584c333ecb2709668e324430dd97dc579d109cfe892723d04fbff208c1d4fd1afe8087af5d51484ac9a8a36ab02e68351b9a0019
7
- data.tar.gz: 19e819791660d49b09686e2d06c2930ed4155e5d2fec351542a98a352e95a9535cbe10a980e85eece7b5aa0c4b4337f53664f8ef0f59d28c21e875825beac758
6
+ metadata.gz: 54ae03a0b3777a788ec84eb54eccef6224f301b87972cd65e070e127c80e93e1c04ba139a82ac83556a9a4a93b8d273dced509efb3290e5f0aaf74035f4c4bc1
7
+ data.tar.gz: 3b39cbd525d60fb2c02a97dca546cad17e68895a5a3de8cc9d0df5ded672e2b6f7c5682f7a1016f6a4b324d59eb6099c203a8393189438aa6907205d4739ecc0
data/README.md CHANGED
@@ -69,6 +69,13 @@ account_id = 5278183
69
69
  response = service.get_campaigns_by_account_id(account_id)
70
70
  ```
71
71
 
72
+ #### Getting campaigns in an account by ids
73
+ ```ruby
74
+ account_id = 5278183
75
+ campaign_ids = [813721838, 813721849, 813721850]
76
+ response = service.get_campaigns_by_ids(account_id, campaign_ids)
77
+ ```
78
+
72
79
  #### Adding campaigns
73
80
  ```ruby
74
81
  account_id = 5278183
@@ -9,6 +9,7 @@ require 'bing/ads/api/errors'
9
9
  require 'bing/ads/api/soap_client'
10
10
  require 'bing/ads/api/v11'
11
11
  require 'bing/ads/api/v11/constants'
12
+ require 'bing/ads/api/v11/data'
12
13
  require 'bing/ads/api/v11/services'
13
14
 
14
15
  require 'bing/ads/utils'
@@ -0,0 +1,4 @@
1
+ require_relative './data/ad_group'
2
+ require_relative './data/expanded_text_ad'
3
+ require_relative './data/campaign'
4
+ require_relative './data/keyword'
@@ -0,0 +1,56 @@
1
+ module Bing
2
+ module Ads
3
+ module API
4
+ module V11
5
+ module Data
6
+ # Bing::Ads::API::V11::Data::AdGroup
7
+ class AdGroup
8
+
9
+ # @order
10
+ # https://msdn.microsoft.com/en-us/library/bing-ads-campaign-management-adgroup.aspx
11
+ KEYS_ORDER = [
12
+ :ad_distribution,
13
+ :ad_rotation,
14
+ :bidding_scheme,
15
+ :content_match_bid,
16
+ :end_date,
17
+ :forward_compatibility_map,
18
+ :id,
19
+ :language,
20
+ :name,
21
+ :native_bid_adjustment,
22
+ :network,
23
+ :pricing_model,
24
+ :remarketing_targeting_setting,
25
+ :search_bid,
26
+ :settings,
27
+ :start_date,
28
+ :status,
29
+ :tracking_url_template,
30
+ :url_custom_parameters
31
+ # Alphabetical
32
+ ]
33
+
34
+ def self.prepare(ad_group_raw)
35
+ ad_group_raw[:ad_rotation] = { type: ad_group_raw[:ad_rotation] } if ad_group_raw[:ad_rotation]
36
+ if ad_group_raw[:bidding_scheme]
37
+ # TODO support MaxClicksBiddingScheme, MaxConversionsBiddingScheme and TargetCpaBiddingScheme
38
+ ad_group_raw[:bidding_scheme] = {
39
+ type: ad_group_raw[:bidding_scheme],
40
+ '@xsi:type' => "#{Bing::Ads::API::V11::NAMESPACE_IDENTIFIER}:#{ad_group_raw[:bidding_scheme]}"
41
+ }
42
+ end
43
+ ad_group_raw[:content_match_bid] = { amount: ad_group_raw[:content_match_bid] } if ad_group_raw[:content_match_bid]
44
+ ad_group_raw[:end_date] = Bing::Ads::Utils.date_hash(ad_group_raw[:end_date]) if ad_group_raw[:end_date]
45
+ ad_group_raw[:search_bid] = { amount: ad_group_raw[:search_bid] } if ad_group_raw[:search_bid]
46
+ ad_group_raw[:start_date] = Bing::Ads::Utils.date_hash(ad_group_raw[:start_date]) if ad_group_raw[:start_date]
47
+ # TODO UrlCustomParameters
48
+ ad_group_raw = Bing::Ads::Utils.sort_keys(ad_group_raw)
49
+ Bing::Ads::Utils.camelcase_keys(ad_group_raw)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,49 @@
1
+ module Bing
2
+ module Ads
3
+ module API
4
+ module V11
5
+ module Data
6
+ # Bing::Ads::API::V11::Data::Campaign
7
+ class Campaign
8
+
9
+ # @order
10
+ # https://msdn.microsoft.com/en-us/library/bing-ads-campaign-management-campaign.aspx
11
+ KEYS_ORDER = [
12
+ :bidding_scheme,
13
+ :budget_type,
14
+ :daily_budget,
15
+ :description,
16
+ :forward_compatibility_map,
17
+ :id,
18
+ :name,
19
+ :native_bid_adjustment,
20
+ :status,
21
+ :time_zone,
22
+ :tracking_url_template,
23
+ :url_custom_parameters,
24
+ # Alphabetical till here
25
+ :campaign_type,
26
+ :settings,
27
+ :budget_id,
28
+ :languages
29
+ ]
30
+
31
+ def self.prepare(campaign_raw)
32
+ if campaign_raw[:bidding_scheme]
33
+ campaign_raw[:bidding_scheme] = {
34
+ # TODO support MaxClicksBiddingScheme, MaxConversionsBiddingScheme and TargetCpaBiddingScheme
35
+ type: campaign_raw[:bidding_scheme],
36
+ '@xsi:type' => "#{Bing::Ads::API::V11::NAMESPACE_IDENTIFIER}:#{campaign_raw[:bidding_scheme]}"
37
+ }
38
+ end
39
+ # TODO UrlCustomParameters
40
+ # TODO Settings
41
+ campaign_raw = Bing::Ads::Utils.sort_keys(campaign_raw, KEYS_ORDER)
42
+ Bing::Ads::Utils.camelcase_keys(campaign_raw)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,38 @@
1
+ module Bing
2
+ module Ads
3
+ module API
4
+ module V11
5
+ module Data
6
+ # Bing::Ads::API::V11::Data::ExpandedTextAd
7
+ class ExpandedTextAd
8
+
9
+ # @order
10
+ # https://msdn.microsoft.com/en-us/library/bing-ads-campaign-management-ad.aspx
11
+ KEYS_ORDER = [
12
+ :device_preference,
13
+ :editorial_status,
14
+ :forward_compatibility_map,
15
+ :id,
16
+ :status,
17
+ :final_urls,
18
+ :path_1,
19
+ :path_2,
20
+ :text,
21
+ :title_part_1,
22
+ :title_part_2
23
+ ]
24
+
25
+ def self.prepare(ad_raw)
26
+ ad_raw['@xsi:type'] = "#{Bing::Ads::API::V11::NAMESPACE_IDENTIFIER}:#{ad_raw[:type]}"
27
+ ad_raw[:final_mobile_urls] = { 'ins1:string' => ad_raw[:final_mobile_urls] } if ad_raw[:final_mobile_urls]
28
+ ad_raw[:final_urls] = { 'ins1:string' => ad_raw[:final_urls] } if ad_raw[:final_urls]
29
+ # TODO FinalAppUrls
30
+ ad_raw = Bing::Ads::Utils.sort_keys(ad_raw, KEYS_ORDER)
31
+ Bing::Ads::Utils.camelcase_keys(ad_raw)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,55 @@
1
+ module Bing
2
+ module Ads
3
+ module API
4
+ module V11
5
+ module Data
6
+ # Bing::Ads::API::V11::Data::Keyword
7
+ class Keyword
8
+
9
+ # @order
10
+ # https://msdn.microsoft.com/en-us/library/bing-ads-campaign-management-keyword.aspx
11
+ KEYS_ORDER = [
12
+ :bidding_scheme,
13
+ :bid,
14
+ :destination_url,
15
+ :editorial_status,
16
+ :final_app_urls,
17
+ :final_mobile_urls,
18
+ :final_urls,
19
+ :forward_compatibility_map,
20
+ :id,
21
+ :match_type,
22
+ :param_1,
23
+ :param_2,
24
+ :param_3,
25
+ :status,
26
+ :text,
27
+ :tracking_url_template,
28
+ :url_custom_parameters
29
+ # Alphabetical
30
+ ]
31
+
32
+ def self.prepare(keyword_raw)
33
+ # To use the AdGroup default match type bid,
34
+ # set the Amount element of the Bid object to null.
35
+ keyword_raw[:bid] = { amount: keyword_raw[:bid] }
36
+ if keyword_raw[:bidding_scheme]
37
+ # TODO support MaxClicksBiddingScheme, MaxConversionsBiddingScheme and TargetCpaBiddingScheme
38
+ keyword_raw[:bidding_scheme] = {
39
+ type: keyword_raw[:bidding_scheme],
40
+ '@xsi:type' => "#{Bing::Ads::API::V11::NAMESPACE_IDENTIFIER}:#{keyword_raw[:bidding_scheme]}"
41
+ }
42
+ end
43
+ keyword_raw[:final_mobile_urls] = { 'ins1:string' => keyword_raw[:final_mobile_urls] } if keyword_raw[:final_mobile_urls]
44
+ keyword_raw[:final_urls] = { 'ins1:string' => keyword_raw[:final_urls] } if keyword_raw[:final_urls]
45
+ # TODO FinalAppUrls
46
+ # TODO UrlCustomParameters
47
+ keyword_raw = Bing::Ads::Utils.sort_keys(keyword_raw)
48
+ Bing::Ads::Utils.camelcase_keys(keyword_raw)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -29,7 +29,7 @@ module Bing
29
29
 
30
30
  def add_campaigns(account_id, campaigns)
31
31
  validate_limits!(:campaign, :add, campaigns)
32
- campaigns = campaigns.map { |campaign| prepare_campaign(campaign) }
32
+ campaigns = campaigns.map { |campaign| Bing::Ads::API::V11::Data::Campaign.prepare(campaign) }
33
33
  payload = {
34
34
  account_id: account_id,
35
35
  campaigns: { campaign: campaigns }
@@ -40,7 +40,7 @@ module Bing
40
40
 
41
41
  def update_campaigns(account_id, campaigns)
42
42
  validate_limits!(:campaign, :update, campaigns)
43
- campaigns = campaigns.map { |campaign| prepare_campaign(campaign) }
43
+ campaigns = campaigns.map { |campaign| Bing::Ads::API::V11::Data::Campaign.prepare(campaign) }
44
44
  payload = {
45
45
  account_id: account_id,
46
46
  campaigns: { campaign: campaigns }
@@ -78,7 +78,7 @@ module Bing
78
78
 
79
79
  def add_ad_groups(campaign_id, ad_groups)
80
80
  validate_limits!(:ad_group, :add, ad_groups)
81
- ad_groups = ad_groups.map { |ad_group| prepare_ad_group(ad_group) }
81
+ ad_groups = ad_groups.map { |ad_group| Bing::Ads::API::V11::Data::AdGroup.prepare(ad_group) }
82
82
  payload = {
83
83
  campaign_id: campaign_id,
84
84
  ad_groups: { ad_group: ad_groups }
@@ -89,7 +89,7 @@ module Bing
89
89
 
90
90
  def update_ad_groups(campaign_id, ad_groups)
91
91
  validate_limits!(:ad_group, :update, ad_groups)
92
- ad_groups = ad_groups.map { |ad_group| prepare_ad_group(ad_group) }
92
+ ad_groups = ad_groups.map { |ad_group| Bing::Ads::API::V11::Data::AdGroup.prepare(ad_group) }
93
93
  payload = {
94
94
  campaign_id: campaign_id,
95
95
  ad_groups: { ad_group: ad_groups }
@@ -142,7 +142,7 @@ module Bing
142
142
 
143
143
  def add_ads(ad_group_id, ads)
144
144
  validate_limits!(:ad, :add, ads)
145
- ads = ads.map { |ad| prepare_ad(ad) }
145
+ ads = ads.map { |ad| Bing::Ads::API::V11::Data::ExpandedTextAd.prepare(ad) }
146
146
  payload = {
147
147
  ad_group_id: ad_group_id,
148
148
  ads: { ad: ads }
@@ -153,7 +153,7 @@ module Bing
153
153
 
154
154
  def update_ads(ad_group_id, ads)
155
155
  validate_limits!(:ad, :update, ads)
156
- ads = ads.map { |ad| prepare_ad(ad) }
156
+ ads = ads.map { |ad| Bing::Ads::API::V11::Data::ExpandedTextAd.prepare(ad) }
157
157
  payload = {
158
158
  ad_group_id: ad_group_id,
159
159
  ads: { ad: ads }
@@ -190,7 +190,7 @@ module Bing
190
190
 
191
191
  def add_keywords(ad_group_id, keywords)
192
192
  validate_limits!(:keyword, :add, keywords)
193
- keywords = keywords.map { |keyword| prepare_keyword(keyword) }
193
+ keywords = keywords.map { |keyword| Bing::Ads::API::V11::Data::Keyword.prepare(keyword) }
194
194
  payload = {
195
195
  ad_group_id: ad_group_id,
196
196
  keywords: { keyword: keywords }
@@ -201,7 +201,7 @@ module Bing
201
201
 
202
202
  def update_keywords(ad_group_id, keywords)
203
203
  validate_limits!(:keyword, :update, keywords)
204
- keywords = keywords.map { |keyword| prepare_keyword(keyword) }
204
+ keywords = keywords.map { |keyword| Bing::Ads::API::V11::Data::Keyword.prepare(keyword) }
205
205
  payload = {
206
206
  ad_group_id: ad_group_id,
207
207
  keywords: { keyword: keywords }
@@ -309,72 +309,6 @@ module Bing
309
309
  'campaign_management'
310
310
  end
311
311
 
312
- def prepare_campaign(campaign)
313
- campaign = Bing::Ads::Utils.sort_keys(campaign)
314
- if campaign[:bidding_scheme]
315
- campaign[:bidding_scheme] = {
316
- # TODO support MaxClicksBiddingScheme, MaxConversionsBiddingScheme and TargetCpaBiddingScheme
317
- type: campaign[:bidding_scheme],
318
- '@xsi:type' => "#{Bing::Ads::API::V11::NAMESPACE_IDENTIFIER}:#{campaign[:bidding_scheme]}"
319
- }
320
- end
321
- campaign[:languages] = { 'ins1:string' => campaign[:languages] } if campaign[:languages]
322
- # TODO UrlCustomParameters
323
- # TODO Settings
324
- Bing::Ads::Utils.camelcase_keys(campaign)
325
- end
326
-
327
- def prepare_ad_group(ad_group)
328
- ad_group = Bing::Ads::Utils.sort_keys(ad_group)
329
- ad_group[:ad_rotation] = { type: ad_group[:ad_rotation] } if ad_group[:ad_rotation]
330
- if ad_group[:bidding_scheme]
331
- # TODO support MaxClicksBiddingScheme, MaxConversionsBiddingScheme and TargetCpaBiddingScheme
332
- ad_group[:bidding_scheme] = {
333
- type: ad_group[:bidding_scheme],
334
- '@xsi:type' => "#{Bing::Ads::API::V11::NAMESPACE_IDENTIFIER}:#{ad_group[:bidding_scheme]}"
335
- }
336
- end
337
- ad_group[:content_match_bid] = { amount: ad_group[:content_match_bid] } if ad_group[:content_match_bid]
338
- ad_group[:end_date] = date_hash(ad_group[:end_date]) if ad_group[:end_date]
339
- ad_group[:search_bid] = { amount: ad_group[:search_bid] } if ad_group[:search_bid]
340
- ad_group[:start_date] = date_hash(ad_group[:start_date]) if ad_group[:start_date]
341
- # TODO UrlCustomParameters
342
- Bing::Ads::Utils.camelcase_keys(ad_group)
343
- end
344
-
345
- def prepare_ad(ad)
346
- ad = Bing::Ads::Utils.sort_keys(ad)
347
- ad['@xsi:type'] = "#{Bing::Ads::API::V11::NAMESPACE_IDENTIFIER}:#{ad[:type]}"
348
- ad[:final_mobile_urls] = { 'ins1:string' => ad[:final_mobile_urls] } if ad[:final_mobile_urls]
349
- ad[:final_urls] = { 'ins1:string' => ad[:final_urls] } if ad[:final_urls]
350
- # TODO FinalAppUrls
351
- Bing::Ads::Utils.camelcase_keys(ad)
352
- end
353
-
354
- def prepare_keyword(keyword)
355
- keyword = Bing::Ads::Utils.sort_keys(keyword)
356
- # To use the AdGroup default match type bid,
357
- # set the Amount element of the Bid object to null.
358
- keyword[:bid] = { amount: keyword[:bid] }
359
- if keyword[:bidding_scheme]
360
- # TODO support MaxClicksBiddingScheme, MaxConversionsBiddingScheme and TargetCpaBiddingScheme
361
- keyword[:bidding_scheme] = {
362
- type: keyword[:bidding_scheme],
363
- '@xsi:type' => "#{Bing::Ads::API::V11::NAMESPACE_IDENTIFIER}:#{keyword[:bidding_scheme]}"
364
- }
365
- end
366
- keyword[:final_mobile_urls] = { 'ins1:string' => keyword[:final_mobile_urls] } if keyword[:final_mobile_urls]
367
- keyword[:final_urls] = { 'ins1:string' => keyword[:final_urls] } if keyword[:final_urls]
368
- # TODO FinalAppUrls
369
- # TODO UrlCustomParameters
370
- Bing::Ads::Utils.camelcase_keys(keyword)
371
- end
372
-
373
- def date_hash(date)
374
- date = Date.parse(date) if date.is_a?(String)
375
- { day: date.day, month: date.month, year: date.year }
376
- end
377
-
378
312
  def validate_limits!(type, operation, array)
379
313
  limit = Bing::Ads::API::V11.constants.limits.per_call.send(type)
380
314
  if array.size > limit
@@ -8,10 +8,29 @@ module Bing
8
8
  end
9
9
  end
10
10
 
11
- def sort_keys(object)
12
- object = Hash[ object.sort_by { |key, val| key.to_s } ]
11
+ def sort_keys(object, ordered_keys_array=nil)
12
+ if ordered_keys_array
13
+ object = sort_by_ordered_keys(object, ordered_keys_array)
14
+ else
15
+ object = sort_alphabetically(object)
16
+ end
13
17
  object.symbolize_keys!
14
18
  end
19
+
20
+ def date_hash(date)
21
+ date = Date.parse(date) if date.is_a?(String)
22
+ { day: date.day, month: date.month, year: date.year }
23
+ end
24
+
25
+ private
26
+
27
+ def sort_by_ordered_keys(object, ordered_keys_array)
28
+ Hash[ object.sort_by { |k, _| ordered_keys_array.index(k.to_sym) || (10000 + k.to_s.ord) } ]
29
+ end
30
+
31
+ def sort_alphabetically(object)
32
+ Hash[ object.sort_by { |key, val| key.to_s } ]
33
+ end
15
34
  end
16
35
  end
17
36
  end
@@ -1,5 +1,5 @@
1
1
  module Bing
2
2
  module Ads
3
- VERSION = '0.1.4'
3
+ VERSION = '0.1.5'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bing-ads
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - oss92
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-18 00:00:00.000000000 Z
11
+ date: 2017-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: savon
@@ -125,6 +125,11 @@ files:
125
125
  - lib/bing/ads/api/v11/constants/limits.yml
126
126
  - lib/bing/ads/api/v11/constants/time_zones.yml
127
127
  - lib/bing/ads/api/v11/constants/wsdl.yml
128
+ - lib/bing/ads/api/v11/data.rb
129
+ - lib/bing/ads/api/v11/data/ad_group.rb
130
+ - lib/bing/ads/api/v11/data/campaign.rb
131
+ - lib/bing/ads/api/v11/data/expanded_text_ad.rb
132
+ - lib/bing/ads/api/v11/data/keyword.rb
128
133
  - lib/bing/ads/api/v11/services.rb
129
134
  - lib/bing/ads/api/v11/services/base.rb
130
135
  - lib/bing/ads/api/v11/services/campaign_management.rb