adzerk 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/Adzerk.rb +49 -0
- data/lib/adzerk/Advertiser.rb +33 -0
- data/lib/adzerk/Campaign.rb +33 -0
- data/lib/adzerk/Channel.rb +33 -0
- data/lib/adzerk/Creative.rb +46 -0
- data/lib/adzerk/CreativeMap.rb +33 -0
- data/lib/adzerk/Flight.rb +33 -0
- data/lib/adzerk/Invitation.rb +17 -0
- data/lib/adzerk/Login.rb +28 -0
- data/lib/adzerk/Publisher.rb +33 -0
- data/lib/adzerk/Reporting.rb +11 -0
- data/lib/adzerk/Site.rb +35 -0
- data/test/advertiser_api_spec.rb +101 -0
- data/test/campaign_api_spec.rb +238 -0
- data/test/channel_api_security_spec.rb +51 -0
- data/test/channel_api_spec.rb +111 -0
- data/test/creative_api_spec.rb +167 -0
- data/test/creative_map_api_spec.rb +331 -0
- data/test/flight_api_spec.rb +296 -0
- data/test/invitation_api_spec.rb +45 -0
- data/test/login_api_spec.rb +52 -0
- data/test/publisher_api_spec.rb +147 -0
- data/test/rakefile.rb +26 -0
- data/test/report_api_spec.rb +30 -0
- data/test/site_api_spec.rb +77 -0
- data/test/spec_helper.rb +19 -0
- metadata +89 -0
@@ -0,0 +1,238 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
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
|
+
|
10
|
+
before(:all) do
|
11
|
+
new_advertiser = {
|
12
|
+
'Title' => "Test"
|
13
|
+
}
|
14
|
+
response = @@advertiser.create(new_advertiser)
|
15
|
+
$brandId = JSON.parse(response.body)["Id"].to_s
|
16
|
+
|
17
|
+
new_channel = {
|
18
|
+
'Title' => 'Test Channel ' + rand(1000000).to_s,
|
19
|
+
'Commission' => '0',
|
20
|
+
'Engine' => 'CPM',
|
21
|
+
'Keywords' => 'test',
|
22
|
+
'CPM' => '10.00',
|
23
|
+
'AdTypes' => [0,1,2,3,4]
|
24
|
+
}
|
25
|
+
response = @@channel.create(new_channel)
|
26
|
+
$channelId = JSON.parse(response.body)["Id"].to_s
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should create a new campaign with no flights" do
|
31
|
+
$campaign_Name = 'Test campaign ' + rand(1000000).to_s
|
32
|
+
$campaign_StartDate = "1/1/2011"
|
33
|
+
$campaign_EndDate = "12/31/2011"
|
34
|
+
$campaign_IsActive = false
|
35
|
+
$campaign_Price = '10.00'
|
36
|
+
$campaign_BrandId = $brandId.to_i
|
37
|
+
$campaign_Flights = []
|
38
|
+
|
39
|
+
new_campaign = {
|
40
|
+
'Name' => $campaign_Name,
|
41
|
+
'StartDate' => $campaign_StartDate,
|
42
|
+
'EndDate' => $campaign_EndDate,
|
43
|
+
'IsActive' => $campaign_IsActive,
|
44
|
+
'Price' => $campaign_Price,
|
45
|
+
'BrandId' => $campaign_BrandId,
|
46
|
+
'Flights' => $campaign_Flights,
|
47
|
+
'IsDeleted' => false
|
48
|
+
}
|
49
|
+
|
50
|
+
response = @@campaign.create(new_campaign)
|
51
|
+
$campaign_id = JSON.parse(response.body)["Id"].to_s
|
52
|
+
$campaign_Name.should == JSON.parse(response.body)["Name"]
|
53
|
+
# JSON.parse(response.body)["StartDate"].should == "/Date(1293858000000-0500)/"
|
54
|
+
# JSON.parse(response.body)["EndDate"].should == "/Date(1325307600000-0500)/"
|
55
|
+
$campaign_IsActive.should == JSON.parse(response.body)["IsActive"]
|
56
|
+
$campaign_Price.to_f.should == JSON.parse(response.body)["Price"]
|
57
|
+
$campaign_BrandId.should == JSON.parse(response.body)["BrandId"]
|
58
|
+
JSON.parse(response.body)["IsDeleted"].should == false
|
59
|
+
$campaign_Flights.should == JSON.parse(response.body)["Flights"]
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should create a new campaign with one flight" do
|
63
|
+
$campaign_Flights1 = [{
|
64
|
+
'StartDate' => "1/1/2011",
|
65
|
+
'EndDate' => "12/31/2011",
|
66
|
+
'NoEndDate' => false,
|
67
|
+
'Price' => "5.00",
|
68
|
+
'Keywords' => "test, test2",
|
69
|
+
'Name' => "Test",
|
70
|
+
'ChannelId' => $channelId,
|
71
|
+
'Impressions' => 10000,
|
72
|
+
'IsDeleted' => false
|
73
|
+
}]
|
74
|
+
new1_campaign = {
|
75
|
+
'Name' => $campaign_Name,
|
76
|
+
'StartDate' => $campaign_StartDate,
|
77
|
+
'EndDate' => $campaign_EndDate,
|
78
|
+
'IsActive' => $campaign_IsActive,
|
79
|
+
'Price' => $campaign_Price,
|
80
|
+
'BrandId' => $campaign_BrandId,
|
81
|
+
'IsDeleted' => false,
|
82
|
+
'Flights' => $campaign_Flights1
|
83
|
+
}
|
84
|
+
response = @@campaign.create(new1_campaign)
|
85
|
+
$campaign_id1 = JSON.parse(response.body)["Id"].to_s
|
86
|
+
$campaign_Name.should == JSON.parse(response.body)["Name"]
|
87
|
+
# JSON.parse(response.body)["StartDate"].should == "/Date(1293858000000-0500)/"
|
88
|
+
# JSON.parse(response.body)["EndDate"].should == "/Date(1325307600000-0500)/"
|
89
|
+
$campaign_IsActive.should == JSON.parse(response.body)["IsActive"]
|
90
|
+
JSON.parse(response.body)["IsDeleted"].should == false
|
91
|
+
$campaign_Price.to_f.should == JSON.parse(response.body)["Price"]
|
92
|
+
$campaign_BrandId.should == JSON.parse(response.body)["BrandId"]
|
93
|
+
#$campaign_Flights1.to_json.should == JSON.parse(response.body)["Flights"]
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should create a new campaign with two flights" do
|
97
|
+
$campaign_Flights2 = [{
|
98
|
+
'StartDate' => "1/1/2011",
|
99
|
+
'EndDate' => "12/31/2011",
|
100
|
+
'NoEndDate' => false,
|
101
|
+
'Price' => "5.00",
|
102
|
+
'Keywords' => "test, test2",
|
103
|
+
'Name' => "Test",
|
104
|
+
'ChannelId' => $channelId,
|
105
|
+
'Impressions' => 10000
|
106
|
+
},{
|
107
|
+
'StartDate' => "1/1/2010",
|
108
|
+
'EndDate' => "12/31/2012",
|
109
|
+
'NoEndDate' => false,
|
110
|
+
'Price' => "10.00",
|
111
|
+
'Keywords' => "test, test2, test3",
|
112
|
+
'Name' => "Test3",
|
113
|
+
'ChannelId' => $channelId,
|
114
|
+
'Impressions' => 15000
|
115
|
+
}]
|
116
|
+
new2_campaign = {
|
117
|
+
'Name' => $campaign_Name,
|
118
|
+
'StartDate' => $campaign_StartDate,
|
119
|
+
'EndDate' => $campaign_EndDate,
|
120
|
+
'IsActive' => $campaign_IsActive,
|
121
|
+
'Price' => $campaign_Price,
|
122
|
+
'BrandId' => $campaign_BrandId,
|
123
|
+
'Flights' => $campaign_Flights2
|
124
|
+
}
|
125
|
+
response = @@campaign.create(new2_campaign)
|
126
|
+
$campaign_id2 = JSON.parse(response.body)["Id"].to_s
|
127
|
+
JSON.parse(response.body)["Flights"].length.should == 2
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should list a specific campaign" do
|
131
|
+
response = @@campaign.get($campaign_id)
|
132
|
+
response.body.should == '{"Id":' + $campaign_id + ',"Name":"' + $campaign_Name + '","StartDate":"\/Date(1293840000000+0000)\/","EndDate":"\/Date(1325289600000+0000)\/","IsActive":false,"Price":' + $campaign_Price + ',"BrandId":' + $campaign_BrandId.to_s + ',"IsDeleted":false}'
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should update a campaign" do
|
136
|
+
$campaign_Name = 'Test campaign ' + rand(1000000).to_s
|
137
|
+
$campaign_StartDate = "1/1/2011"
|
138
|
+
$campaign_EndDate = "12/31/2011"
|
139
|
+
$campaign_IsActive = false
|
140
|
+
$campaign_Price = '10.00'
|
141
|
+
$campaign_Flights = []
|
142
|
+
|
143
|
+
new_campaign = {
|
144
|
+
'Id' => $campaign_id,
|
145
|
+
'Name' => $campaign_Name,
|
146
|
+
'StartDate' => $campaign_StartDate,
|
147
|
+
'EndDate' => $campaign_EndDate,
|
148
|
+
'IsActive' => $campaign_IsActive,
|
149
|
+
'Price' => $campaign_Price,
|
150
|
+
'BrandId' => $campaign_BrandId,
|
151
|
+
'Flights' => $campaign_Flights,
|
152
|
+
'IsDeleted' => false
|
153
|
+
}
|
154
|
+
|
155
|
+
response = @@campaign.update(new_campaign)
|
156
|
+
$campaign_id = JSON.parse(response.body)["Id"].to_s
|
157
|
+
$campaign_Name.should == JSON.parse(response.body)["Name"]
|
158
|
+
# JSON.parse(response.body)["StartDate"].should == "/Date(1293858000000-0500)/"
|
159
|
+
# JSON.parse(response.body)["EndDate"].should == "/Date(1325307600000-0500)/"
|
160
|
+
$campaign_IsActive.should == JSON.parse(response.body)["IsActive"]
|
161
|
+
$campaign_Price.to_f.should == JSON.parse(response.body)["Price"]
|
162
|
+
$campaign_BrandId.should == JSON.parse(response.body)["BrandId"]
|
163
|
+
JSON.parse(response.body)["IsDeleted"].should == false
|
164
|
+
$campaign_Flights.should == JSON.parse(response.body)["Flights"]
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should list all campaigns" do
|
168
|
+
result = @@campaign.list()
|
169
|
+
result.length.should > 0
|
170
|
+
# result["Items"].last["Id"].to_s.should == $campaign_id
|
171
|
+
# result["Items"].last["Title"].should == $u_campaign_title
|
172
|
+
# result["Items"].last["Commission"].should == $u_campaign_commission.to_f
|
173
|
+
# result["Items"].last["Engine"].should == $u_campaign_engine
|
174
|
+
# result["Items"].last["Keywords"].should == $u_campaign_keywords
|
175
|
+
# result["Items"].last["CPM"].to_s.should == $u_campaign_CPM.to_f.to_s
|
176
|
+
# result["Items"].last["AdTypes"].should == $u_campaign_AdTypes
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should delete a new campaign" do
|
180
|
+
response = @@campaign.delete($campaign_id)
|
181
|
+
response.body.should == 'OK'
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should not get individual deleted campaign" do
|
185
|
+
response = @@campaign.get($campaign_id)
|
186
|
+
true.should == !response.body.scan(/Object/).nil?
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should not update deleted campaigns" do
|
190
|
+
updated_campaign = {
|
191
|
+
'Id' => $campaign_id,
|
192
|
+
'Name' => $campaign_Name,
|
193
|
+
'StartDate' => $campaign_StartDate,
|
194
|
+
'EndDate' => $campaign_EndDate,
|
195
|
+
'IsActive' => $campaign_IsActive,
|
196
|
+
'Price' => $campaign_Price,
|
197
|
+
'BrandId' => $campaign_BrandId,
|
198
|
+
'Flights' => $campaign_Flights,
|
199
|
+
'IsDeleted' => false
|
200
|
+
}
|
201
|
+
response = @@campaign.update(updated_campaign)
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should not create/update a campaign with a brandId that doesn't belong to it" do
|
205
|
+
new_campaign = {
|
206
|
+
'Name' => 'Test campaign ' + rand(1000000).to_s,
|
207
|
+
'StartDate' => "1/1/2011",
|
208
|
+
'EndDate' => "12/31/2011",
|
209
|
+
'IsActive' => false,
|
210
|
+
'Price' => '10.00',
|
211
|
+
'BrandId' => '123',
|
212
|
+
'Flights' => [],
|
213
|
+
'IsDeleted' => false
|
214
|
+
}
|
215
|
+
response = @@campaign.create(new_campaign)
|
216
|
+
true.should == !response.body.scan(/Object/).nil?
|
217
|
+
|
218
|
+
updated_campaign = {
|
219
|
+
'Id' => $campaign_id,
|
220
|
+
'Name' => 'Test campaign ' + rand(1000000).to_s,
|
221
|
+
'StartDate' => "1/1/2011",
|
222
|
+
'EndDate' => "12/31/2011",
|
223
|
+
'IsActive' => false,
|
224
|
+
'Price' => '10.00',
|
225
|
+
'BrandId' => '123',
|
226
|
+
'Flights' => [],
|
227
|
+
'IsDeleted' => false
|
228
|
+
}
|
229
|
+
response = @@campaign.update(updated_campaign)
|
230
|
+
true.should == !response.body.scan(/Object/).nil?
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should not retrieve a campaign with a brandId that doesn't belong to it" do
|
234
|
+
response = @@campaign.get('123')
|
235
|
+
true.should == !response.body.scan(/Object/).nil?
|
236
|
+
end
|
237
|
+
|
238
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'net/http'
|
3
|
+
describe "Channel API security" do
|
4
|
+
|
5
|
+
channel_url = 'http://www.adzerk.com'
|
6
|
+
channel = $adzerk::Channel.new
|
7
|
+
|
8
|
+
it "should reject unauthenticated GET requests" do
|
9
|
+
uri = URI.parse(ENV['ADZERK_API_HOST'] + 'channel/')
|
10
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
11
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
12
|
+
http.request(request).response.code.should_not == 200
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should reject GET requests with null API keys" do
|
16
|
+
uri = URI.parse(ENV['ADZERK_API_HOST'] + 'channel/')
|
17
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
18
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
19
|
+
request.add_field "X-Adzerk-ApiKey", ""
|
20
|
+
http.request(request).response.code.should_not == 200
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should reject GET requests with SQL injection attack as API keys" do
|
24
|
+
uri = URI.parse(ENV['ADZERK_API_HOST'] + 'channel/')
|
25
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
26
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
27
|
+
request.add_field "X-Adzerk-ApiKey", "hi' or 1=1--"
|
28
|
+
http.request(request).response.code.should_not == 200
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should reject an attempt to delete a channel not of the same network" do
|
32
|
+
channel.delete("14").response.code.should_not == 200
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
it "should reject an attempt to update a channel not of the same network" do
|
37
|
+
updated_channel = {
|
38
|
+
'Id' => 14,
|
39
|
+
'Title' => "The Impossible Dream",
|
40
|
+
'Commission' => 0,
|
41
|
+
'Engine' => "CPM",
|
42
|
+
'Keywords' => "bigfoot",
|
43
|
+
'CPM' => "10.00",
|
44
|
+
'AdTypes' => [0,1,2,3,4]
|
45
|
+
}
|
46
|
+
channel.update(updated_channel).response.code.should_not == 200
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Channel API" do
|
4
|
+
|
5
|
+
$channel_url = 'http://www.adzerk.com'
|
6
|
+
@@channel = $adzerk::Channel.new
|
7
|
+
|
8
|
+
it "should create a new channel" do
|
9
|
+
$channel_title = 'Test Channel ' + rand(1000000).to_s
|
10
|
+
$channel_commission = '0'
|
11
|
+
$channel_engine = 'CPM'
|
12
|
+
$channel_keywords = 'test, another test'
|
13
|
+
$channel_CPM = '10.00'
|
14
|
+
$channel_AdTypes = [0,1,2,3,4]
|
15
|
+
|
16
|
+
new_channel = {
|
17
|
+
'Title' => $channel_title,
|
18
|
+
'Commission' => $channel_commission,
|
19
|
+
'Engine' => $channel_engine,
|
20
|
+
'Keywords' => $channel_keywords,
|
21
|
+
'CPM' => $channel_CPM,
|
22
|
+
'AdTypes' => $channel_AdTypes
|
23
|
+
}
|
24
|
+
|
25
|
+
response = @@channel.create(new_channel)
|
26
|
+
$channel_id = JSON.parse(response.body)["Id"].to_s
|
27
|
+
$channel_title.should == JSON.parse(response.body)["Title"]
|
28
|
+
$channel_commission.to_f.should == JSON.parse(response.body)["Commission"]
|
29
|
+
$channel_engine.should == JSON.parse(response.body)["Engine"]
|
30
|
+
$channel_keywords.should == JSON.parse(response.body)["Keywords"]
|
31
|
+
$channel_CPM.to_f.should == JSON.parse(response.body)["CPM"]
|
32
|
+
$channel_AdTypes.should == JSON.parse(response.body)["AdTypes"]
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should list a specific channel" do
|
36
|
+
response = @@channel.get($channel_id)
|
37
|
+
response.body.should == '{"Id":' + $channel_id + ',"Title":"' + $channel_title + '","Commission":' + $channel_commission.to_s + ',"Engine":"' + $channel_engine + '","Keywords":"' + $channel_keywords + '","CPM":' + $channel_CPM + ',"AdTypes":' + $channel_AdTypes.to_json + ',"IsDeleted":false}'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should update a channel" do
|
41
|
+
$u_channel_title = 'Test Channel ' + rand(1000000).to_s + 'test'
|
42
|
+
$u_channel_commission = '1'
|
43
|
+
$u_channel_engine = 'CPI'
|
44
|
+
$u_channel_keywords = 'another test'
|
45
|
+
$u_channel_CPM = '0'
|
46
|
+
$u_channel_AdTypes = [4,5,6,7,8]
|
47
|
+
|
48
|
+
updated_channel = {
|
49
|
+
'Id' => $channel_id,
|
50
|
+
'Title' => $u_channel_title,
|
51
|
+
'Commission' => $u_channel_commission,
|
52
|
+
'Engine' => $u_channel_engine,
|
53
|
+
'Keywords' => $u_channel_keywords,
|
54
|
+
'CPM' => $u_channel_CPM,
|
55
|
+
'AdTypes' => $u_channel_AdTypes
|
56
|
+
}
|
57
|
+
|
58
|
+
response = @@channel.update(updated_channel)
|
59
|
+
$channel_id = JSON.parse(response.body)["Id"].to_s
|
60
|
+
$u_channel_title.should == JSON.parse(response.body)["Title"]
|
61
|
+
$u_channel_commission.to_f.should == JSON.parse(response.body)["Commission"]
|
62
|
+
$u_channel_engine.should == JSON.parse(response.body)["Engine"]
|
63
|
+
$u_channel_keywords.should == JSON.parse(response.body)["Keywords"]
|
64
|
+
$u_channel_CPM.to_f.should == JSON.parse(response.body)["CPM"]
|
65
|
+
$u_channel_AdTypes.should == JSON.parse(response.body)["AdTypes"]
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should list all channels" do
|
69
|
+
result = @@channel.list()
|
70
|
+
result.length.should > 0
|
71
|
+
result["Items"].last["Id"].to_s.should == $channel_id
|
72
|
+
result["Items"].last["Title"].should == $u_channel_title
|
73
|
+
result["Items"].last["Commission"].should == $u_channel_commission.to_f
|
74
|
+
result["Items"].last["Engine"].should == $u_channel_engine
|
75
|
+
result["Items"].last["Keywords"].should == $u_channel_keywords
|
76
|
+
result["Items"].last["CPM"].to_s.should == $u_channel_CPM.to_f.to_s
|
77
|
+
result["Items"].last["AdTypes"].should == $u_channel_AdTypes
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should delete a new channel" do
|
81
|
+
response = @@channel.delete($channel_id)
|
82
|
+
response.body.should == 'OK'
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should not list deleted channels" do
|
86
|
+
result = @@channel.list()
|
87
|
+
result["Items"].each do |r|
|
88
|
+
r["Id"].to_s.should_not == $channel_id
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should not get individual deleted channel" do
|
93
|
+
response = @@channel.get($channel_id)
|
94
|
+
response.body.should == '{"Id":0,"Commission":0,"CPM":0,"IsDeleted":false}'
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should not update deleted channels" do
|
98
|
+
updated_channel = {
|
99
|
+
'Id' => $channel_id,
|
100
|
+
'Title' => $u_channel_title + "test",
|
101
|
+
'Commission' => $u_channel_commission,
|
102
|
+
'Engine' => $u_channel_engine,
|
103
|
+
'Keywords' => $u_channel_keywords,
|
104
|
+
'CPM' => $u_channel_CPM,
|
105
|
+
'AdTypes' => $u_channel_AdTypes
|
106
|
+
}
|
107
|
+
response = @@channel.update(updated_channel)
|
108
|
+
response.body.should == '{"Id":0,"Commission":0,"CPM":0,"IsDeleted":false}'
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Creative API" do
|
4
|
+
|
5
|
+
$creative_url = 'http://www.adzerk.com'
|
6
|
+
@@creative = $adzerk::Creative.new
|
7
|
+
@@advertiser = $adzerk::Advertiser.new
|
8
|
+
|
9
|
+
before(:all) do
|
10
|
+
new_advertiser = {
|
11
|
+
'Title' => "Test"
|
12
|
+
}
|
13
|
+
response = @@advertiser.create(new_advertiser)
|
14
|
+
$brandId = JSON.parse(response.body)["Id"]
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should create a creative" do
|
18
|
+
$Title = 'Test creative ' + rand(1000000).to_s
|
19
|
+
$ImageName = ""
|
20
|
+
$Url = "http://adzerk.com"
|
21
|
+
$Body = "Test text"
|
22
|
+
$BrandId = $brandId
|
23
|
+
$AdTypeId = 18
|
24
|
+
$IsActive = true
|
25
|
+
$Alt = "test alt"
|
26
|
+
$IsDeleted = false
|
27
|
+
$IsSync = false
|
28
|
+
|
29
|
+
new_creative = {
|
30
|
+
'Title' => $Title,
|
31
|
+
'ImageName' => $ImageName,
|
32
|
+
'Url' => $Url,
|
33
|
+
'Body' => $Body,
|
34
|
+
'BrandId' => $BrandId,
|
35
|
+
'AdTypeId' => $AdTypeId,
|
36
|
+
'IsActive' => $IsActive,
|
37
|
+
'Alt' => $Alt,
|
38
|
+
'IsDeleted' => $IsDeleted,
|
39
|
+
'IsSync' => $IsSync
|
40
|
+
}
|
41
|
+
response = @@creative.create(new_creative, '250x250.gif')
|
42
|
+
|
43
|
+
$creative_id = JSON.parse(response)["Id"].to_s
|
44
|
+
JSON.parse(response.body)["Title"].should == $Title
|
45
|
+
JSON.parse(response.body)["Url"].should == $Url
|
46
|
+
JSON.parse(response.body)["Body"].should == $Body
|
47
|
+
JSON.parse(response.body)["BrandId"].should == $BrandId
|
48
|
+
JSON.parse(response.body)["AdTypeId"].should == $AdTypeId
|
49
|
+
JSON.parse(response.body)["IsActive"].should == $IsActive
|
50
|
+
JSON.parse(response.body)["Alt"].should == $Alt
|
51
|
+
JSON.parse(response.body)["IsDeleted"].should == $IsDeleted
|
52
|
+
JSON.parse(response.body)["IsSync"].should == $IsSync
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should get a specific creative" do
|
57
|
+
response = @@creative.get($creative_id)
|
58
|
+
JSON.parse(response.body)["Id"].to_s.should == $creative_id
|
59
|
+
JSON.parse(response.body)["Title"].should == $Title
|
60
|
+
JSON.parse(response.body)["Url"].should == $Url
|
61
|
+
JSON.parse(response.body)["Body"].should == $Body
|
62
|
+
JSON.parse(response.body)["BrandId"].should == $BrandId
|
63
|
+
JSON.parse(response.body)["AdTypeId"].should == $AdTypeId
|
64
|
+
JSON.parse(response.body)["IsActive"].should == $IsActive
|
65
|
+
JSON.parse(response.body)["Alt"].should == $Alt
|
66
|
+
JSON.parse(response.body)["IsDeleted"].should == $IsDeleted
|
67
|
+
JSON.parse(response.body)["IsSync"].should == $IsSync
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should update a specific creative" do
|
71
|
+
update_creative = {
|
72
|
+
'Id' => $creative_id.to_i,
|
73
|
+
'Title' => $Title,
|
74
|
+
'ImageName' => $ImageName,
|
75
|
+
'Url' => $Url,
|
76
|
+
'Body' => $Body,
|
77
|
+
'BrandId' => $BrandId,
|
78
|
+
'AdTypeId' => $AdTypeId,
|
79
|
+
'IsActive' => $IsActive,
|
80
|
+
'Alt' => $Alt,
|
81
|
+
'IsDeleted' => $IsDeleted,
|
82
|
+
'IsSync' => $IsSync
|
83
|
+
}
|
84
|
+
response = @@creative.update(update_creative)
|
85
|
+
# JSON.parse(response.body)["Id"].should == $creative_id
|
86
|
+
# JSON.parse(response.body)["Title"].should == $Title
|
87
|
+
# JSON.parse(response.body)["Url"].should == $Url
|
88
|
+
# JSON.parse(response.body)["Body"].should == $Body
|
89
|
+
# JSON.parse(response.body)["BrandId"].should == $BrandId
|
90
|
+
# JSON.parse(response.body)["AdTypeId"].should == $AdTypeId
|
91
|
+
# JSON.parse(response.body)["IsActive"].should == $IsActive
|
92
|
+
# JSON.parse(response.body)["Alt"].should == $Alt
|
93
|
+
# JSON.parse(response.body)["IsDeleted"].should == $IsDeleted
|
94
|
+
# JSON.parse(response.body)["IsSync"].should == $IsSync
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should list all creatives for an advertiser" do
|
98
|
+
response = @@creative.list($BrandId)
|
99
|
+
entry = response["Items"].last.to_json
|
100
|
+
JSON.parse(entry)["Id"].should == $creative_id.to_i
|
101
|
+
JSON.parse(entry)["Title"].should == $Title
|
102
|
+
JSON.parse(entry)["Url"].should == $Url
|
103
|
+
JSON.parse(entry)["Body"].should == $Body
|
104
|
+
JSON.parse(entry)["BrandId"].should == $BrandId
|
105
|
+
JSON.parse(entry)["AdTypeId"].should == $AdTypeId
|
106
|
+
JSON.parse(entry)["IsActive"].should == $IsActive
|
107
|
+
JSON.parse(entry)["Alt"].should == $Alt
|
108
|
+
JSON.parse(entry)["IsDeleted"].should == $IsDeleted
|
109
|
+
JSON.parse(entry)["IsSync"].should == $IsSync
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should delete the creatives after creating it" do
|
113
|
+
response = @@creative.delete($creative_id)
|
114
|
+
response.body.should == "OK"
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should not use a brandId it doesn't have access to when creating" do
|
118
|
+
new_creative = {
|
119
|
+
'Title' => $Title,
|
120
|
+
'ImageName' => $ImageName,
|
121
|
+
'Url' => $Url,
|
122
|
+
'Body' => $Body,
|
123
|
+
'BrandId' => 1,
|
124
|
+
'AdTypeId' => $AdTypeId,
|
125
|
+
'IsActive' => $IsActive,
|
126
|
+
'Alt' => $Alt,
|
127
|
+
'IsDeleted' => $IsDeleted,
|
128
|
+
'IsSync' => $IsSync
|
129
|
+
}
|
130
|
+
begin
|
131
|
+
response = @@creative.create(new_creative)
|
132
|
+
rescue Exception => e
|
133
|
+
response = e
|
134
|
+
end
|
135
|
+
|
136
|
+
response.to_s.scan("302 Found").should_not == nil
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should not use a brandId it doesn't have access to when updating" do
|
140
|
+
new_creative = {
|
141
|
+
'Id' => $creative_id.to_i,
|
142
|
+
'Title' => $Title,
|
143
|
+
'ImageName' => $ImageName,
|
144
|
+
'Url' => $Url,
|
145
|
+
'Body' => $Body,
|
146
|
+
'BrandId' => 1,
|
147
|
+
'AdTypeId' => $AdTypeId,
|
148
|
+
'IsActive' => $IsActive,
|
149
|
+
'Alt' => $Alt,
|
150
|
+
'IsDeleted' => $IsDeleted,
|
151
|
+
'IsSync' => $IsSync
|
152
|
+
}
|
153
|
+
response = @@creative.update(new_creative)
|
154
|
+
true.should == !response.body.scan(/Object/).nil?
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should not retrieve a creative it doesn't have access to" do
|
158
|
+
response = @@creative.get("123")
|
159
|
+
true.should == !response.body.scan(/Object/).nil?
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should not delete a creative it doesn't have access to" do
|
163
|
+
response = @@creative.delete("123")
|
164
|
+
true.should == !response.body.scan(/Object/).nil?
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|