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.
Files changed (51) hide show
  1. data/lib/adzerk.rb +15 -0
  2. data/lib/adzerk/advertiser.rb +9 -0
  3. data/lib/adzerk/api_endpoint.rb +41 -0
  4. data/lib/adzerk/channel_site_map.rb +53 -0
  5. data/lib/adzerk/client.rb +80 -0
  6. data/lib/adzerk/creative.rb +17 -0
  7. data/lib/adzerk/creative_map.rb +38 -0
  8. data/lib/adzerk/flight.rb +12 -0
  9. data/lib/adzerk/invitation.rb +23 -0
  10. data/lib/adzerk/publisher.rb +17 -0
  11. data/lib/adzerk/reporting.rb +21 -0
  12. data/lib/adzerk/util.rb +37 -0
  13. data/lib/adzerk/version.rb +3 -0
  14. data/test/advertiser_api_spec.rb +57 -82
  15. data/test/campaign_api_spec.rb +150 -271
  16. data/test/channel_api_spec.rb +72 -79
  17. data/test/channel_site_map_api_spec.rb +43 -94
  18. data/test/creative_api_spec.rb +82 -251
  19. data/test/creative_map_api_spec.rb +291 -375
  20. data/test/flight_api_spec.rb +165 -493
  21. data/test/invitation_api_spec.rb +18 -41
  22. data/test/login_api_spec.rb +24 -49
  23. data/test/priority_api_spec.rb +53 -83
  24. data/test/publisher_api_spec.rb +71 -142
  25. data/test/rakefile.rb +7 -7
  26. data/test/report_api_spec.rb +18 -24
  27. data/test/security_api_spec.rb +21 -0
  28. data/test/site_api_spec.rb +37 -51
  29. data/test/spec_helper.rb +4 -17
  30. data/test/zone_api_spec.rb +38 -64
  31. metadata +61 -23
  32. data/lib/Adzerk.rb +0 -55
  33. data/lib/adzerk/Advertiser.rb +0 -39
  34. data/lib/adzerk/Campaign.rb +0 -33
  35. data/lib/adzerk/Channel.rb +0 -33
  36. data/lib/adzerk/ChannelSiteMap.rb +0 -44
  37. data/lib/adzerk/Creative.rb +0 -43
  38. data/lib/adzerk/CreativeMap.rb +0 -33
  39. data/lib/adzerk/Flight.rb +0 -44
  40. data/lib/adzerk/Invitation.rb +0 -17
  41. data/lib/adzerk/Login.rb +0 -28
  42. data/lib/adzerk/Priority.rb +0 -34
  43. data/lib/adzerk/Publisher.rb +0 -47
  44. data/lib/adzerk/Reporting.rb +0 -16
  45. data/lib/adzerk/Site.rb +0 -35
  46. data/lib/adzerk/Zone.rb +0 -35
  47. data/test/channel_api_security_spec.rb +0 -51
  48. data/test/csv_export_spec.rb +0 -89
  49. data/test/delivery-test.rb +0 -132
  50. data/test/test.rb +0 -43
  51. data/test/test2.rb +0 -175
@@ -1,311 +1,190 @@
1
- require './spec_helper.rb'
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
- new_advertiser = {
13
- 'Title' => "Test"
14
- }
15
- response = @@advertiser.create(new_advertiser)
16
- $advertiserId = JSON.parse(response.body)["Id"].to_s
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
- new_channel = {
19
- 'Title' => 'Test Channel ' + rand(1000000).to_s,
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
- new_priority = {
30
- 'Name' => "High Priority Test",
31
- 'ChannelId' => $channelId,
32
- 'Weight' => 1,
33
- 'IsDeleted' => false
34
- }
35
- response = @@priority.create(new_priority)
36
- $priority_id = JSON.parse(response.body)["Id"].to_s
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
- $campaign_Name = 'Test campaign ' + rand(1000000).to_s
42
- $campaign_StartDate = "1/1/2011"
43
- $campaign_EndDate = "12/31/2011"
44
- $campaign_IsActive = false
45
- $campaign_Price = '10.00'
46
- $campaign_AdvertiserId = $advertiserId.to_i
47
- $campaign_Flights = []
48
-
49
- new_campaign = {
50
- 'Name' => $campaign_Name,
51
- 'StartDate' => $campaign_StartDate,
52
- 'EndDate' => $campaign_EndDate,
53
- 'IsActive' => $campaign_IsActive,
54
- 'Price' => $campaign_Price,
55
- 'AdvertiserId' => $campaign_AdvertiserId,
56
- 'Flights' => $campaign_Flights,
57
- 'IsDeleted' => false
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
- $campaign_IsActive.should == JSON.parse(response.body)["IsActive"]
66
- $campaign_Price.to_f.should == JSON.parse(response.body)["Price"]
67
- $campaign_AdvertiserId.should == JSON.parse(response.body)["AdvertiserId"]
68
- JSON.parse(response.body)["IsDeleted"].should == false
69
- $campaign_Flights.should == JSON.parse(response.body)["Flights"]
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
- $campaign_Flights1 = [{
74
- 'StartDate' => "1/1/2011",
75
- 'EndDate' => "12/31/2011",
76
- 'NoEndDate' => false,
77
- 'Price' => "5.00",
78
- 'Keywords' => "test, test2",
79
- 'Name' => "Test",
80
- 'PriorityId' => $priority_id,
81
- 'Impressions' => 10000,
82
- 'IsDeleted' => false
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
- 'Name' => $campaign_Name,
86
- 'StartDate' => $campaign_StartDate,
87
- 'EndDate' => $campaign_EndDate,
88
- 'IsActive' => $campaign_IsActive,
89
- 'Price' => $campaign_Price,
90
- 'AdvertiserId' => $campaign_AdvertiserId,
91
- 'IsDeleted' => false,
92
- 'Flights' => $campaign_Flights1
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
- response = @@campaign.create(new1_campaign)
95
- $campaign_id1 = JSON.parse(response.body)["Id"].to_s
96
- $campaign_Name.should == JSON.parse(response.body)["Name"]
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
- $campaign_IsActive.should == JSON.parse(response.body)["IsActive"]
100
- JSON.parse(response.body)["IsDeleted"].should == false
101
- $campaign_Price.to_f.should == JSON.parse(response.body)["Price"]
102
- $campaign_AdvertiserId.should == JSON.parse(response.body)["AdvertiserId"]
103
- #$campaign_Flights1.to_json.should == JSON.parse(response.body)["Flights"]
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
- it "should create a new campaign with two flights" do
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
- response = @@campaign.get($campaign_id2)
142
- (response.body.scan($campaign_id2).empty?).should == false
143
- (response.body.scan('"Flights":[]').empty?).should == true
144
- (response.body.scan('"Flights":[').empty?).should == false
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
- $campaign_Name = 'Test campaign ' + rand(1000000).to_s
150
- $campaign_StartDate = "1/1/2011"
151
- $campaign_EndDate = "12/31/2011"
152
- $campaign_IsActive = false
153
- $campaign_Price = '10.00'
154
- $campaign_Flights = []
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
- it "should deactivate a campaign" do
181
- $campaign_Name = 'Test campaign ' + rand(1000000).to_s
182
- $campaign_StartDate = "1/1/2011"
183
- $campaign_EndDate = "12/31/2011"
184
- $campaign_IsActive = false
185
- $campaign_Price = '10.00'
186
- $campaign_Flights = []
187
-
188
- new_campaign = {
189
- 'Id' => $campaign_id,
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
- response = @@campaign.update(new_campaign)
201
- $campaign_id = JSON.parse(response.body)["Id"].to_s
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
- $campaign_IsActive.should == JSON.parse(response.body)["IsActive"]
206
- $campaign_Price.to_f.should == JSON.parse(response.body)["Price"]
207
- $campaign_AdvertiserId.should == JSON.parse(response.body)["AdvertiserId"]
208
- JSON.parse(response.body)["IsDeleted"].should == false
209
- $campaign_Flights.should == JSON.parse(response.body)["Flights"]
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
- result = @@campaign.list()
214
- result.length.should > 0
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 = @@campaign.delete($campaign_id)
226
- response.body.should == 'OK'
140
+ response = @campaigns.delete($campaign_id)
141
+ response.body.should == '"Successfully deleted."'
227
142
  end
228
-
229
- it "should not get individual deleted campaign" do
230
- response = @@campaign.get($campaign_id)
231
- true.should == !response.body.scan(/Exception/).empty?
232
- end
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
- response = @@campaign.update(updated_campaign)
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
- 'Name' => 'Test campaign ' + rand(1000000).to_s,
252
- 'StartDate' => "1/1/2011",
253
- 'EndDate' => "12/31/2011",
254
- 'IsActive' => false,
255
- 'Price' => '10.00',
256
- 'AdvertiserId' => '123',
257
- 'Flights' => [],
258
- 'IsDeleted' => false
259
- }
260
- response = @@campaign.create(new_campaign)
261
- true.should == !response.body.scan(/Exception/).empty?
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
- 'Id' => $campaign_id,
265
- 'Name' => 'Test campaign ' + rand(1000000).to_s,
266
- 'StartDate' => "1/1/2011",
267
- 'EndDate' => "12/31/2011",
268
- 'IsActive' => false,
269
- 'Price' => '10.00',
270
- 'AdvertiserId' => '123',
271
- 'Flights' => [],
272
- 'IsDeleted' => false
273
- }
274
- response = @@campaign.update(updated_campaign)
275
- #true.should == !response.body.scan(/Exception/).empty?
276
- end
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 create a new campaign with no end date" do
284
- $campaign_Name = 'Test campaign ' + rand(1000000).to_s
285
- $campaign_StartDate = "1/1/2011"
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