bing-ads-api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +92 -0
- data/Rakefile +38 -0
- data/lib/bing-ads-api.rb +38 -0
- data/lib/bing-ads-api.yml +345 -0
- data/lib/bing-ads-api/api_exception.rb +42 -0
- data/lib/bing-ads-api/client_proxy.rb +131 -0
- data/lib/bing-ads-api/config.rb +75 -0
- data/lib/bing-ads-api/constants.rb +133 -0
- data/lib/bing-ads-api/data/ad.rb +119 -0
- data/lib/bing-ads-api/data/ad_group.rb +121 -0
- data/lib/bing-ads-api/data/campaign.rb +40 -0
- data/lib/bing-ads-api/data/report_request.rb +78 -0
- data/lib/bing-ads-api/data/report_request_status.rb +48 -0
- data/lib/bing-ads-api/data/reporting/account_performance_report_request.rb +176 -0
- data/lib/bing-ads-api/data/reporting/campaign_performance_report_request.rb +186 -0
- data/lib/bing-ads-api/data/reporting/helpers/column_helper.rb +65 -0
- data/lib/bing-ads-api/data/reporting/helpers/filter_helper.rb +124 -0
- data/lib/bing-ads-api/data/reporting/helpers/scope_helper.rb +51 -0
- data/lib/bing-ads-api/data/reporting/helpers/time_helper.rb +69 -0
- data/lib/bing-ads-api/data/reporting/performance_report_request.rb +78 -0
- data/lib/bing-ads-api/data_object.rb +35 -0
- data/lib/bing-ads-api/fault/ad_api_error.rb +15 -0
- data/lib/bing-ads-api/fault/ad_api_fault_detail.rb +67 -0
- data/lib/bing-ads-api/fault/api_fault_detail.rb +97 -0
- data/lib/bing-ads-api/fault/application_fault.rb +18 -0
- data/lib/bing-ads-api/fault/batch_error.rb +47 -0
- data/lib/bing-ads-api/fault/operation_error.rb +22 -0
- data/lib/bing-ads-api/fault/partial_errors.rb +75 -0
- data/lib/bing-ads-api/service.rb +174 -0
- data/lib/bing-ads-api/service/campaign_management.rb +483 -0
- data/lib/bing-ads-api/service/reporting.rb +101 -0
- data/lib/bing-ads-api/soap_hasheable.rb +143 -0
- data/lib/bing-ads-api/version.rb +6 -0
- data/lib/locales/es.yml +174 -0
- data/lib/tasks/bing-ads-api_tasks.rake +4 -0
- data/test/bing-ads-api_test.rb +134 -0
- data/test/campaign_management_test.rb +463 -0
- data/test/data_object_test.rb +46 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +56 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +29 -0
- data/test/dummy/log/test.log +3264 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/report_request_test.rb +312 -0
- data/test/reporting_test.rb +145 -0
- data/test/test_helper.rb +11 -0
- metadata +205 -0
@@ -0,0 +1,463 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
# Public : Test case for Campaign Management services
|
5
|
+
#
|
6
|
+
# Author:: jlopezn@neonline.cl
|
7
|
+
class CampaignManagementTest < ActiveSupport::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
|
11
|
+
@config = BingAdsApi::Config.instance
|
12
|
+
@options = {
|
13
|
+
:environment => :sandbox,
|
14
|
+
:username => "desarrollo_neonline",
|
15
|
+
:password => "neonline2013",
|
16
|
+
:developer_token => "BBD37VB98",
|
17
|
+
:customer_id => "21021746",
|
18
|
+
:account_id => "5978083"
|
19
|
+
}
|
20
|
+
@service = BingAdsApi::CampaignManagement.new(@options)
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
test "truth" do
|
25
|
+
assert_kind_of Module, BingAdsApi
|
26
|
+
end
|
27
|
+
|
28
|
+
test "initialize" do
|
29
|
+
@service = BingAdsApi::CampaignManagement.new(@options)
|
30
|
+
assert !@service.nil?, "CampaignManagement service not instantiated"
|
31
|
+
end
|
32
|
+
|
33
|
+
test "get campaigns by account" do
|
34
|
+
response = @service.get_campaigns_by_account_id(@options[:account_id])
|
35
|
+
assert !response.nil?, "No response received"
|
36
|
+
assert response.is_a?(Array), "No Array as response received"
|
37
|
+
end
|
38
|
+
|
39
|
+
test "add campaign" do
|
40
|
+
|
41
|
+
name = "Test Campaign #{DateTime.now.strftime("%Y-%m-%d %H:%M:%S")}"
|
42
|
+
campaigns = [
|
43
|
+
BingAdsApi::Campaign.new(
|
44
|
+
:budget_type => BingAdsApi::Campaign::DAILY_BUDGET_STANDARD,
|
45
|
+
:conversion_tracking_enabled => "false",
|
46
|
+
:daily_budget => 2000,
|
47
|
+
:daylight_saving => "false",
|
48
|
+
:description => name + " description",
|
49
|
+
:monthly_budget => 5400,
|
50
|
+
:name => name + " name",
|
51
|
+
:status => BingAdsApi::Campaign::PAUSED,
|
52
|
+
:time_zone => BingAdsApi::Campaign::SANTIAGO),
|
53
|
+
]
|
54
|
+
response = @service.add_campaigns(@options[:account_id], campaigns)
|
55
|
+
|
56
|
+
puts "response[:campaign_ids][:long]"
|
57
|
+
puts response[:campaign_ids][:long]
|
58
|
+
assert !response[:campaign_ids][:long].nil?, "No campaigns id received"
|
59
|
+
end
|
60
|
+
|
61
|
+
test "add campaigns" do
|
62
|
+
name = "Test Campaign #{DateTime.now.strftime("%Y-%m-%d %H:%M:%S")}"
|
63
|
+
campaigns = [
|
64
|
+
BingAdsApi::Campaign.new(
|
65
|
+
:budget_type => BingAdsApi::Campaign::DAILY_BUDGET_STANDARD,
|
66
|
+
:conversion_tracking_enabled => "false",
|
67
|
+
:daily_budget => 2000,
|
68
|
+
:daylight_saving => "false",
|
69
|
+
:description => name + " first description",
|
70
|
+
:monthly_budget => 5400,
|
71
|
+
:name => name + " first name",
|
72
|
+
:status => BingAdsApi::Campaign::PAUSED,
|
73
|
+
:time_zone => BingAdsApi::Campaign::SANTIAGO),
|
74
|
+
|
75
|
+
BingAdsApi::Campaign.new(
|
76
|
+
:budget_type => BingAdsApi::Campaign::DAILY_BUDGET_STANDARD,
|
77
|
+
:conversion_tracking_enabled => "false",
|
78
|
+
:daily_budget => 2500,
|
79
|
+
:daylight_saving => "false",
|
80
|
+
:description => name + " second description",
|
81
|
+
:monthly_budget => 7800,
|
82
|
+
:name => name + " second name",
|
83
|
+
:status => BingAdsApi::Campaign::PAUSED,
|
84
|
+
:time_zone => BingAdsApi::Campaign::SANTIAGO),
|
85
|
+
|
86
|
+
]
|
87
|
+
response = @service.add_campaigns(@options[:account_id], campaigns)
|
88
|
+
puts "response.inspect"
|
89
|
+
puts response.inspect
|
90
|
+
|
91
|
+
puts "response[:campaign_ids][:long]"
|
92
|
+
puts response[:campaign_ids][:long]
|
93
|
+
assert !response[:campaign_ids][:long].nil?, "No campaigns ids received"
|
94
|
+
assert response[:campaign_ids][:long].is_a?(Array), "No array with campaign ids received"
|
95
|
+
assert response[:campaign_ids][:long].size == campaigns.size, "expected campaign_ids: #{campaigns.size}. Received: #{response[:campaign_ids][:long].size}"
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
test "update campaigns" do
|
101
|
+
|
102
|
+
campaigns = @service.get_campaigns_by_account_id(@options[:account_id])
|
103
|
+
assert !campaigns.nil?, "No campaigns received"
|
104
|
+
|
105
|
+
campaigns.each do |campaign|
|
106
|
+
campaign.description = campaign.description + " updated #{DateTime.now.strftime("%Y-%m-%d %H:%M:%S")}"
|
107
|
+
campaign.status = nil
|
108
|
+
end
|
109
|
+
|
110
|
+
response = @service.update_campaigns(@options[:account_id], campaigns)
|
111
|
+
|
112
|
+
puts "UpdateCampaigns response"
|
113
|
+
puts response.inspect
|
114
|
+
assert !response.nil?, "No response received"
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
test "get ad groups by campaign" do
|
120
|
+
campaigns = @service.get_campaigns_by_account_id(@options[:account_id])
|
121
|
+
assert !campaigns.empty?, "No campaigns received for account id #{@options[:account_id]}"
|
122
|
+
campaign_id = campaigns.first.id
|
123
|
+
|
124
|
+
response = @service.get_ad_groups_by_campaign_id(campaign_id)
|
125
|
+
|
126
|
+
puts "GetAdGroupsByCampaignId response :"
|
127
|
+
puts response.inspect
|
128
|
+
|
129
|
+
assert !response.empty?, "No ad groups received from campaign #{campaign_id}"
|
130
|
+
assert response.is_a?(Array), "No array response received"
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
test "get ad groups by ids" do
|
135
|
+
campaigns = @service.get_campaigns_by_account_id(@options[:account_id])
|
136
|
+
assert !campaigns.empty?, "No campaigns received for account id #{@options[:account_id]}"
|
137
|
+
campaign_id = campaigns.first.id
|
138
|
+
|
139
|
+
groups = @service.get_ad_groups_by_campaign_id(campaign_id)
|
140
|
+
|
141
|
+
ad_group_ids = groups.map{ |gr| gr.id }
|
142
|
+
response = @service.get_ad_groups_by_ids(campaign_id, ad_group_ids)
|
143
|
+
|
144
|
+
puts "GetAdGroupsByIds response :"
|
145
|
+
puts response.inspect
|
146
|
+
|
147
|
+
assert !response.nil?, "No ad groups received in campaign #{campaign_id} where ad_group_ids #{ad_group_ids}"
|
148
|
+
assert response.size == ad_group_ids.size, "Excpected #{ad_group_ids.size} ad groups. Received #{response.size}"
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
test "add ad group" do
|
153
|
+
|
154
|
+
campaigns = @service.get_campaigns_by_account_id(@options[:account_id])
|
155
|
+
assert !campaigns.empty?, "No campaigns received for account id #{@options[:account_id]}"
|
156
|
+
campaign_id = campaigns.first.id
|
157
|
+
|
158
|
+
name = "Ad Group #{DateTime.now.strftime("%Y-%m-%d %H:%M:%S")}"
|
159
|
+
ad_groups = [
|
160
|
+
BingAdsApi::AdGroup.new(
|
161
|
+
:ad_distribution => BingAdsApi::AdGroup::SEARCH,
|
162
|
+
:language => BingAdsApi::AdGroup::SPANISH,
|
163
|
+
:name => name + " name",
|
164
|
+
:pricing_model => BingAdsApi::AdGroup::CPC,
|
165
|
+
:bidding_model => BingAdsApi::AdGroup::KEYWORD)
|
166
|
+
]
|
167
|
+
response = @service.add_ad_groups(campaign_id, ad_groups)
|
168
|
+
|
169
|
+
puts "AddAdGroups response[:ad_group_ids][:long]"
|
170
|
+
puts response[:ad_group_ids][:long]
|
171
|
+
assert !response[:ad_group_ids][:long].nil?, "No ad groups id received"
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
test "add ad groups" do
|
177
|
+
|
178
|
+
campaigns = @service.get_campaigns_by_account_id(@options[:account_id])
|
179
|
+
assert !campaigns.empty?, "No campaigns received for account id #{@options[:account_id]}"
|
180
|
+
campaign_id = campaigns.first.id
|
181
|
+
|
182
|
+
name = "Ad Group #{DateTime.now.strftime("%Y-%m-%d %H:%M:%S")}"
|
183
|
+
ad_groups = [
|
184
|
+
BingAdsApi::AdGroup.new(
|
185
|
+
:ad_distribution => BingAdsApi::AdGroup::SEARCH,
|
186
|
+
:language => BingAdsApi::AdGroup::SPANISH,
|
187
|
+
:name => name + " name",
|
188
|
+
:pricing_model => BingAdsApi::AdGroup::CPC,
|
189
|
+
:bidding_model => BingAdsApi::AdGroup::KEYWORD),
|
190
|
+
|
191
|
+
BingAdsApi::AdGroup.new(
|
192
|
+
:ad_distribution => BingAdsApi::AdGroup::SEARCH,
|
193
|
+
:language => BingAdsApi::AdGroup::SPANISH,
|
194
|
+
:name => name + " second name",
|
195
|
+
:pricing_model => BingAdsApi::AdGroup::CPC,
|
196
|
+
:bidding_model => BingAdsApi::AdGroup::KEYWORD)
|
197
|
+
|
198
|
+
]
|
199
|
+
response = @service.add_ad_groups(campaign_id, ad_groups)
|
200
|
+
|
201
|
+
puts "AddAdGroups response[:ad_group_ids][:long]"
|
202
|
+
puts response[:ad_group_ids][:long]
|
203
|
+
assert !response[:ad_group_ids][:long].nil?, "No ad groups id received"
|
204
|
+
assert response[:ad_group_ids][:long].is_a?(Array), "No array with ad group ids received"
|
205
|
+
assert response[:ad_group_ids][:long].size == ad_groups.size, "expected ad_group_ids: #{ad_groups.size}. Received: #{response[:ad_group_ids][:long].size}"
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
|
210
|
+
test "update ad groups" do
|
211
|
+
campaigns = @service.get_campaigns_by_account_id(@options[:account_id])
|
212
|
+
assert !campaigns.empty?, "No campaigns received for account id #{@options[:account_id]}"
|
213
|
+
campaign_id = campaigns.first.id
|
214
|
+
|
215
|
+
ad_groups = @service.get_ad_groups_by_campaign_id(campaign_id)
|
216
|
+
|
217
|
+
ad_groups_to_update = ad_groups.map do |ad_group|
|
218
|
+
BingAdsApi::AdGroup.new(
|
219
|
+
:id => ad_group.id,
|
220
|
+
:name => ad_group.name + " updated #{DateTime.now.strftime("%Y-%m-%d %H:%M:%S")}" )
|
221
|
+
end
|
222
|
+
|
223
|
+
response = @service.update_ad_groups(campaign_id, ad_groups_to_update)
|
224
|
+
|
225
|
+
puts "UpdateAdGroups response"
|
226
|
+
puts response
|
227
|
+
assert !response.nil?, "No response received"
|
228
|
+
|
229
|
+
end
|
230
|
+
|
231
|
+
|
232
|
+
test "add ads" do
|
233
|
+
|
234
|
+
ad_group_id = 1980939070
|
235
|
+
|
236
|
+
date = DateTime.now.strftime("%Y-%m-%d %H:%M:%S")
|
237
|
+
|
238
|
+
# TextAds
|
239
|
+
text_ads = [
|
240
|
+
BingAdsApi::TextAd.new(
|
241
|
+
:type => BingAdsApi::Ad::TEXT,
|
242
|
+
:status => BingAdsApi::Ad::INACTIVE,
|
243
|
+
:destination_url => "http://www.adxion.com",
|
244
|
+
:display_url => "AdXion.com",
|
245
|
+
:text => "TextAd #{date}",
|
246
|
+
:title => "TextAd"),
|
247
|
+
|
248
|
+
BingAdsApi::TextAd.new(
|
249
|
+
:type => BingAdsApi::Ad::TEXT,
|
250
|
+
:status => BingAdsApi::Ad::INACTIVE,
|
251
|
+
:destination_url => "http://www.adxion.com",
|
252
|
+
:display_url => "AdXion.com",
|
253
|
+
:text => "TextAd 2 #{date}",
|
254
|
+
:title => "TextAd 2")
|
255
|
+
]
|
256
|
+
response = @service.add_ads(ad_group_id, text_ads)
|
257
|
+
assert !response.nil? , "No response received adding text ads"
|
258
|
+
|
259
|
+
assert response[:partial_errors].nil?, "TextAds response with partial errors"
|
260
|
+
|
261
|
+
puts "Text: AddAds response[:ad_ids][:long]"
|
262
|
+
puts response[:ad_ids][:long]
|
263
|
+
assert !response[:ad_ids][:long].nil?, "No ad ids received for TextAds"
|
264
|
+
|
265
|
+
|
266
|
+
mobile_ads = [
|
267
|
+
BingAdsApi::MobileAd.new(
|
268
|
+
:bussines_name => "Bussiness 1",
|
269
|
+
:destination_url => "http://www.adxion.com",
|
270
|
+
:display_url => "AdXion.com",
|
271
|
+
:phone_number => "555555555",
|
272
|
+
:text => "Publish with us",
|
273
|
+
:title => "MobileAd"),
|
274
|
+
|
275
|
+
BingAdsApi::MobileAd.new(
|
276
|
+
:bussines_name => "Bussiness 2",
|
277
|
+
:destination_url => "http://www.adxion.com",
|
278
|
+
:display_url => "AdXion.com",
|
279
|
+
:phone_number => "555555555",
|
280
|
+
:text => "Keep publishing",
|
281
|
+
:title => "MobileAd 2")
|
282
|
+
]
|
283
|
+
response = @service.add_ads(ad_group_id, mobile_ads)
|
284
|
+
assert !response.nil? , "No response received adding mobile ads"
|
285
|
+
|
286
|
+
puts response[:partial_errors] if !response[:partial_errors].nil?
|
287
|
+
assert response[:partial_errors].nil?, "MobileAds response with partial errors"
|
288
|
+
|
289
|
+
puts "Mobile: AddAds response[:ad_ids][:long]"
|
290
|
+
puts response[:ad_ids][:long]
|
291
|
+
assert !response[:ad_ids][:long].nil?, "No ad ids received for MobileAds"
|
292
|
+
|
293
|
+
# product_ads = [
|
294
|
+
# BingAdsApi::MobileAd.new(
|
295
|
+
# :promotional_text => "My Promotional text #{date}"),
|
296
|
+
#
|
297
|
+
# BingAdsApi::MobileAd.new(
|
298
|
+
# :promotional_text => "My Promotional text 2 #{date}")
|
299
|
+
# ]
|
300
|
+
# response = @service.add_ads(ad_group_id, product_ads)
|
301
|
+
# assert !response.nil? , "No response received adding product ads"
|
302
|
+
|
303
|
+
end
|
304
|
+
|
305
|
+
|
306
|
+
test "add ad" do
|
307
|
+
|
308
|
+
ad_group_id = 1980939070
|
309
|
+
|
310
|
+
date = DateTime.now.strftime("%Y-%m-%d %H:%M:%S")
|
311
|
+
|
312
|
+
# TextAd
|
313
|
+
text_ad = BingAdsApi::TextAd.new(
|
314
|
+
:type => BingAdsApi::Ad::TEXT,
|
315
|
+
:status => BingAdsApi::Ad::INACTIVE,
|
316
|
+
:destination_url => "http://www.adxion.com",
|
317
|
+
:display_url => "AdXion.com",
|
318
|
+
:text => "Text Ad #{date}",
|
319
|
+
:title => "Text Ad")
|
320
|
+
|
321
|
+
response = @service.add_ads(ad_group_id, text_ad)
|
322
|
+
assert !response.nil? , "No response received adding text ad"
|
323
|
+
|
324
|
+
assert response[:partial_errors].nil?, "TextAd response with partial errors"
|
325
|
+
|
326
|
+
puts "Text: AddAds response[:ad_ids][:long]"
|
327
|
+
puts response[:ad_ids][:long]
|
328
|
+
assert !response[:ad_ids][:long].nil?, "No ad ids received for TextAd"
|
329
|
+
|
330
|
+
|
331
|
+
# MobileAd
|
332
|
+
mobile_ad = BingAdsApi::MobileAd.new(
|
333
|
+
:bussines_name => "Bussiness",
|
334
|
+
:destination_url => "http://www.adxion.com",
|
335
|
+
:display_url => "adxion.com",
|
336
|
+
:phone_number => "555555555",
|
337
|
+
:text => "Publish with us",
|
338
|
+
:title => "Mobile Ad")
|
339
|
+
|
340
|
+
response = @service.add_ads(ad_group_id, mobile_ad)
|
341
|
+
assert !response.nil? , "No response received adding mobile ad"
|
342
|
+
|
343
|
+
puts response[:partial_errors] if !response[:partial_errors].nil?
|
344
|
+
assert response[:partial_errors].nil?, "MobileAd response with partial errors"
|
345
|
+
|
346
|
+
puts "Mobile: AddAds response[:ad_ids][:long]"
|
347
|
+
puts response[:ad_ids][:long]
|
348
|
+
assert !response[:ad_ids][:long].nil?, "No ad ids received for MobileAd"
|
349
|
+
|
350
|
+
|
351
|
+
# ProductAd
|
352
|
+
# product_ad = BingAdsApi::ProductAd.new(
|
353
|
+
# :promotional_text => "Promotion #{date}")
|
354
|
+
# response = @service.add_ads(ad_group_id, product_ad)
|
355
|
+
# assert !response.nil? , "No response received adding product ad"
|
356
|
+
#
|
357
|
+
# puts response[:partial_errors] if !response[:partial_errors].nil?
|
358
|
+
# assert response[:partial_errors].nil?, "ProductAd response with partial errors"
|
359
|
+
#
|
360
|
+
# puts "Product: AddAds response[:ad_ids][:long]"
|
361
|
+
# puts response[:ad_ids][:long]
|
362
|
+
# assert !response[:ad_ids][:long].nil?, "No ad ids received for ProductAd"
|
363
|
+
|
364
|
+
end
|
365
|
+
|
366
|
+
test "add ad with partial errors" do
|
367
|
+
|
368
|
+
ad_group_id = 1980939070
|
369
|
+
|
370
|
+
date = DateTime.now.strftime("%Y-%m-%d %H:%M:%S")
|
371
|
+
text_ad = BingAdsApi::TextAd.new(
|
372
|
+
:type => BingAdsApi::Ad::TEXT,
|
373
|
+
:status => BingAdsApi::Ad::INACTIVE,
|
374
|
+
:destination_url => "http://www.adxion.com",
|
375
|
+
:display_url => "http://www.adxion.com",
|
376
|
+
:text => "Test Text Ad #{date}",
|
377
|
+
:title => "Test Text Ad #{date}")
|
378
|
+
|
379
|
+
response = @service.add_ads(ad_group_id, text_ad)
|
380
|
+
assert !response.nil? , "No response received adding text ad"
|
381
|
+
|
382
|
+
puts response[:partial_errors]
|
383
|
+
assert !response[:partial_errors].nil?, "response should have partial errors"
|
384
|
+
end
|
385
|
+
|
386
|
+
|
387
|
+
test "get ads by group id" do
|
388
|
+
campaigns = @service.get_campaigns_by_account_id(@options[:account_id])
|
389
|
+
assert !campaigns.empty?, "No campaigns received for account id #{@options[:account_id]}"
|
390
|
+
campaign_id = campaigns.first.id
|
391
|
+
|
392
|
+
ad_group = @service.get_ad_groups_by_campaign_id(campaign_id).first
|
393
|
+
|
394
|
+
ads = @service.get_ads_by_ad_group_id(ad_group.id)
|
395
|
+
assert !ads.empty?, "No ads received for ad group #{ad_group.id}"
|
396
|
+
ads.each do |ad|
|
397
|
+
assert ad.is_a?(BingAdsApi::Ad), "Object received is not an ad"
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
|
402
|
+
test "get ads by ids" do
|
403
|
+
# campaigns = @service.get_campaigns_by_account_id(@options[:account_id])
|
404
|
+
# assert !campaigns.empty?, "No campaigns received for account id #{@options[:account_id]}"
|
405
|
+
# campaign_id = campaigns.first.id
|
406
|
+
# ad_group = @service.get_ad_groups_by_campaign_id(campaign_id).first
|
407
|
+
# ads = @service.get_ads_by_ad_group_id(ad_group.id)
|
408
|
+
ad_group_id = 1980939070
|
409
|
+
ads = @service.get_ads_by_ad_group_id(ad_group_id)
|
410
|
+
assert !ads.nil?, "No ads by ad group response received"
|
411
|
+
assert !ads.empty?, "No ads received for ad group #{ad_group_id}"
|
412
|
+
|
413
|
+
# Get 2 ads
|
414
|
+
ad_ids = [ads[0].id, ads[1].id]
|
415
|
+
ads_by_ids = @service.get_ads_by_ids(ad_group_id, ad_ids)
|
416
|
+
assert !ads_by_ids.nil?, "No response received"
|
417
|
+
assert !ads_by_ids.empty?, "No ads received for ad group #{ad_group_id} and ad ids #{ad_ids}"
|
418
|
+
assert ad_ids.size == ads_by_ids.size, "Expetected ads #{ad_ids.size}. Received #{ads_by_ids.size}"
|
419
|
+
ads.each do |ad|
|
420
|
+
assert ad.is_a?(BingAdsApi::Ad), "Object received is not an ad"
|
421
|
+
end
|
422
|
+
|
423
|
+
# Get specific ad
|
424
|
+
ad_ids = [ads[0].id]
|
425
|
+
ads_by_ids = @service.get_ads_by_ids(ad_group_id, ad_ids)
|
426
|
+
assert !ads_by_ids.nil?, "No response received"
|
427
|
+
assert !ads.empty?, "No ads received for ad group #{ad_group_id} and ad ids #{ad_ids}"
|
428
|
+
assert ad_ids.size == ads_by_ids.size, "Expetected one ad. Received #{ads_by_ids.size}"
|
429
|
+
|
430
|
+
end
|
431
|
+
|
432
|
+
|
433
|
+
test "update ads" do
|
434
|
+
|
435
|
+
ad_group_id = 1980939070
|
436
|
+
# One TextAd and one MobileAd
|
437
|
+
ad_ids = [4560003693, 4560003694]
|
438
|
+
|
439
|
+
ads = @service.get_ads_by_ids(ad_group_id, ad_ids)
|
440
|
+
|
441
|
+
# Loop to modify something in the adds
|
442
|
+
ads.each do |ad|
|
443
|
+
case ad.type
|
444
|
+
when "Text"
|
445
|
+
ad.text = ad.text + " updated"
|
446
|
+
when "Mobile"
|
447
|
+
ad.phone_number = 1234567890
|
448
|
+
when "Product"
|
449
|
+
ad.promotional_text = ad.promotional_text + " edit"
|
450
|
+
end
|
451
|
+
ad.status = nil
|
452
|
+
ad.editorial_status = nil
|
453
|
+
end
|
454
|
+
|
455
|
+
response = @service.update_ads(ad_group_id, ads)
|
456
|
+
assert !response.nil? , "No response received updateing ads"
|
457
|
+
|
458
|
+
assert response[:partial_errors].nil?, "response with partial errors when updating ads"
|
459
|
+
|
460
|
+
end
|
461
|
+
|
462
|
+
|
463
|
+
end
|