adzerk 0.1.4 → 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/adzerk.rb +15 -0
- data/lib/adzerk/advertiser.rb +9 -0
- data/lib/adzerk/api_endpoint.rb +41 -0
- data/lib/adzerk/channel_site_map.rb +53 -0
- data/lib/adzerk/client.rb +80 -0
- data/lib/adzerk/creative.rb +17 -0
- data/lib/adzerk/creative_map.rb +38 -0
- data/lib/adzerk/flight.rb +12 -0
- data/lib/adzerk/invitation.rb +23 -0
- data/lib/adzerk/publisher.rb +17 -0
- data/lib/adzerk/reporting.rb +21 -0
- data/lib/adzerk/util.rb +37 -0
- data/lib/adzerk/version.rb +3 -0
- data/test/advertiser_api_spec.rb +57 -82
- data/test/campaign_api_spec.rb +150 -271
- data/test/channel_api_spec.rb +72 -79
- data/test/channel_site_map_api_spec.rb +43 -94
- data/test/creative_api_spec.rb +82 -251
- data/test/creative_map_api_spec.rb +291 -375
- data/test/flight_api_spec.rb +165 -493
- data/test/invitation_api_spec.rb +18 -41
- data/test/login_api_spec.rb +24 -49
- data/test/priority_api_spec.rb +53 -83
- data/test/publisher_api_spec.rb +71 -142
- data/test/rakefile.rb +7 -7
- data/test/report_api_spec.rb +18 -24
- data/test/security_api_spec.rb +21 -0
- data/test/site_api_spec.rb +37 -51
- data/test/spec_helper.rb +4 -17
- data/test/zone_api_spec.rb +38 -64
- metadata +61 -23
- data/lib/Adzerk.rb +0 -55
- data/lib/adzerk/Advertiser.rb +0 -39
- data/lib/adzerk/Campaign.rb +0 -33
- data/lib/adzerk/Channel.rb +0 -33
- data/lib/adzerk/ChannelSiteMap.rb +0 -44
- data/lib/adzerk/Creative.rb +0 -43
- data/lib/adzerk/CreativeMap.rb +0 -33
- data/lib/adzerk/Flight.rb +0 -44
- data/lib/adzerk/Invitation.rb +0 -17
- data/lib/adzerk/Login.rb +0 -28
- data/lib/adzerk/Priority.rb +0 -34
- data/lib/adzerk/Publisher.rb +0 -47
- data/lib/adzerk/Reporting.rb +0 -16
- data/lib/adzerk/Site.rb +0 -35
- data/lib/adzerk/Zone.rb +0 -35
- data/test/channel_api_security_spec.rb +0 -51
- data/test/csv_export_spec.rb +0 -89
- data/test/delivery-test.rb +0 -132
- data/test/test.rb +0 -43
- data/test/test2.rb +0 -175
data/test/campaign_api_spec.rb
CHANGED
@@ -1,311 +1,190 @@
|
|
1
|
-
require '
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe "Campaign API" do
|
4
|
-
|
5
|
-
$campaign_url = 'http://www.adzerk.com'
|
6
|
-
@@campaign = $adzerk::Campaign.new
|
7
|
-
@@advertiser = $adzerk::Advertiser.new
|
8
|
-
@@channel = $adzerk::Channel.new
|
9
|
-
@@priority = $adzerk::Priority.new
|
10
4
|
|
11
5
|
before(:all) do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
6
|
+
client = Adzerk::Client.new(API_KEY)
|
7
|
+
@campaigns = client.campaigns
|
8
|
+
@advertisers = client.advertisers
|
9
|
+
@channels = client.channels
|
10
|
+
@priorities = client.priorities
|
17
11
|
|
18
|
-
|
19
|
-
|
20
|
-
'Commission' => '0.0',
|
21
|
-
'Engine' => 'CPM',
|
22
|
-
'Keywords' => 'test',
|
23
|
-
'CPM' => '10.00',
|
24
|
-
'AdTypes' => [1,2,3,4]
|
25
|
-
}
|
26
|
-
response = @@channel.create(new_channel)
|
27
|
-
$channelId = JSON.parse(response.body)["Id"].to_s
|
12
|
+
advertiser = @advertisers.create(:title => "test")
|
13
|
+
$advertiserId = advertiser[:id].to_s
|
28
14
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
15
|
+
channel = @channels.create(:title => 'Test Channel ' + rand(1000000).to_s,
|
16
|
+
:commission => '0.0',
|
17
|
+
:engine => 'CPM',
|
18
|
+
:keywords => 'test',
|
19
|
+
'CPM' => '10.00',
|
20
|
+
:ad_types => [1,2,3,4])
|
21
|
+
$channel_id = channel[:id].to_s
|
22
|
+
|
23
|
+
priority = @priorities.create(:name => "High Priority Test",
|
24
|
+
:channel_id => $channel_id,
|
25
|
+
:weight => 1,
|
26
|
+
:is_deleted => false)
|
27
|
+
$priority_id = priority[:id].to_s
|
38
28
|
end
|
39
|
-
|
29
|
+
|
30
|
+
|
31
|
+
|
40
32
|
it "should create a new campaign with no flights" do
|
41
|
-
$
|
42
|
-
$
|
43
|
-
$
|
44
|
-
$
|
45
|
-
$
|
46
|
-
$
|
47
|
-
$
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
response = @@campaign.create(new_campaign)
|
61
|
-
$campaign_id = JSON.parse(response.body)["Id"].to_s
|
62
|
-
$campaign_Name.should == JSON.parse(response.body)["Name"]
|
33
|
+
$campaign_name = 'Test campaign ' + rand(1000000).to_s
|
34
|
+
$campaign_start_date = "1/1/2011"
|
35
|
+
$campaign_end_date = "12/31/2011"
|
36
|
+
$campaign_is_active = false
|
37
|
+
$campaign_price = '10.00'
|
38
|
+
$campaign_advertiser_id = $advertiserId.to_i
|
39
|
+
$campaign_flights = []
|
40
|
+
|
41
|
+
campaign = @campaigns.create(:name => $campaign_name,
|
42
|
+
:start_date => $campaign_start_date,
|
43
|
+
:end_date => $campaign_end_date,
|
44
|
+
:is_active => $campaign_is_active,
|
45
|
+
:price => $campaign_price,
|
46
|
+
:advertiser_id => $campaign_advertiser_id,
|
47
|
+
:flights => $campaign_flights,
|
48
|
+
:is_deleted => false)
|
49
|
+
|
50
|
+
$campaign_id = campaign[:id].to_s
|
51
|
+
$campaign_name.should == campaign[:name]
|
63
52
|
# JSON.parse(response.body)["StartDate"].should == "/Date(1293858000000-0500)/"
|
64
53
|
# JSON.parse(response.body)["EndDate"].should == "/Date(1325307600000-0500)/"
|
65
|
-
$
|
66
|
-
$
|
67
|
-
$
|
68
|
-
|
69
|
-
|
54
|
+
$campaign_is_active.should == campaign[:is_active]
|
55
|
+
$campaign_price.to_f.should == campaign[:price]
|
56
|
+
$campaign_advertiser_id.should == campaign[:advertiser_id]
|
57
|
+
campaign[:is_deleted].should == false
|
58
|
+
campaign[:flights].should eq([])
|
70
59
|
end
|
71
|
-
|
60
|
+
|
72
61
|
it "should create a new campaign with one flight" do
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
62
|
+
@campaign_flights_1 = [{
|
63
|
+
:start_date => "1/1/2011",
|
64
|
+
:end_date => "12/31/2011",
|
65
|
+
:no_end_date => false,
|
66
|
+
:price => "5.00",
|
67
|
+
:keywords => "test, test2",
|
68
|
+
:name => "Test",
|
69
|
+
:priority_id => $priority_id,
|
70
|
+
:impressions => 10000,
|
71
|
+
:is_deleted => false
|
83
72
|
}]
|
84
73
|
new1_campaign = {
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
74
|
+
:name => $campaign_name,
|
75
|
+
:start_date => $campaign_start_date,
|
76
|
+
:end_date => $campaign_end_date,
|
77
|
+
:is_active => $campaign_is_active,
|
78
|
+
:price => $campaign_price,
|
79
|
+
:advertiser_id => $campaign_advertiser_id,
|
80
|
+
:is_deleted => false,
|
81
|
+
:flights => @campaign_flights_1
|
93
82
|
}
|
94
|
-
|
95
|
-
$
|
96
|
-
$
|
83
|
+
campaign = @campaigns.create(new1_campaign)
|
84
|
+
$campaign_id_1 = campaign[:id].to_s
|
85
|
+
$campaign_name.should == campaign[:name]
|
97
86
|
# JSON.parse(response.body)["StartDate"].should == "/Date(1293858000000-0500)/"
|
98
87
|
# JSON.parse(response.body)["EndDate"].should == "/Date(1325307600000-0500)/"
|
99
|
-
$
|
100
|
-
|
101
|
-
$
|
102
|
-
$
|
103
|
-
|
88
|
+
$campaign_is_active.should == campaign[:is_active]
|
89
|
+
campaign[:is_deleted].should == false
|
90
|
+
$campaign_price.to_f.should == campaign[:price]
|
91
|
+
$campaign_advertiser_id.should == campaign[:advertiser_id]
|
92
|
+
campaign[:flights].first[:id].should_not == nil
|
104
93
|
end
|
105
|
-
|
106
|
-
|
107
|
-
$campaign_Flights2 = [{
|
108
|
-
'StartDate' => "1/1/2011",
|
109
|
-
'EndDate' => "12/31/2011",
|
110
|
-
'NoEndDate' => false,
|
111
|
-
'Price' => "5.00",
|
112
|
-
'Keywords' => "test, test2",
|
113
|
-
'Name' => "Test",
|
114
|
-
'PriorityId' => $priority_id,
|
115
|
-
'Impressions' => 10000
|
116
|
-
},{
|
117
|
-
'StartDate' => "1/1/2010",
|
118
|
-
'EndDate' => "12/31/2012",
|
119
|
-
'NoEndDate' => false,
|
120
|
-
'Price' => "10.00",
|
121
|
-
'Keywords' => "test, test2, test3",
|
122
|
-
'Name' => "Test3",
|
123
|
-
'PriorityId' => $priority_id,
|
124
|
-
'Impressions' => 15000
|
125
|
-
}]
|
126
|
-
new2_campaign = {
|
127
|
-
'Name' => $campaign_Name,
|
128
|
-
'StartDate' => $campaign_StartDate,
|
129
|
-
'EndDate' => $campaign_EndDate,
|
130
|
-
'IsActive' => $campaign_IsActive,
|
131
|
-
'Price' => $campaign_Price,
|
132
|
-
'AdvertiserId' => $campaign_AdvertiserId,
|
133
|
-
'Flights' => $campaign_Flights2
|
134
|
-
}
|
135
|
-
response = @@campaign.create(new2_campaign)
|
136
|
-
$campaign_id2 = JSON.parse(response.body)["Id"].to_s
|
137
|
-
JSON.parse(response.body)["Flights"].length.should == 2
|
138
|
-
end
|
139
|
-
|
94
|
+
|
95
|
+
|
140
96
|
it "should list a specific campaign" do
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
(response.body.scan($campaign_Name).empty?).should == false
|
97
|
+
campaign = @campaigns.get($campaign_id_1)
|
98
|
+
campaign[:id].should eq($campaign_id_1.to_i)
|
99
|
+
campaign[:flights].should_not be_empty
|
100
|
+
campaign[:name].should eq($campaign_name)
|
146
101
|
end
|
147
|
-
|
102
|
+
|
148
103
|
it "should update a campaign" do
|
149
|
-
$
|
150
|
-
$
|
151
|
-
$
|
152
|
-
$
|
153
|
-
$
|
154
|
-
$
|
155
|
-
|
156
|
-
new_campaign = {
|
157
|
-
'Id' => $campaign_id,
|
158
|
-
'Name' => $campaign_Name,
|
159
|
-
'StartDate' => $campaign_StartDate,
|
160
|
-
'EndDate' => $campaign_EndDate,
|
161
|
-
'IsActive' => $campaign_IsActive,
|
162
|
-
'Price' => $campaign_Price,
|
163
|
-
'AdvertiserId' => $campaign_AdvertiserId,
|
164
|
-
'Flights' => $campaign_Flights,
|
165
|
-
'IsDeleted' => false
|
166
|
-
}
|
167
|
-
|
168
|
-
response = @@campaign.update(new_campaign)
|
169
|
-
$campaign_id = JSON.parse(response.body)["Id"].to_s
|
170
|
-
$campaign_Name.should == JSON.parse(response.body)["Name"]
|
171
|
-
# JSON.parse(response.body)["StartDate"].should == "/Date(1293858000000-0500)/"
|
172
|
-
# JSON.parse(response.body)["EndDate"].should == "/Date(1325307600000-0500)/"
|
173
|
-
$campaign_IsActive.should == JSON.parse(response.body)["IsActive"]
|
174
|
-
$campaign_Price.to_f.should == JSON.parse(response.body)["Price"]
|
175
|
-
$campaign_AdvertiserId.should == JSON.parse(response.body)["AdvertiserId"]
|
176
|
-
JSON.parse(response.body)["IsDeleted"].should == false
|
177
|
-
$campaign_Flights.should == JSON.parse(response.body)["Flights"]
|
178
|
-
end
|
104
|
+
$campaign_name = 'Test campaign ' + rand(1000000).to_s
|
105
|
+
$campaign_start_date = "1/1/2011"
|
106
|
+
$campaign_end_date = "12/31/2011"
|
107
|
+
$campaign_is_active = false
|
108
|
+
$campaign_price = '12.00'
|
109
|
+
$campaign_flights = []
|
179
110
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
'Name' => $campaign_Name,
|
191
|
-
'StartDate' => $campaign_StartDate,
|
192
|
-
'EndDate' => $campaign_EndDate,
|
193
|
-
'IsActive' => $campaign_IsActive,
|
194
|
-
'Price' => $campaign_Price,
|
195
|
-
'AdvertiserId' => $campaign_AdvertiserId,
|
196
|
-
'Flights' => $campaign_Flights,
|
197
|
-
'IsDeleted' => false
|
111
|
+
campaign_to_update = {
|
112
|
+
:id => $campaign_id,
|
113
|
+
:name => $campaign_name,
|
114
|
+
:start_date => $campaign_start_date,
|
115
|
+
:end_date => $campaign_end_date,
|
116
|
+
:is_active => $campaign_is_active,
|
117
|
+
:price => $campaign_price,
|
118
|
+
:advertiser_id => $campaign_advertiser_id,
|
119
|
+
:flights => $campaign_flights,
|
120
|
+
:is_deleted => false
|
198
121
|
}
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
$campaign_Name.should == JSON.parse(response.body)["Name"]
|
122
|
+
|
123
|
+
campaign = @campaigns.update(campaign_to_update)
|
124
|
+
campaign[:name].should eq($campaign_name)
|
203
125
|
# JSON.parse(response.body)["StartDate"].should == "/Date(1293858000000-0500)/"
|
204
126
|
# JSON.parse(response.body)["EndDate"].should == "/Date(1325307600000-0500)/"
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
127
|
+
campaign[:is_active].should eq($campaign_is_active)
|
128
|
+
campaign[:price].should eq($campaign_price.to_f)
|
129
|
+
campaign[:advertiser_id].should eq($campaign_advertiser_id)
|
130
|
+
campaign[:is_deleted].should eq(false)
|
131
|
+
campaign[:flights].should eq($campaign_flights)
|
210
132
|
end
|
211
|
-
|
133
|
+
|
212
134
|
it "should list all campaigns" do
|
213
|
-
|
214
|
-
|
215
|
-
# result["Items"].last["Id"].to_s.should == $campaign_id
|
216
|
-
# result["Items"].last["Title"].should == $u_campaign_title
|
217
|
-
# result["Items"].last["Commission"].should == $u_campaign_commission.to_f
|
218
|
-
# result["Items"].last["Engine"].should == $u_campaign_engine
|
219
|
-
# result["Items"].last["Keywords"].should == $u_campaign_keywords
|
220
|
-
# result["Items"].last["CPM"].to_s.should == $u_campaign_CPM.to_f.to_s
|
221
|
-
# result["Items"].last["AdTypes"].should == $u_campaign_AdTypes
|
135
|
+
campaigns = @campaigns.list
|
136
|
+
campaigns.length.should > 0
|
222
137
|
end
|
223
|
-
|
138
|
+
|
224
139
|
it "should delete a new campaign" do
|
225
|
-
response =
|
226
|
-
response.body.should == '
|
140
|
+
response = @campaigns.delete($campaign_id)
|
141
|
+
response.body.should == '"Successfully deleted."'
|
227
142
|
end
|
228
|
-
|
229
|
-
it "should not
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
it "should not update deleted campaigns" do
|
235
|
-
updated_campaign = {
|
236
|
-
'Id' => $campaign_id,
|
237
|
-
'Name' => $campaign_Name,
|
238
|
-
'StartDate' => $campaign_StartDate,
|
239
|
-
'EndDate' => $campaign_EndDate,
|
240
|
-
'IsActive' => $campaign_IsActive,
|
241
|
-
'Price' => $campaign_Price,
|
242
|
-
'AdvertiserId' => $campaign_AdvertiserId,
|
243
|
-
'Flights' => $campaign_Flights,
|
244
|
-
'IsDeleted' => false
|
143
|
+
|
144
|
+
it "should not update a deleted campaign" do
|
145
|
+
campaign_to_update = {
|
146
|
+
:id => $campaign_id,
|
147
|
+
:name => "test"
|
245
148
|
}
|
246
|
-
|
149
|
+
|
150
|
+
campaign = @campaigns.update(campaign_to_update)
|
151
|
+
campaign[:message].should eq("This advertiser is not part of your network")
|
247
152
|
end
|
248
|
-
|
153
|
+
|
249
154
|
it "should not create/update a campaign with a advertiserId that doesn't belong to it" do
|
250
155
|
new_campaign = {
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
}
|
260
|
-
|
261
|
-
|
262
|
-
|
156
|
+
:name => 'Test campaign ' + rand(1000000).to_s,
|
157
|
+
:start_date => "1/1/2011",
|
158
|
+
:end_date => "12/31/2011",
|
159
|
+
:is_active => false,
|
160
|
+
:price => '10.00',
|
161
|
+
:advertiser_id => '123',
|
162
|
+
:flights => [],
|
163
|
+
:is_deleted => false
|
164
|
+
}
|
165
|
+
|
166
|
+
campaign = @campaigns.create(new_campaign)
|
167
|
+
campaign[:message].should eq("This advertiser is not part of your network")
|
168
|
+
|
263
169
|
updated_campaign = {
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
}
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
it "should not retrieve a campaign with a advertiserId that doesn't belong to it" do
|
279
|
-
response = @@campaign.get('123')
|
280
|
-
true.should == !response.body.scan(/Exception/).empty?
|
170
|
+
:id => $campaign_id,
|
171
|
+
:name => 'Test campaign ' + rand(1000000).to_s,
|
172
|
+
:start_date => "1/1/2011",
|
173
|
+
:end_date => "12/31/2011",
|
174
|
+
:is_active => false,
|
175
|
+
:price => '10.00',
|
176
|
+
:advertiser_id => '123',
|
177
|
+
:flights => [],
|
178
|
+
:is_deleted => false
|
179
|
+
}
|
180
|
+
|
181
|
+
campaign = @campaigns.update(updated_campaign)
|
182
|
+
campaign[:message].should eq("This advertiser is not part of your network")
|
281
183
|
end
|
282
184
|
|
283
|
-
it "should
|
284
|
-
|
285
|
-
|
286
|
-
$campaign_EndDate = "12/31/2011"
|
287
|
-
$campaign_IsActive = false
|
288
|
-
$campaign_Price = '10.00'
|
289
|
-
$campaign_AdvertiserId = $advertiserId.to_i
|
290
|
-
$campaign_Flights = []
|
291
|
-
|
292
|
-
new_campaign = {
|
293
|
-
'Name' => $campaign_Name,
|
294
|
-
'StartDate' => $campaign_StartDate,
|
295
|
-
'IsActive' => $campaign_IsActive,
|
296
|
-
'Price' => $campaign_Price,
|
297
|
-
'AdvertiserId' => $campaign_AdvertiserId,
|
298
|
-
'Flights' => $campaign_Flights,
|
299
|
-
'IsDeleted' => false
|
300
|
-
}
|
301
|
-
|
302
|
-
response = @@campaign.create(new_campaign)
|
303
|
-
$campaign_Name.should == JSON.parse(response.body)["Name"]
|
304
|
-
$campaign_IsActive.should == JSON.parse(response.body)["IsActive"]
|
305
|
-
$campaign_Price.to_f.should == JSON.parse(response.body)["Price"]
|
306
|
-
$campaign_AdvertiserId.should == JSON.parse(response.body)["AdvertiserId"]
|
307
|
-
JSON.parse(response.body)["IsDeleted"].should == false
|
308
|
-
$campaign_Flights.should == JSON.parse(response.body)["Flights"]
|
185
|
+
it "should not retrieve a campaign with a advertiserId that doesn't belong to it" do
|
186
|
+
response = @campaigns.get('123')
|
187
|
+
response[:message].should eq("This campaign is not part of your network")
|
309
188
|
end
|
310
189
|
|
311
190
|
end
|