adzerk 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,11 @@ require "rest_client"
3
3
  module Adzerk
4
4
  class Creative
5
5
 
6
- def create(data={}, imagepath='')
6
+ def create(data={}, imagepath='')
7
+ #uri = URI.parse($host + "creative/")
8
+ #data = { 'creative' => data.to_json }
9
+ #response = Adzerk.post_request(uri, data)
10
+
7
11
  response = RestClient.post $host + 'creative',
8
12
  {:creative => data.to_json},
9
13
  :X_Adzerk_ApiKey => Adzerk.api_key,
@@ -0,0 +1,35 @@
1
+ require 'rest_client'
2
+
3
+ module Adzerk
4
+ class Zone
5
+
6
+ def create(data={})
7
+ uri = URI.parse($host + 'zone')
8
+ data = { 'zone' => data.to_json }
9
+ Adzerk.post_request(uri, data)
10
+ end
11
+
12
+ def get(id)
13
+ uri = URI.parse($host + 'zone/' + id)
14
+ Adzerk.get_request(uri)
15
+ end
16
+
17
+ def list()
18
+ uri = URI.parse($host + 'zone')
19
+ response = Adzerk.get_request(uri)
20
+ JSON.parse(response.body)
21
+ end
22
+
23
+ def update(data={})
24
+ uri = URI.parse($host + 'zone/' + data["Id"].to_s)
25
+ data = { 'zone' => data.to_json }
26
+ Adzerk.put_request(uri, data)
27
+ end
28
+
29
+ def delete(id)
30
+ uri = URI.parse($host + 'zone/' + id + '/delete')
31
+ Adzerk.get_request(uri)
32
+ end
33
+
34
+ end
35
+ end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require './spec_helper'
2
2
 
3
3
  describe "Advertiser API" do
4
4
 
@@ -100,6 +100,7 @@ describe "Advertiser API" do
100
100
 
101
101
  it "should search advertiser based on name" do
102
102
  response = @@advertiser.search("test")
103
+
103
104
  JSON.parse(response.body)["TotalItems"].should > 0
104
105
  end
105
106
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require './spec_helper.rb'
2
2
 
3
3
  describe "Campaign API" do
4
4
 
@@ -138,8 +138,11 @@ describe "Campaign API" do
138
138
  end
139
139
 
140
140
  it "should list a specific campaign" do
141
- response = @@campaign.get($campaign_id)
142
- response.body.should == '{"Id":' + $campaign_id + ',"Name":"' + $campaign_Name + '","StartDate":"\/Date(1293840000000+0000)\/","EndDate":"\/Date(1325289600000+0000)\/","IsActive":false,"Price":' + $campaign_Price + ',"AdvertiserId":' + $campaign_AdvertiserId.to_s + ',"IsDeleted":false}'
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
143
146
  end
144
147
 
145
148
  it "should update a campaign" do
@@ -173,6 +176,38 @@ describe "Campaign API" do
173
176
  JSON.parse(response.body)["IsDeleted"].should == false
174
177
  $campaign_Flights.should == JSON.parse(response.body)["Flights"]
175
178
  end
179
+
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
198
+ }
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"]
203
+ # JSON.parse(response.body)["StartDate"].should == "/Date(1293858000000-0500)/"
204
+ # 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"]
210
+ end
176
211
 
177
212
  it "should list all campaigns" do
178
213
  result = @@campaign.list()
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require './spec_helper'
2
2
  require 'net/http'
3
3
  describe "Channel API security" do
4
4
 
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require './spec_helper'
2
2
 
3
3
  describe "Channel API" do
4
4
 
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require './spec_helper'
2
2
 
3
3
  describe "Creative API" do
4
4
 
@@ -14,18 +14,19 @@ describe "Creative API" do
14
14
  $advertiserId = JSON.parse(response.body)["Id"]
15
15
  end
16
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
- $AdvertiserId = $advertiserId
23
- $AdTypeId = 18
24
- $IsActive = true
25
- $Alt = "test alt"
26
- $IsDeleted = false
27
- $IsSync = false
28
-
17
+ it "should create a creative using old api spec" do
18
+ $Title = 'Test creative ' + rand(1000000).to_s
19
+ $ImageName = ""
20
+ $Url = "http://adzerk.com"
21
+ $Body = "Test text"
22
+ $AdvertiserId = $advertiserId
23
+ $AdTypeId = 18
24
+ $IsActive = true
25
+ $Alt = "test alt"
26
+ $IsDeleted = false
27
+ $IsSync = false
28
+ $IsHTMLJS = true
29
+ $ScriptBody = "<html>"
29
30
  new_creative = {
30
31
  'Title' => $Title,
31
32
  'ImageName' => $ImageName,
@@ -49,7 +50,36 @@ describe "Creative API" do
49
50
  JSON.parse(response.body)["Alt"].should == $Alt
50
51
  JSON.parse(response.body)["IsDeleted"].should == $IsDeleted
51
52
  JSON.parse(response.body)["IsSync"].should == $IsSync
52
-
53
+ end
54
+
55
+ it "should create a creative using new api fields" do
56
+ new_creative = {
57
+ 'Title' => $Title,
58
+ 'ImageName' => $ImageName,
59
+ 'Url' => $Url,
60
+ 'Body' => $Body,
61
+ 'AdvertiserId' => $AdvertiserId,
62
+ 'AdTypeId' => $AdTypeId,
63
+ 'IsActive' => $IsActive,
64
+ 'Alt' => $Alt,
65
+ 'IsDeleted' => $IsDeleted,
66
+ 'IsSync' => $IsSync,
67
+ 'IsHTMLJS' => $IsHTMLJS,
68
+ 'ScriptBody' => $ScriptBody
69
+ }
70
+ response = @@creative.create(new_creative, '250x250.gif')
71
+ $creative_id = JSON.parse(response)["Id"].to_s
72
+ JSON.parse(response.body)["Title"].should == $Title
73
+ JSON.parse(response.body)["Url"].should == $Url
74
+ JSON.parse(response.body)["Body"].should == $Body
75
+ JSON.parse(response.body)["AdvertiserId"].should == $AdvertiserId
76
+ JSON.parse(response.body)["AdTypeId"].should == $AdTypeId
77
+ JSON.parse(response.body)["IsActive"].should == $IsActive
78
+ JSON.parse(response.body)["Alt"].should == $Alt
79
+ JSON.parse(response.body)["IsDeleted"].should == $IsDeleted
80
+ JSON.parse(response.body)["IsSync"].should == $IsSync
81
+ JSON.parse(response.body)["IsHTMLJS"].should == $IsHTMLJS
82
+ JSON.parse(response.body)["ScriptBody"].should == $ScriptBody
53
83
  end
54
84
 
55
85
  it "should get a specific creative" do
@@ -93,6 +123,38 @@ describe "Creative API" do
93
123
  JSON.parse(response.body)["IsSync"].should == $IsSync
94
124
  end
95
125
 
126
+ it "should update a specific creative with html ad" do
127
+ update_creative = {
128
+ 'Id' => $creative_id.to_i,
129
+ 'Title' => $Title,
130
+ 'ImageName' => $ImageName,
131
+ 'Url' => $Url,
132
+ 'Body' => $Body,
133
+ 'AdvertiserId' => $AdvertiserId,
134
+ 'AdTypeId' => $AdTypeId,
135
+ 'IsActive' => $IsActive,
136
+ 'Alt' => $Alt,
137
+ 'IsDeleted' => $IsDeleted,
138
+ 'IsSync' => $IsSync,
139
+ 'IsHTMLJS' => true,
140
+ 'ScriptBody' => "<html></html>"
141
+ }
142
+ response = @@creative.update(update_creative)
143
+ JSON.parse(response.body)["Id"].should == $creative_id.to_i
144
+ JSON.parse(response.body)["Title"].should == $Title
145
+ JSON.parse(response.body)["Url"].should == $Url
146
+ JSON.parse(response.body)["Body"].should == $Body
147
+ JSON.parse(response.body)["AdvertiserId"].should == $AdvertiserId
148
+ JSON.parse(response.body)["AdTypeId"].should == $AdTypeId
149
+ JSON.parse(response.body)["IsActive"].should == $IsActive
150
+ JSON.parse(response.body)["Alt"].should == $Alt
151
+ JSON.parse(response.body)["IsDeleted"].should == $IsDeleted
152
+ JSON.parse(response.body)["IsSync"].should == $IsSync
153
+ JSON.parse(response.body)["IsHTMLJS"].should == true
154
+ JSON.parse(response.body)["ScriptBody"].should == "<html></html>"
155
+ end
156
+
157
+
96
158
  it "should list all creatives for an advertiser" do
97
159
  response = @@creative.list($AdvertiserId)
98
160
  entry = response["Items"].last.to_json
@@ -108,6 +170,25 @@ describe "Creative API" do
108
170
  JSON.parse(entry)["IsSync"].should == $IsSync
109
171
  end
110
172
 
173
+ #it "should update a creative with no adtype and preserve the adtype" do
174
+ #updated_creative = {
175
+ #'Id' => $creative_id,
176
+ #'Title' => 'test',
177
+ #'Body' => 'test',
178
+ #'AdvertiserId' => $advertiserId,
179
+ ##'AdTypeId' => 18,
180
+ #'IsActive' => true,
181
+ #'Alt' => "",
182
+ #'IsDeleted' => false,
183
+ #'IsSync' => false
184
+ #}
185
+ #response = @@creative.update(updated_creative)
186
+ #JSON.parse(response.body)["Title"].should == 'test'
187
+ #JSON.parse(response.body)["Body"].should == 'test'
188
+ #JSON.parse(response.body)["AdvertiserId"].should == $advertiserId
189
+ #JSON.parse(response.body)["AdTypeId"].should == $AdTypeId
190
+ #end
191
+
111
192
  it "should delete the creatives after creating it" do
112
193
  response = @@creative.delete($creative_id)
113
194
  response.body.should == "OK"
@@ -1,15 +1,17 @@
1
- require 'spec_helper'
1
+ require './spec_helper'
2
2
 
3
3
  describe "Creative Flight API" do
4
4
 
5
5
  $creative_url = 'http://www.adzerk.com'
6
6
  @@map = $adzerk::CreativeMap.new
7
+ @@creative = $adzerk::Creative.new
7
8
  @@advertiser = $adzerk::Advertiser.new
8
9
  @@channel = $adzerk::Channel.new
9
10
  @@campaign = $adzerk::Campaign.new
10
11
  @@site = $adzerk::Site.new
11
12
  @@flight = $adzerk::Flight.new
12
13
  @@priority = $adzerk::Priority.new
14
+ @@zone = $adzerk::Zone.new
13
15
 
14
16
  before(:all) do
15
17
  new_advertiser = {
@@ -79,6 +81,14 @@ describe "Creative Flight API" do
79
81
  }
80
82
  response = @@site.create(new_site)
81
83
  $siteId = JSON.parse(response.body)["Id"]
84
+
85
+ new_zone = {
86
+ 'Name' => 'Test Zone ' + rand(10000000).to_s,
87
+ 'SiteId' => $siteId,
88
+ }
89
+ response = @@zone.create(new_zone)
90
+ $zoneId = JSON.parse(response.body)["Id"]
91
+
82
92
  end
83
93
 
84
94
  it "should create a creative" do
@@ -91,16 +101,16 @@ describe "Creative Flight API" do
91
101
  $FlightId = $flightId
92
102
  $MapId = 0
93
103
  $AdTypeId = 18
94
- $ZoneId = 0
104
+ $ZoneId = $zoneId
95
105
  $SiteId = $siteId
96
106
  $SizeOverride = false
97
107
  $Iframe = false
98
108
  $PublisherAccountId = 372
99
- $ScriptBody = nil
109
+ $ScriptBody = '<html>'
100
110
  $Impressions = 100000
101
- $Percentage = 0
102
- $DistributionType = 0
103
- $AdFormatId = 0
111
+ $Percentage = 50
112
+ $DistributionType = 1
113
+ $IsHTMLJS = true
104
114
  $IsActive = true
105
115
  $Alt = "test alt"
106
116
  $IsDeleted = false
@@ -109,17 +119,14 @@ describe "Creative Flight API" do
109
119
  new_creative = {
110
120
  'CampaignId' => $CampaignId,
111
121
  'FlightId' => $FlightId,
112
- #'MapId' => $MapId,
113
- #'ZoneId' => $ZoneId,
114
122
  'SizeOverride' => $SizeOverride,
115
123
  'Iframe' => $Iframe,
116
124
  'PublisherAccountId' => $PublisherAccountId,
117
- 'ScriptBody' => $ScriptBody,
118
125
  'Impressions' => $Impressions,
119
126
  'Percentage' => $Percentage,
120
127
  'SiteId' => $SiteId,
121
- #'DistributionType' => $DistributionType,
122
- 'AdFormatId' => $AdFormatId,
128
+ 'ZoneId' => $ZoneId,
129
+ 'DistributionType' => $DistributionType,
123
130
  'IsActive' => $IsActive,
124
131
  'IsDeleted' => $IsDeleted,
125
132
  'Creative' => {
@@ -128,6 +135,8 @@ describe "Creative Flight API" do
128
135
  'Body' => $Body,
129
136
  'AdvertiserId' => $AdvertiserId,
130
137
  'AdTypeId' => $AdTypeId,
138
+ 'IsHTMLJS' => $IsHTMLJS,
139
+ 'ScriptBody' => $ScriptBody,
131
140
  'IsActive' => $IsActive,
132
141
  'Alt' => $Alt,
133
142
  'IsDeleted' => $IsDeleted,
@@ -136,51 +145,50 @@ describe "Creative Flight API" do
136
145
  }
137
146
  response = @@map.create(new_creative)
138
147
  Adzerk.uploadCreative(JSON.parse(response.body)["Creative"]["Id"].to_s, "250x250.gif")
139
- $creative_id = JSON.parse(response.body)["Id"].to_s
148
+ $map_id= JSON.parse(response.body)["Id"].to_s
140
149
  JSON.parse(response.body)["Creative"]["Title"].should == $Title
141
150
  JSON.parse(response.body)["Creative"]["Url"].should == $Url
142
151
  JSON.parse(response.body)["Creative"]["Body"].should == $Body
143
152
  JSON.parse(response.body)["Creative"]["AdvertiserId"].should == $AdvertiserId
144
153
  JSON.parse(response.body)["CampaignId"].should == $CampaignId
145
154
  JSON.parse(response.body)["FlightId"].should == $FlightId
146
- #JSON.parse(response.body)["MapId"].should == $MapId
147
155
  JSON.parse(response.body)["Creative"]["AdTypeId"].should == $AdTypeId
148
- #JSON.parse(response.body)["ZoneId"].should == $ZoneId
149
- JSON.parse(response.body)["SiteId"].should == $SiteId
156
+ JSON.parse(response.body)["ZoneId"].should == $zoneId
157
+ JSON.parse(response.body)["SiteId"].should == $siteId
150
158
  JSON.parse(response.body)["SizeOverride"].should == $SizeOverride
151
159
  JSON.parse(response.body)["PublisherAccountId"].should == $PublisherAccountId
152
- JSON.parse(response.body)["ScriptBody"].should == $ScriptBody
153
160
  JSON.parse(response.body)["Impressions"].should == $Impressions
154
161
  JSON.parse(response.body)["Percentage"].should == $Percentage
155
- #JSON.parse(response.body)["DistributionType"].should == $DistributionType
156
- JSON.parse(response.body)["AdFormatId"].should == $AdFormatId
162
+ JSON.parse(response.body)["DistributionType"].should == $DistributionType
163
+ JSON.parse(response.body)["Creative"]["IsHTMLJS"].should == $IsHTMLJS
164
+ JSON.parse(response.body)["Creative"]["ScriptBody"].should == $ScriptBody
157
165
  JSON.parse(response.body)["Creative"]["IsActive"].should == $IsActive
158
166
  JSON.parse(response.body)["Creative"]["Alt"].should == $Alt
159
167
  JSON.parse(response.body)["IsDeleted"].should == $IsDeleted
160
168
  JSON.parse(response.body)["Creative"]["IsSync"].should == $IsSync
169
+ $creative_id_id = JSON.parse(response.body)["Creative"]["Id"]
161
170
  end
162
171
 
163
172
  it "should list all creatives for a flight" do
164
173
  response = @@map.list($FlightId)
165
174
  entry = response["Items"].last.to_json
166
- $creative_id = JSON.parse(entry)["Id"]
175
+ $map_id = JSON.parse(entry)["Id"]
167
176
  JSON.parse(entry)["Creative"]["Title"].should == $Title
168
177
  JSON.parse(entry)["Creative"]["Url"].should == $Url
169
178
  JSON.parse(entry)["Creative"]["Body"].should == $Body
170
179
  JSON.parse(entry)["Creative"]["AdvertiserId"].should == $AdvertiserId
171
- #JSON.parse(entry)["CampaignId"].should == $CampaignId
172
- #JSON.parse(entry)["FlightId"].should == $FlightId
173
- #JSON.parse(entry)["MapId"].should == $MapId
180
+ JSON.parse(entry)["CampaignId"].should == $CampaignId
181
+ JSON.parse(entry)["FlightId"].should == $FlightId
174
182
  JSON.parse(entry)["Creative"]["AdTypeId"].should == $AdTypeId
175
- #JSON.parse(entry)["ZoneId"].should == $ZoneId
183
+ JSON.parse(entry)["ZoneId"].should == $ZoneId
176
184
  JSON.parse(entry)["SiteId"].should == $SiteId
177
- JSON.parse(entry)["SizeOverride"].should == $SizeOverride
185
+ #JSON.parse(entry)["SizeOverride"].should == $SizeOverride
178
186
  #JSON.parse(entry)["PublisherAccountId"].should == $PublisherAccountId
179
- JSON.parse(entry)["ScriptBody"].should == $ScriptBody
180
187
  #JSON.parse(entry)["Impressions"].should == $Impressions
181
188
  JSON.parse(entry)["Percentage"].should == $Percentage
182
- #JSON.parse(entry)["DistributionType"].should == $DistributionType
183
- #JSON.parse(entry)["AdFormatId"].should == $AdFormatId
189
+ JSON.parse(entry)["DistributionType"].should == $DistributionType
190
+ JSON.parse(entry)["Creative"]["IsHTMLJS"].should == $IsHTMLJS
191
+ JSON.parse(entry)["Creative"]["ScriptBody"].should == $ScriptBody
184
192
  JSON.parse(entry)["Creative"]["IsActive"].should == $IsActive
185
193
  JSON.parse(entry)["Creative"]["Alt"].should == $Alt
186
194
  JSON.parse(entry)["IsDeleted"].should == $IsDeleted
@@ -188,25 +196,24 @@ describe "Creative Flight API" do
188
196
  end
189
197
 
190
198
  it "should get a specific creative" do
191
- response = @@map.get($creative_id, $flightId)
192
- JSON.parse(response.body)["Id"].should == $creative_id
199
+ response = @@map.get($map_id, $flightId)
200
+ JSON.parse(response.body)["Id"].should == $map_id
193
201
  JSON.parse(response.body)["Creative"]["Title"].should == $Title
194
202
  JSON.parse(response.body)["Creative"]["Url"].should == $Url
195
203
  JSON.parse(response.body)["Creative"]["Body"].should == $Body
196
204
  JSON.parse(response.body)["Creative"]["AdvertiserId"].should == $AdvertiserId
197
- #JSON.parse(response.body)["CampaignId"].should == $CampaignId
198
- #JSON.parse(response.body)["FlightId"].should == $FlightId
199
- #JSON.parse(response.body)["MapId"].should == $MapId
205
+ JSON.parse(response.body)["CampaignId"].should == $CampaignId
206
+ JSON.parse(response.body)["FlightId"].should == $FlightId
200
207
  JSON.parse(response.body)["Creative"]["AdTypeId"].should == $AdTypeId
201
- #JSON.parse(response.body)["ZoneId"].should == $ZoneId
208
+ JSON.parse(response.body)["ZoneId"].should == $ZoneId
202
209
  JSON.parse(response.body)["SiteId"].should == $SiteId
203
- JSON.parse(response.body)["SizeOverride"].should == $SizeOverride
210
+ #JSON.parse(response.body)["SizeOverride"].should == $SizeOverride
204
211
  #JSON.parse(response.body)["PublisherAccountId"].should == $PublisherAccountId
205
- JSON.parse(response.body)["ScriptBody"].should == $ScriptBody
206
212
  #JSON.parse(response.body)["Impressions"].should == $Impressions
213
+ JSON.parse(response.body)["Creative"]["IsHTMLJS"].should == $IsHTMLJS
214
+ JSON.parse(response.body)["Creative"]["ScriptBody"].should == $ScriptBody
207
215
  JSON.parse(response.body)["Percentage"].should == $Percentage
208
- #JSON.parse(response.body)["DistributionType"].should == $DistributionType
209
- #JSON.parse(response.body)["AdFormatId"].should == $AdFormatId
216
+ JSON.parse(response.body)["DistributionType"].should == $DistributionType
210
217
  JSON.parse(response.body)["Creative"]["IsActive"].should == $IsActive
211
218
  JSON.parse(response.body)["Creative"]["Alt"].should == $Alt
212
219
  JSON.parse(response.body)["IsDeleted"].should == $IsDeleted
@@ -215,59 +222,71 @@ describe "Creative Flight API" do
215
222
  end
216
223
 
217
224
  it "should update a specific creative" do
218
- update_creative = {
219
- 'Id' => $creative_id.to_i,
220
- 'Title' => $Title,
221
- 'ImageName' => $ImageName,
222
- 'Url' => $Url,
223
- 'Body' => $Body,
224
- 'AdvertiserId' => $AdvertiserId,
225
+ updated_creative = {
226
+ 'Id' => $map_id,
225
227
  'CampaignId' => $CampaignId,
226
228
  'FlightId' => $FlightId,
227
- 'MapId' => $MapId,
228
- 'AdTypeId' => $AdTypeId,
229
- 'ZoneId' => $ZoneId,
229
+ 'SizeOverride' => $SizeOverride,
230
+ 'Iframe' => $Iframe,
231
+ 'PublisherAccountId' => $PublisherAccountId,
232
+ 'Impressions' => $Impressions + 100,
233
+ 'Percentage' => $Percentage,
230
234
  'SiteId' => $SiteId,
235
+ 'ZoneId' => $zoneId,
236
+ 'IsActive' => $IsActive,
237
+ 'IsDeleted' => $IsDeleted,
238
+ 'Creative' => {
239
+ 'Id' => @@creativeId
240
+ }
241
+ }
242
+ response = @@map.create(updated_creative)
243
+ Adzerk.uploadCreative(JSON.parse(response.body)["Creative"]["Id"].to_s, "250x250.gif")
244
+ JSON.parse(response.body)["Creative"]["Title"].should == $Title
245
+ JSON.parse(response.body)["Creative"]["Url"].should == $Url
246
+ JSON.parse(response.body)["Creative"]["Body"].should == $Body
247
+ JSON.parse(response.body)["Creative"]["AdvertiserId"].should == $AdvertiserId
248
+ JSON.parse(response.body)["CampaignId"].should == $CampaignId
249
+ JSON.parse(response.body)["FlightId"].should == $FlightId
250
+ JSON.parse(response.body)["Creative"]["AdTypeId"].should == $AdTypeId
251
+ JSON.parse(response.body)["ZoneId"].should == $zoneId
252
+ JSON.parse(response.body)["SiteId"].should == $SiteId
253
+ JSON.parse(response.body)["SizeOverride"].should == $SizeOverride
254
+ JSON.parse(response.body)["PublisherAccountId"].should == $PublisherAccountId
255
+ JSON.parse(response.body)["Impressions"].should == $Impressions + 100
256
+ JSON.parse(response.body)["Percentage"].should == $Percentage
257
+ JSON.parse(response.body)["Creative"]["IsActive"].should == $IsActive
258
+ JSON.parse(response.body)["Creative"]["Alt"].should == $Alt
259
+ JSON.parse(response.body)["IsDeleted"].should == $IsDeleted
260
+ JSON.parse(response.body)["Creative"]["IsSync"].should == $IsSync
261
+ end
262
+
263
+ it "should update the scriptBody tag on a nested creative" do
264
+ updated_creative = {
265
+ 'Id' => $map_id,
266
+ 'CampaignId' => $CampaignId,
267
+ 'FlightId' => $FlightId,
268
+ 'ZoneId' => $ZoneId,
231
269
  'SizeOverride' => $SizeOverride,
232
270
  'Iframe' => $Iframe,
233
271
  'PublisherAccountId' => $PublisherAccountId,
234
- 'ScriptBody' => $ScriptBody,
235
272
  'Impressions' => $Impressions,
236
273
  'Percentage' => $Percentage,
237
- 'DistributionType' => $DistributionType,
238
- 'AdFormatId' => $AdFormatId,
274
+ 'SiteId' => $SiteId,
239
275
  'IsActive' => $IsActive,
240
- 'Alt' => $Alt,
241
- 'IsDeleted' => $IsDeleted,
242
- 'IsSync' => $IsSync
276
+ 'IsDeleted' => nil,
277
+ 'Creative' => {
278
+ 'Id' => @@creativeId,
279
+ 'IsHTMLJS' => true,
280
+ 'ScriptBody' => '<html></html>',
281
+ 'Title' => 'test'
282
+ }
243
283
  }
244
- response = @@map.update(update_creative)
245
- #JSON.parse(response.body)["Id"].should == $creative_id
246
- #JSON.parse(response.body)["Creative"]["Title"].should == $Title
247
- #JSON.parse(response.body)["Creative"]["Url"].should == $Url
248
- #JSON.parse(response.body)["Creative"]["Body"].should == $Body
249
- #JSON.parse(response.body)["Creative"]["AdvertiserId"].should == $AdvertiserId
250
- #JSON.parse(response.body)["CampaignId"].should == $CampaignId
251
- #JSON.parse(response.body)["FlightId"].should == $FlightId
252
- #JSON.parse(response.body)["MapId"].should == $MapId
253
- #JSON.parse(response.body)["Creative"]["AdTypeId"].should == $AdTypeId
254
- #JSON.parse(response.body)["ZoneId"].should == $ZoneId
255
- #JSON.parse(response.body)["SiteId"].should == $SiteId
256
- #JSON.parse(response.body)["SizeOverride"].should == $SizeOverride
257
- #JSON.parse(response.body)["PublisherAccountId"].should == $PublisherAccountId
258
- #JSON.parse(response.body)["ScriptBody"].should == $ScriptBody
259
- #JSON.parse(response.body)["Impressions"].should == $Impressions
260
- #JSON.parse(response.body)["Percentage"].should == $Percentage
261
- #JSON.parse(response.body)["DistributionType"].should == $DistributionType
262
- #JSON.parse(response.body)["AdFormatId"].should == $AdFormatId
263
- #JSON.parse(response.body)["Creative"]["IsActive"].should == $IsActive
264
- #JSON.parse(response.body)["Creative"]["Alt"].should == $Alt
265
- #JSON.parse(response.body)["IsDeleted"].should == $IsDeleted
266
- #JSON.parse(response.body)["Creative"]["IsSync"].should == $IsSync
284
+ response = @@map.update(updated_creative)
285
+ response.body.scan(/Exception/).should == []
267
286
  end
268
287
 
269
288
  it "should delete the creatives after creating it" do
270
- response = @@map.delete($creative_id, $FlightId)
289
+ response = @@map.delete($map_id, $FlightId)
271
290
  response.body.should == "OK"
272
291
  end
273
292
 
@@ -278,16 +297,14 @@ describe "Creative Flight API" do
278
297
  'SizeOverride' => $SizeOverride,
279
298
  'Iframe' => $Iframe,
280
299
  'PublisherAccountId' => $PublisherAccountId,
281
- 'ScriptBody' => $ScriptBody,
282
300
  'Impressions' => $Impressions,
283
301
  'SiteId' => $SiteId,
284
302
  'Percentage' => $Percentage,
285
- 'AdFormatId' => $AdFormatId,
286
303
  'IsActive' => $IsActive,
287
304
  'IsDeleted' => $IsDeleted
288
305
  }
289
306
  response = @@map.create(map)
290
- true.should == !response.body.scan(/Exception/).empty?
307
+ response.body.scan(/This campaign is not part/).should_not == []
291
308
  end
292
309
 
293
310
  it "should not create a map when flightId is forbidden" do
@@ -297,16 +314,14 @@ describe "Creative Flight API" do
297
314
  'SizeOverride' => $SizeOverride,
298
315
  'Iframe' => $Iframe,
299
316
  'PublisherAccountId' => $PublisherAccountId,
300
- 'ScriptBody' => $ScriptBody,
301
317
  'Impressions' => $Impressions,
302
318
  'SiteId' => $SiteId,
303
319
  'Percentage' => $Percentage,
304
- 'AdFormatId' => $AdFormatId,
305
320
  'IsActive' => $IsActive,
306
321
  'IsDeleted' => $IsDeleted
307
322
  }
308
323
  response = @@map.create(map)
309
- true.should == !response.body.scan(/Exception/).empty?
324
+ response.body.scan(/This flight is not part/).should_not == []
310
325
  end
311
326
 
312
327
  it "should create a map when there is no creative object, just id" do
@@ -316,11 +331,9 @@ describe "Creative Flight API" do
316
331
  'SizeOverride' => $SizeOverride,
317
332
  'Iframe' => $Iframe,
318
333
  'PublisherAccountId' => $PublisherAccountId,
319
- 'ScriptBody' => $ScriptBody,
320
334
  'Impressions' => $Impressions,
321
335
  'SiteId' => $SiteId,
322
336
  'Percentage' => $Percentage,
323
- 'AdFormatId' => $AdFormatId,
324
337
  'IsActive' => $IsActive,
325
338
  'IsDeleted' => $IsDeleted,
326
339
  'Creative' => {
@@ -328,7 +341,7 @@ describe "Creative Flight API" do
328
341
  }
329
342
  }
330
343
  response = @@map.create(map)
331
- false.should == !response.body.scan(/Exception/).empty?
344
+ response.body.scan(/Exception/).should == []
332
345
  end
333
346
 
334
347
  it "should not create a map when there is no creative object, just id that belongs to a different advertiser" do
@@ -338,11 +351,9 @@ describe "Creative Flight API" do
338
351
  'SizeOverride' => $SizeOverride,
339
352
  'Iframe' => $Iframe,
340
353
  'PublisherAccountId' => $PublisherAccountId,
341
- 'ScriptBody' => $ScriptBody,
342
354
  'Impressions' => $Impressions,
343
355
  'SiteId' => $SiteId,
344
356
  'Percentage' => $Percentage,
345
- 'AdFormatId' => $AdFormatId,
346
357
  'IsActive' => $IsActive,
347
358
  'IsDeleted' => $IsDeleted,
348
359
  'Creative' => {
@@ -350,8 +361,77 @@ describe "Creative Flight API" do
350
361
  }
351
362
  }
352
363
  response = @@map.create(map)
353
- true.should == !response.body.scan(/Exception/).empty?
364
+ response.body.scan(/That creative belongs to an advertiser/).should_not == []
354
365
  end
355
366
 
367
+ it "should create a map with and invalid siteId" do
368
+ new_creative = {
369
+ 'CampaignId' => $CampaignId,
370
+ 'FlightId' => $FlightId,
371
+ 'ZoneId' => $ZoneId,
372
+ 'SizeOverride' => $SizeOverride,
373
+ 'Iframe' => $Iframe,
374
+ 'PublisherAccountId' => $PublisherAccountId,
375
+ 'Impressions' => $Impressions,
376
+ 'Percentage' => $Percentage,
377
+ 'SiteId' => 0,
378
+ 'IsActive' => $IsActive,
379
+ 'IsDeleted' => $IsDeleted,
380
+ 'Creative' => {
381
+ 'Title' => $Title,
382
+ 'Url' => $Url,
383
+ 'Body' => $Body,
384
+ 'AdvertiserId' => $AdvertiserId,
385
+ 'AdTypeId' => $AdTypeId,
386
+ 'IsActive' => $IsActive,
387
+ 'Alt' => $Alt,
388
+ 'IsDeleted' => $IsDeleted,
389
+ 'IsSync' => $IsSync
390
+ }
391
+ }
392
+ response = @@map.create(new_creative)
393
+ response.body.scan(/This site does not belong to your network/).should_not == []
394
+ end
395
+
396
+ it "should test if IsHTMLJS is getting written over" do
397
+ creative = {
398
+ 'Title' => 'Test Creative ' + rand(1000).to_s,
399
+ 'Url' => 'http://adzerk.com/',
400
+ 'Body' => 'test',
401
+ 'AdvertiserId' => $advertiserId,
402
+ 'AdTypeId' => 18,
403
+ 'IsHTMLJS' => true,
404
+ 'ScriptBody' => '<html>test</html>',
405
+ 'IsActive' => true,
406
+ 'Alt' => 'test',
407
+ 'IsDeleted' => false,
408
+ 'IsSync' => false
409
+ }
410
+ response = @@creative.create(creative, '250x250.gif')
411
+ creativeId = JSON.parse(response.body)["Id"]
412
+ JSON.parse(response.body)["IsHTMLJS"].should == true
413
+ JSON.parse(response.body)["ScriptBody"].should == '<html>test</html>'
414
+
415
+ map = {
416
+ 'CampaignId' => $campaignId,
417
+ 'FlightId' => $flightId,
418
+ 'ZoneId' => $zoneId,
419
+ 'SizeOverride' => $SizeOverride,
420
+ 'Iframe' => $Iframe,
421
+ 'PublisherAccountId' => $PublisherAccountId,
422
+ 'Impressions' => $Impressions,
423
+ 'Percentage' => $Percentage,
424
+ 'SiteId' => $siteId,
425
+ 'IsActive' => $IsActive,
426
+ 'IsDeleted' => $IsDeleted,
427
+ 'Creative' => {
428
+ 'Id' => creativeId
429
+ }
430
+ }
431
+ map_response = @@map.create(map)
432
+
433
+ JSON.parse(map_response.body)["Creative"]["IsHTMLJS"].should == true
434
+ JSON.parse(map_response.body)["Creative"]["ScriptBody"].should == '<html>test</html>'
435
+ end
356
436
 
357
437
  end