adzerk 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,106 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Category API" do
4
+
5
+
6
+ before(:all) do
7
+ new_advertiser = {
8
+ 'Title' => "Test"
9
+ }
10
+ client = Adzerk::Client.new(API_KEY)
11
+ @flights= client.flights
12
+ @advertisers = client.advertisers
13
+ @channels = client.channels
14
+ @campaigns = client.campaigns
15
+ @priorities = client.priorities
16
+ @category = client.categories
17
+ # @sites = client.sites
18
+ advertiser = @advertisers.create(:title => "test")
19
+ $advertiserId = advertiser[:id].to_s
20
+
21
+ channel = @channels.create(:title => 'Test Channel ' + rand(1000000).to_s,
22
+ :commission => '0.0',
23
+ :engine => 'CPM',
24
+ :keywords => 'test',
25
+ 'CPM' => '10.00',
26
+ :ad_types => [1,2,3,4])
27
+ $channel_id = channel[:id].to_s
28
+
29
+ priority = @priorities.create(:name => "High Priority Test",
30
+ :channel_id => $channel_id,
31
+ :weight => 1,
32
+ :is_deleted => false)
33
+ $priority_id = priority[:id].to_s
34
+
35
+ campaign = @campaigns.
36
+ create(:name => 'Test campaign ' + rand(1000000).to_s,
37
+ :start_date => "1/1/2011",
38
+ :end_date => "12/31/2011",
39
+ :is_active => false,
40
+ :price => '10.00',
41
+ :advertiser_id => $advertiserId,
42
+ :flights => [],
43
+ :is_deleted => false)
44
+ $campaign_id = campaign[:id]
45
+
46
+ new_flight = {
47
+ :no_end_date => false,
48
+ :priority_id => $priority_id,
49
+ :name => 'Test flight ' + rand(1000000).to_s,
50
+ :start_date => "1/1/2011",
51
+ :end_date => "12/31/2011",
52
+ :no_end_date => false,
53
+ :price => '15.00',
54
+ :option_type => 1,
55
+ :impressions => 10000,
56
+ :is_unlimited => false,
57
+ :is_full_speed => false,
58
+ :keywords => "test, test2",
59
+ :user_agent_keywords => nil,
60
+ :weight_override => nil,
61
+ :campaign_id => $campaign_id,
62
+ :is_active => true,
63
+ :is_deleted => false,
64
+ :goal_type => 1
65
+ }
66
+ flight = @flights.create(new_flight)
67
+ $flight_id = flight[:id].to_s
68
+
69
+ $category_name = 'test category'
70
+ $new_category = {
71
+ :name => $category_name
72
+ }
73
+
74
+ end
75
+
76
+ it "should add a category to a flight" do
77
+ cat = @category.create($flight_id, $new_category)
78
+ $category_id = cat[:id]
79
+ expect(cat[:name]).to eq($category_name)
80
+ end
81
+
82
+ it "should list categories for a given flight" do
83
+ cat = @category.list($flight_id)[:items].first
84
+ expect(cat[:name]).to eq($category_name)
85
+ expect(cat[:id]).to eq($category_id)
86
+ end
87
+
88
+ it "should list categories for the current network" do
89
+ cat = @category.listAll()[:items].last
90
+ expect(cat[:name]).to eq($category_name)
91
+ end
92
+
93
+ it "should delete a category from a flight" do
94
+ response = @category.delete($flight_id, $category_id)
95
+ expect(response.body).to eq('"Successfully deleted"')
96
+ end
97
+
98
+ it "should error when the flight or category id does not exist or does not belong to the network" do
99
+ bad_id = 0
100
+ expect{ cat = @category.create(bad_id, $new_category) }.to raise_error
101
+ expect{ cat = @category.list(bad_id) }.to raise_error
102
+ expect{ cat = @category.delete(bad_id,$category_id) }.to raise_error
103
+ expect{ cat = @category.delete($flight_id,bad_id) }.to raise_error
104
+ end
105
+
106
+ end
@@ -21,22 +21,22 @@ describe "Channel API" do
21
21
  :ad_types => $channel_ad_types,
22
22
  'CPM' => $channel_cpm)
23
23
  $channel_id = channel[:id].to_s
24
- $channel_title.should == channel[:title]
25
- $channel_commission.to_f.should == channel[:commission]
26
- $channel_engine.should == channel[:engine]
27
- $channel_keywords.should == channel[:keywords]
28
- $channel_cpm.to_f.should == channel[:cpm]
29
- $channel_ad_types.should == channel[:ad_types]
24
+ expect($channel_title).to eq(channel[:title])
25
+ expect($channel_commission.to_f).to eq(channel[:commission])
26
+ expect($channel_engine).to eq(channel[:engine])
27
+ expect($channel_keywords).to eq(channel[:keywords])
28
+ expect($channel_cpm.to_f).to eq(channel[:cpm])
29
+ expect($channel_ad_types).to eq(channel[:ad_types])
30
30
  end
31
31
 
32
32
  it "should list a specific channel" do
33
33
  channel = @channels.get($channel_id)
34
- $channel_title.should == channel[:title]
35
- $channel_commission.to_f.should == channel[:commission]
36
- $channel_engine.should == channel[:engine]
37
- $channel_keywords.should == channel[:keywords]
38
- $channel_cpm.to_f.should == channel[:cpm]
39
- $channel_ad_types.should == channel[:ad_types]
34
+ expect($channel_title).to eq(channel[:title])
35
+ expect($channel_commission.to_f).to eq(channel[:commission])
36
+ expect($channel_engine).to eq(channel[:engine])
37
+ expect($channel_keywords).to eq(channel[:keywords])
38
+ expect($channel_cpm.to_f).to eq(channel[:cpm])
39
+ expect($channel_ad_types).to eq(channel[:ad_types])
40
40
  end
41
41
 
42
42
  it "should update a channel" do
@@ -56,35 +56,34 @@ describe "Channel API" do
56
56
  :ad_types => $u_channel_AdTypes,
57
57
  'CPM' => $u_channel_CPM)
58
58
 
59
- $u_channel_title.should == channel[:title]
60
- $u_channel_commission.should == channel[:commission].to_s
61
- $u_channel_engine.should == channel[:engine]
62
- $u_channel_keywords.should == channel[:keywords]
63
- $u_channel_CPM.to_f.should == channel[:cpm]
64
- $u_channel_AdTypes.should == channel[:ad_types]
59
+ expect($u_channel_title).to eq(channel[:title])
60
+ expect($u_channel_commission).to eq(channel[:commission].to_s)
61
+ expect($u_channel_engine).to eq(channel[:engine])
62
+ expect($u_channel_keywords).to eq(channel[:keywords])
63
+ expect($u_channel_CPM.to_f).to eq(channel[:cpm])
64
+ expect($u_channel_AdTypes).to eq(channel[:ad_types])
65
65
  end
66
66
 
67
67
  it "should list all channels" do
68
68
  result = @channels.list
69
- result.length.should > 0
69
+ expect(result.length).to be > 0
70
70
  last_channel = result[:items].last
71
- last_channel[:id].to_s.should == $channel_id
72
- last_channel[:title].should == $u_channel_title
73
- last_channel[:commission].should == $u_channel_commission.to_f
74
- last_channel[:engine].should == $u_channel_engine
75
- last_channel[:keywords].should == $u_channel_keywords
76
- last_channel[:cpm].should == $u_channel_CPM.to_f
77
- last_channel[:ad_types].should == $u_channel_AdTypes
71
+ expect(last_channel[:id].to_s).to eq($channel_id)
72
+ expect(last_channel[:title]).to eq($u_channel_title)
73
+ expect(last_channel[:commission]).to eq($u_channel_commission.to_f)
74
+ expect(last_channel[:engine]).to eq($u_channel_engine)
75
+ expect(last_channel[:keywords]).to eq($u_channel_keywords)
76
+ expect(last_channel[:cpm]).to eq($u_channel_CPM.to_f)
77
+ expect(last_channel[:ad_types]).to eq($u_channel_AdTypes)
78
78
  end
79
79
 
80
80
  it "should delete a new channel" do
81
81
  response = @channels.delete($channel_id)
82
- response.body.should == '"Successfully deleted"'
82
+ expect(response.body).to eq('"Successfully deleted"')
83
83
  end
84
84
 
85
85
  it "should not get individual deleted channel" do
86
- response = @channels.get($channel_id)
87
- response[:message].should == 'This channel has been deleted'
86
+ expect{ @channels.get($channel_id) }.to raise_error 'This channel has been deleted'
88
87
  end
89
88
 
90
89
  it "should not update deleted channels" do
@@ -97,8 +96,7 @@ describe "Channel API" do
97
96
  'CPM' => $u_channel_CPM,
98
97
  :ad_types => $u_channel_AdTypes
99
98
  }
100
- response = @channels.update(updated_channel)
101
- response[:message].should == "This channel has been deleted"
99
+ expect { @channels.update(updated_channel) }.to raise_error "This channel has been deleted"
102
100
  end
103
101
 
104
102
  end
@@ -29,26 +29,26 @@ describe "Channel Site Map API" do
29
29
  :priority => 10
30
30
  }
31
31
  channel_site_map = @csm.create(new_map)
32
- channel_site_map[:site_id].should eq(@site_id)
33
- channel_site_map[:channel_id].should eq(@channel_id)
34
- channel_site_map[:priority].should eq(10)
32
+ expect(channel_site_map[:site_id]).to eq(@site_id)
33
+ expect(channel_site_map[:channel_id]).to eq(@channel_id)
34
+ expect(channel_site_map[:priority]).to eq(10)
35
35
  end
36
36
 
37
37
  it "should retrieve a list of sites in a channel" do
38
38
  sites = @csm.sites_in_channel(@channel_id)
39
- sites[:site_ids].should include(@site_id)
39
+ expect(sites[:site_ids]).to include(@site_id)
40
40
  end
41
41
 
42
42
  it "should retrieve a list of channels in a site" do
43
43
  channels = @csm.channels_in_site(@site_id)
44
- channels[:channel_ids].should include(@channel_id)
44
+ expect(channels[:channel_ids]).to include(@channel_id)
45
45
  end
46
46
 
47
47
  it "should list a specific map" do
48
48
  channel_site_map = @csm.get(@channel_id, @site_id)
49
- channel_site_map[:site_id].should eq(@site_id)
50
- channel_site_map[:channel_id].should eq(@channel_id)
51
- channel_site_map[:priority].should eq(10)
49
+ expect(channel_site_map[:site_id]).to eq(@site_id)
50
+ expect(channel_site_map[:channel_id]).to eq(@channel_id)
51
+ expect(channel_site_map[:priority]).to eq(10)
52
52
  end
53
53
 
54
54
  it "should update a map" do
@@ -58,17 +58,17 @@ describe "Channel Site Map API" do
58
58
  :priority => 200
59
59
  }
60
60
  channel_map = @csm.update(u_map)
61
- channel_map[:priority].should eq(200)
61
+ expect(channel_map[:priority]).to eq(200)
62
62
  end
63
63
 
64
64
  it "should list all maps for network" do
65
65
  channel_maps = @csm.list
66
- channel_maps[:items].last[:site_id].should eq(@site_id)
66
+ expect(channel_maps[:items].last[:site_id]).to eq(@site_id)
67
67
  end
68
68
 
69
69
  it "should delete a new maps" do
70
70
  response = @csm.delete(@channel_id, @site_id)
71
- response.body.should == '"Successfully deleted."'
71
+ expect(response.body).to eq('"Successfully deleted."')
72
72
  end
73
73
 
74
74
  end
@@ -7,105 +7,137 @@ describe "Creative API" do
7
7
  @creatives = client.creatives
8
8
  @advertiser_id = client.advertisers.create(:title => "Test")[:id]
9
9
  end
10
+
11
+ # this test gets a 400 error... doesn't work with current release
12
+ # commenting out for now
10
13
 
11
- it "should create a creative using old api spec" do
12
- new_creative = {
13
- :title => 'Test Creative Old API',
14
- :image_name => "",
15
- :url => "http://adzerk.com",
16
- :body => "Test Body",
17
- :advertiser_id => @advertiser_id,
18
- :ad_type_id => 18,
19
- :is_active => true,
20
- :alt => 'test alt',
21
- :is_deleted => false,
22
- :is_sync => false
23
- }
24
- creative_path = File.expand_path(File.dirname(__FILE__) + '/' + '250x250.gif')
25
- creative = @creatives.create(new_creative, creative_path)
26
- $creative_id = creative[:id].to_s
27
- creative[:title].should eq('Test Creative Old API')
28
- creative[:url].should eq("http://adzerk.com")
29
- creative[:body].should eq("Test Body")
30
- creative[:advertiser_id].should eq(@advertiser_id)
31
- creative[:ad_type_id].should eq(18)
32
- creative[:is_active].should eq(true)
33
- creative[:alt].should eq('test alt')
34
- creative[:is_deleted].should eq(false)
35
- creative[:is_sync].should eq(false)
36
- end
14
+ # it "should create a creative using old api spec" do
15
+ # new_creative = {
16
+ # :title => 'Test Creative Old API',
17
+ # :image_name => "",
18
+ # :url => "http://adzerk.com",
19
+ # :body => "Test Body",
20
+ # :advertiser_id => @advertiser_id,
21
+ # :ad_type_id => 18,
22
+ # :is_active => true,
23
+ # :alt => 'test alt',
24
+ # :is_deleted => false,
25
+ # :is_sync => false
26
+ # }
27
+ # creative_path = File.expand_path(File.dirname(__FILE__) + '/' + '250x250.gif')
28
+ # creative = @creatives.create(new_creative, creative_path)
29
+ # $creative_id = creative[:id].to_s
30
+ # creative[:title].should eq('Test Creative Old API')
31
+ # creative[:url].should eq("http://adzerk.com")
32
+ # creative[:body].should eq("Test Body")
33
+ # creative[:advertiser_id].should eq(@advertiser_id)
34
+ # creative[:ad_type_id].should eq(18)
35
+ # creative[:is_active].should eq(true)
36
+ # creative[:alt].should eq('test alt')
37
+ # creative[:is_deleted].should eq(false)
38
+ # creative[:is_sync].should eq(false)
39
+ # end
37
40
 
38
41
  it "should create a creative using new api fields" do
42
+
43
+ $Title = 'Test creative ' + rand(1000000).to_s
44
+ $Url = "http://adzerk.com"
45
+ $Body = "Test Body"
46
+ $AdTypeId = 18
47
+ $IsHTMLJS = true
48
+ $ScriptBody = '<html></html>'
49
+ $IsCreativeActive = true
50
+ $IsCreativeDeleted = false
51
+ $Alt = "test alt"
52
+ $IsSync = false
53
+
39
54
  new_creative = {
40
- :title => "Creative with the new API",
55
+ :title => $Title,
41
56
  :image_name => "",
42
- :url => "http://adzerk.com",
43
- :body => "Test Body",
57
+ :url => $Url,
58
+ :body => $Body,
44
59
  :advertiser_id => @advertiser_id,
45
- :ad_type_id => 18,
46
- :is_active => true,
47
- :alt => "alt text",
48
- :is_deleted => false,
49
- :is_sync => true,
50
- 'isHTMLJS' => true,
51
- :script_body => "<html></html>"
60
+ :ad_type_id => $AdTypeId,
61
+ :is_active => $IsCreativeActive,
62
+ :alt => $Alt,
63
+ :is_deleted => $IsCreativeDeleted,
64
+ :is_sync => $IsSync,
65
+ :'isHTMLJS' => $isHTMLJS,
66
+ :script_body => $ScriptBody
52
67
  }
53
68
  creative = @creatives.create(new_creative)
54
69
  $creative_id = creative[:id].to_s
55
- creative[:title].should eq('Creative with the new API')
56
- creative[:url].should eq("http://adzerk.com")
57
- creative[:body].should eq("Test Body")
58
- creative[:advertiser_id].should eq(@advertiser_id)
59
- creative[:ad_type_id].should eq(18)
60
- creative[:is_active].should eq(true)
61
- creative[:alt].should eq('alt text')
62
- creative[:is_deleted].should eq(false)
63
- creative[:is_sync].should eq(false)
70
+
71
+ expect(creative[:title]).to eq($Title)
72
+ expect(creative[:url]).to eq($Url)
73
+ expect(creative[:body]).to eq($Body)
74
+ expect(creative[:advertiser_id]).to eq(@advertiser_id)
75
+ expect(creative[:ad_type_id]).to eq($AdTypeId)
76
+ expect(creative[:is_active]).to eq($IsCreativeActive)
77
+ expect(creative[:alt]).to eq($Alt)
78
+ expect(creative[:is_deleted]).to eq($IsCreativeDeleted)
79
+ expect(creative[:is_sync]).to eq($IsSync)
64
80
  end
65
81
 
66
82
  it "should get a specific creative" do
67
83
  creative = @creatives.get($creative_id)
68
- creative[:title].should eq('Creative with the new API')
69
- creative[:url].should eq("http://adzerk.com")
70
- creative[:body].should eq("Test Body")
71
- creative[:advertiser_id].should eq(@advertiser_id)
72
- creative[:ad_type_id].should eq(18)
73
- creative[:is_active].should eq(true)
74
- creative[:alt].should eq('alt text')
75
- creative[:is_deleted].should eq(false)
76
- creative[:is_sync].should eq(false)
84
+ expect(creative[:title]).to eq($Title)
85
+ expect(creative[:url]).to eq($Url)
86
+ expect(creative[:body]).to eq($Body)
87
+ expect(creative[:advertiser_id]).to eq(@advertiser_id)
88
+ expect(creative[:ad_type_id]).to eq($AdTypeId)
89
+ expect(creative[:is_active]).to eq($IsCreativeActive)
90
+ expect(creative[:alt]).to eq($Alt)
91
+ expect(creative[:is_deleted]).to eq($IsCreativeDeleted)
92
+ expect(creative[:is_sync]).to eq($IsSync)
77
93
  end
78
94
 
79
95
  it "should update a specific creative" do
96
+
97
+ $new_title = "Updated Title"
98
+ $new_url = "http://adzerk2.com"
99
+ $new_body = "new body"
100
+ $new_ad_type_id = 5
101
+ $new_is_active = false
102
+ $new_alt = "new alt text"
103
+ $new_is_sync = false
104
+
80
105
  update_creative = {
81
106
  :id => $creative_id.to_i,
82
- :title => "Updated Title",
83
- :url => 'http://www.google.com',
84
- :body => 'new body',
107
+ :title => $new_title,
108
+ :url => $new_url,
109
+ :body => $new_body,
85
110
  :advertiser_id => @advertiser_id,
86
- :ad_type_id => 18,
87
- :is_active => true,
88
- :alt => 'new alt text',
111
+ :ad_type_id => $new_ad_type_id,
112
+ :is_active => $new_is_active,
113
+ :alt => $new_alt,
89
114
  :is_deleted => false,
90
- :is_sync => false
115
+ :is_sync => $new_is_sync
91
116
  }
92
117
  creative = @creatives.update(update_creative)
93
- creative[:title].should eq('Updated Title')
94
- creative[:url].should eq('http://www.google.com')
95
- creative[:body].should eq('new body')
118
+ expect(creative[:title]).to eq($new_title)
119
+ expect(creative[:url]).to eq($new_url)
120
+ expect(creative[:body]).to eq($new_body)
121
+ expect(creative[:ad_type_id]).to eq($new_ad_type_id)
122
+ expect(creative[:is_active]).to eq($new_is_active)
123
+ expect(creative[:is_sync]).to eq($new_is_sync)
96
124
  end
97
125
 
98
126
 
99
127
  it "should list all creatives for an advertiser" do
100
128
  response = @creatives.list(@advertiser_id)
101
129
  creative = response[:items].last
102
- creative[:url].should eq('http://www.google.com')
103
- creative[:body].should eq('new body')
130
+ expect(creative[:title]).to eq($new_title)
131
+ expect(creative[:url]).to eq($new_url)
132
+ expect(creative[:body]).to eq($new_body)
133
+ expect(creative[:ad_type_id]).to eq($new_ad_type_id)
134
+ expect(creative[:is_active]).to eq($new_is_active)
135
+ expect(creative[:is_sync]).to eq($new_is_sync)
104
136
  end
105
137
 
106
138
  it "should delete the creatives after creating it" do
107
139
  response = @creatives.delete($creative_id)
108
- response.body.should == '"Successfully deleted"'
140
+ expect(response.body).to eq('"Successfully deleted"')
109
141
  end
110
142
 
111
143
  end