adzerk 0.2 → 0.3

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.
@@ -26,23 +26,23 @@ describe "Publisher API" do
26
26
  }
27
27
  publisher = @publishers.create(new_publisher)
28
28
  $publisher_id = publisher[:id]
29
- publisher[:first_name].should eq('John' + @rand)
30
- publisher[:last_name].should eq('Doe' + @rand)
31
- publisher[:company_name].should eq('Company' + @rand)
32
- publisher[:payment_option].should eq("1")
33
- publisher[:paypal_email].should eq("johndoe+" + @rand + "@johndoe.com")
34
- publisher[:address].should_not be_nil
29
+ expect(publisher[:first_name]).to eq('John' + @rand)
30
+ expect(publisher[:last_name]).to eq('Doe' + @rand)
31
+ expect(publisher[:company_name]).to eq('Company' + @rand)
32
+ expect(publisher[:payment_option]).to eq("1")
33
+ expect(publisher[:paypal_email]).to eq("johndoe+" + @rand + "@johndoe.com")
34
+ expect(publisher[:address]).not_to be_nil
35
35
  $address_id = publisher[:address][:id].to_s
36
36
  end
37
37
 
38
38
  it "should list a specific publisher" do
39
39
  publisher = @publishers.get($publisher_id)
40
- publisher[:first_name].should eq('John' + @rand)
41
- publisher[:last_name].should eq('Doe' + @rand)
42
- publisher[:company_name].should eq('Company' + @rand)
43
- publisher[:payment_option].should eq("PayPal")
44
- publisher[:paypal_email].should eq("johndoe+" + @rand + "@johndoe.com")
45
- publisher[:address].should_not be_nil
40
+ expect(publisher[:first_name]).to eq('John' + @rand)
41
+ expect(publisher[:last_name]).to eq('Doe' + @rand)
42
+ expect(publisher[:company_name]).to eq('Company' + @rand)
43
+ expect(publisher[:payment_option]).to eq("PayPal")
44
+ expect(publisher[:paypal_email]).to eq("johndoe+" + @rand + "@johndoe.com")
45
+ expect(publisher[:address]).not_to be_nil
46
46
  end
47
47
 
48
48
  it "should update a publisher" do
@@ -63,81 +63,19 @@ describe "Publisher API" do
63
63
  :paypal_email => "johndoe+" + @rand + "@johndoe.com"
64
64
  }
65
65
  publisher = @publishers.update(updated_publisher)
66
- publisher[:first_name].should eq("Rafael" + @rand)
66
+ expect(publisher[:first_name]).to eq("Rafael" + @rand)
67
67
  end
68
68
 
69
69
  it "should list all publishers" do
70
70
  publishers = @publishers.list
71
71
 
72
72
  publisher = publishers[:items].last
73
- publisher[:id].should eq($publisher_id)
73
+ expect(publisher[:id]).to eq($publisher_id)
74
74
  end
75
75
 
76
76
  it "should delete a new publisher" do
77
77
  response = @publishers.delete($publisher_id)
78
- response.body.should == '"Successfully deleted"'
79
- end
80
-
81
- it "should retrieve publisher earnings" do
82
- earnings = {
83
- 'Channel' => 'all'
84
- }
85
- #response = @@publisher.earnings earnings
86
- #response.first.length.should == 12
87
- end
88
-
89
- it "should retrieve publisher earnings for previous month" do
90
- earnings = {
91
- 'Channel' => 'all',
92
- 'Month' => 'previous'
93
- }
94
- #response = @@publisher.earnings earnings
95
- #response.first.length.should == 12
96
- end
97
-
98
- it "should retrieve publisher earnings for individual channel" do
99
- earnings = {
100
- 'Channel' => '1127'
101
- }
102
- #response = @@publisher.earnings earnings
103
- #response.first.length.should == 12
104
- end
105
-
106
- it "should retrieve publisher payments for a network" do
107
- payments = { }
108
- response = @publishers.payments payments
109
- #response.first.length.should == 5
110
- end
111
-
112
- it "should retrieve publisher payments for a network with start and end date" do
113
- payments = {
114
- 'StartDate' => '01/01/2000',
115
- 'EndDate' => '03/01/2000'
116
- }
117
- response = @publishers.payments payments
118
- response.first.should == nil
119
- end
120
-
121
- it "should retrieve publisher payments for a network with only start date" do
122
- payments = {
123
- 'StartDate' => '01/01/2012'
124
- }
125
- response = @publishers.payments payments
126
- #response.first.length.should == 5
127
- end
128
-
129
- it "should retrieve publisher payments for a site" do
130
- payments = {
131
- #'SiteId' => 6872
132
- }
133
- response = @publishers.payments payments
134
- end
135
-
136
- it "should retrieve publisher payments for a publisher" do
137
- payments = {
138
- #'PublisherAccountId' => 644
139
- }
140
- response = @publishers.payments payments
78
+ expect(response.body).to eq('"Successfully deleted"')
141
79
  end
142
80
 
143
81
  end
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
3
  @files = [
4
+ 'adtype_api_spec.rb',
4
5
  'advertiser_api_spec.rb',
5
6
  'campaign_api_spec.rb',
6
7
  'channel_api_spec.rb',
@@ -14,7 +15,10 @@ require 'rake'
14
15
  #'report_api_spec.rb',
15
16
  'security_api_spec.rb',
16
17
  'site_api_spec.rb',
17
- 'zone_api_spec.rb'
18
+ 'zone_api_spec.rb',
19
+ 'site_zone_targeting_api_spec.rb',
20
+ 'geo_targeting_api_spec.rb',
21
+ 'category_api_spec.rb'
18
22
  ]
19
23
 
20
24
  task :runall do
@@ -17,8 +17,8 @@ describe "Report API" do
17
17
  :parameters => []
18
18
  }
19
19
  report = @reports.create_report(new_report)
20
- report[:is_total].should eq(true)
21
- report[:grouping].should eq(["month"])
20
+ expect(report[:is_total]).to eq(true)
21
+ expect(report[:grouping]).to eq(["month"])
22
22
  end
23
23
 
24
24
  it "should pull a saved custom report" do
@@ -7,7 +7,7 @@ describe "Channel API security" do
7
7
  uri = URI.parse(ENV['ADZERK_API_HOST'] + 'channel/')
8
8
  http = Net::HTTP.new(uri.host, uri.port)
9
9
  request = Net::HTTP::Get.new(uri.request_uri)
10
- http.request(request).response.code.should_not == 200
10
+ expect(http.request(request).response.code).not_to eq(200)
11
11
  end
12
12
 
13
13
  it "should reject GET requests with null API keys" do
@@ -15,7 +15,7 @@ describe "Channel API security" do
15
15
  http = Net::HTTP.new(uri.host, uri.port)
16
16
  request = Net::HTTP::Get.new(uri.request_uri)
17
17
  request.add_field "X-Adzerk-ApiKey", ""
18
- http.request(request).response.code.should_not == 200
18
+ expect(http.request(request).response.code).not_to eq(200)
19
19
  end
20
20
 
21
21
  end
@@ -15,17 +15,17 @@ describe "Site API" do
15
15
  }
16
16
  site = @client.sites.create(:title => $site_title, :url => @site_url)
17
17
  $site_id = site[:id].to_s
18
- $site_title.should == site[:title]
19
- @site_url.should == site[:url]
18
+ expect($site_title).to eq(site[:title])
19
+ expect(@site_url).to eq(site[:url])
20
20
  $site_pub_id = site[:publisher_account_id].to_s
21
21
  end
22
22
 
23
23
  it "should list a specific site" do
24
24
  site = @client.sites.get($site_id)
25
- site[:id].should eq($site_id.to_i)
26
- site[:title].should eq($site_title)
27
- site[:url].should eq(@site_url)
28
- site[:publisher_account_id].should eq($site_pub_id.to_i)
25
+ expect(site[:id]).to eq($site_id.to_i)
26
+ expect(site[:title]).to eq($site_title)
27
+ expect(site[:url]).to eq(@site_url)
28
+ expect(site[:publisher_account_id]).to eq($site_pub_id.to_i)
29
29
  end
30
30
 
31
31
  it "should update a site" do
@@ -34,29 +34,29 @@ describe "Site API" do
34
34
  :title => $site_title + "test",
35
35
  :url => @site_url + "test")
36
36
  $site_id = site[:id].to_s
37
- ($site_title + "test").should == site[:title]
38
- (@site_url + "test").should == site[:url]
37
+ expect($site_title + "test").to eq(site[:title])
38
+ expect(@site_url + "test").to eq(site[:url])
39
39
  $site_pub_id = site[:publisher_account_id].to_s
40
40
  end
41
41
 
42
42
  it "should list all sites" do
43
43
  result = @client.sites.list
44
- result.length.should > 0
45
- result[:items].last[:id].to_s.should == $site_id
46
- result[:items].last[:title].should == $site_title + "test"
47
- result[:items].last[:url].should == @site_url + "test"
48
- result[:items].last[:publisher_account_id].to_s.should == $site_pub_id
44
+ expect(result.length).to be > 0
45
+ expect(result[:items].last[:id].to_s).to eq($site_id)
46
+ expect(result[:items].last[:title]).to eq($site_title + "test")
47
+ expect(result[:items].last[:url]).to eq(@site_url + "test")
48
+ expect(result[:items].last[:publisher_account_id].to_s).to eq($site_pub_id)
49
49
  end
50
50
 
51
51
  it "should delete a new site" do
52
52
  response = @client.sites.delete($site_id)
53
- response.body.should == '"Successfully deleted."'
53
+ expect(response.body).to eq('"Successfully deleted."')
54
54
  end
55
55
 
56
56
  it "should not list deleted sites" do
57
57
  result = @client.sites.list
58
58
  result[:items].each do |site|
59
- site[:id].to_s.should_not == $site_id
59
+ expect(site[:id].to_s).not_to eq($site_id)
60
60
  end
61
61
  end
62
62
 
@@ -0,0 +1,134 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "SiteZoneTargeting 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
+ @sitezonetargeting = client.sitezonetargetings
17
+ @sites = client.sites
18
+ @zones = client.zones
19
+ advertiser = @advertisers.create(:title => "test")
20
+ $advertiserId = advertiser[:id].to_s
21
+
22
+ channel = @channels.create(:title => 'Test Channel ' + rand(1000000).to_s,
23
+ :commission => '0.0',
24
+ :engine => 'CPM',
25
+ :keywords => 'test',
26
+ 'CPM' => '10.00',
27
+ :ad_types => [1,2,3,4])
28
+ $channel_id = channel[:id].to_s
29
+
30
+ priority = @priorities.create(:name => "High Priority Test",
31
+ :channel_id => $channel_id,
32
+ :weight => 1,
33
+ :is_deleted => false)
34
+ $priority_id = priority[:id].to_s
35
+
36
+ campaign = @campaigns.
37
+ create(:name => 'Test campaign ' + rand(1000000).to_s,
38
+ :start_date => "1/1/2011",
39
+ :end_date => "12/31/2011",
40
+ :is_active => false,
41
+ :price => '10.00',
42
+ :advertiser_id => $advertiserId,
43
+ :flights => [],
44
+ :is_deleted => false)
45
+ $campaign_id = campaign[:id]
46
+
47
+ new_flight = {
48
+ :no_end_date => false,
49
+ :priority_id => $priority_id,
50
+ :name => 'Test flight ' + rand(1000000).to_s,
51
+ :start_date => "1/1/2011",
52
+ :end_date => "12/31/2011",
53
+ :no_end_date => false,
54
+ :price => '15.00',
55
+ :option_type => 1,
56
+ :impressions => 10000,
57
+ :is_unlimited => false,
58
+ :is_full_speed => false,
59
+ :keywords => "test, test2",
60
+ :user_agent_keywords => nil,
61
+ :weight_override => nil,
62
+ :campaign_id => $campaign_id,
63
+ :is_active => true,
64
+ :is_deleted => false,
65
+ :goal_type => 1
66
+ }
67
+ flight = @flights.create(new_flight)
68
+ $flight_id = flight[:id].to_s
69
+
70
+ site_title = 'Test Site ' + rand(1000000).to_s
71
+ site = @sites.create(:title => site_title, :url => 'http://www.adzerk.com')
72
+ $site_id = site[:id].to_s
73
+
74
+ zone_name = 'Test Zone ' + rand(1000000).to_s
75
+ zone = @zones.create(:name => zone_name,
76
+ :site_id => $site_id,
77
+ :is_deleted => false)
78
+ $zone_id = zone[:id].to_s
79
+
80
+ end
81
+
82
+ it "should create a sitezone targeting" do
83
+ $sitezone_SiteId = $site_id;
84
+ $sitezone_ZoneId = $zone_id;
85
+ $sitezone_IsExclude = true;
86
+
87
+ new_sitezone = {
88
+ :site_id => $sitezone_SiteId,
89
+ :zone_id => $sitezone_ZoneId,
90
+ :is_exclude => true,
91
+ }
92
+
93
+ sitezone = @sitezonetargeting.create($flight_id, new_sitezone)
94
+ expect(sitezone[:site_id]).to eq($sitezone_SiteId.to_i)
95
+ expect(sitezone[:zone_id]).to eq($sitezone_ZoneId.to_i)
96
+ expect(sitezone[:is_exclude]).to eq(true)
97
+ $sitezone_id = sitezone[:id]
98
+
99
+ end
100
+
101
+ it "should retrieve a sitezone targeting" do
102
+ sitezone = @sitezonetargeting.get($flight_id,$sitezone_id)
103
+ expect(sitezone[:site_id]).to eq($sitezone_SiteId.to_i)
104
+ expect(sitezone[:zone_id]).to eq($sitezone_ZoneId.to_i)
105
+ expect(sitezone[:is_exclude]).to eq(true)
106
+ end
107
+
108
+ it "should update a sitezone targeting" do
109
+ data = {
110
+ :site_id => $sitezone_SiteId,
111
+ :zone_id => $sitezone_ZoneId,
112
+ :is_exclude => false,
113
+ }
114
+ sitezone = @sitezonetargeting.update($flight_id,$sitezone_id,data)
115
+ expect(sitezone[:is_exclude]).to eq(false)
116
+ end
117
+
118
+ it "should delete a sitezone targeting" do
119
+ sitezone = @sitezonetargeting.delete($flight_id,$sitezone_id)
120
+ expect(sitezone.body).to include("Successfully deleted")
121
+ end
122
+
123
+ it "should error when deleting a sitezone targeting that does not exist" do
124
+ expect{ geo = @sitezonetargeting.delete($flight_id,1) }.to raise_error
125
+ end
126
+
127
+ it "should check if a flight is not a part of your network" do
128
+ non_network_flight = 123;
129
+ expect{ @sitezonetargeting.delete(non_network_flight,1) }.to raise_error("Flight is not a part of your network")
130
+ expect{ @sitezonetargeting.get(non_network_flight,1) }.to raise_error("Flight is not a part of your network")
131
+ expect{ @sitezonetargeting.update(non_network_flight,1,{}) }.to raise_error("Flight is not a part of your network")
132
+ end
133
+
134
+ end
@@ -8,6 +8,6 @@ API_KEY = ENV['ADZERK_API_KEY'] || 'your_api_key'
8
8
  # $adzerk = Adzerk.new(API_KEY)
9
9
 
10
10
  RSpec.configure do |config|
11
- config.color_enabled = true
11
+ config.color = true
12
12
  end
13
13
 
@@ -0,0 +1,17 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Adzerk::Util do
4
+ describe "#camelize_data(data)" do
5
+ it "doesn't camelize keys when they are strings" do
6
+ data = {'No_CAMELcaseString' => 1234}
7
+ result = Adzerk::Util.camelize_data(data)
8
+ expect(result['No_CAMELcaseString']).to eql(1234)
9
+ end
10
+
11
+ it "camelizes keys when they are symbols" do
12
+ data = {:'No_CAMEL_case_Symbol' => 1234}
13
+ result = Adzerk::Util.camelize_data(data)
14
+ expect(result['NoCamelCaseSymbol']).to eql(1234)
15
+ end
16
+ end
17
+ end
@@ -21,17 +21,17 @@ describe "Zone API" do
21
21
  :site_id => $site_id,
22
22
  :is_deleted => false)
23
23
  $zone_id = zone[:id].to_s
24
- zone[:name].should == $name
25
- zone[:site_id].should == $site_id
26
- zone[:is_deleted].should == false
24
+ expect(zone[:name]).to eq($name)
25
+ expect(zone[:site_id]).to eq($site_id)
26
+ expect(zone[:is_deleted]).to eq(false)
27
27
  end
28
28
 
29
29
  it "should list a specific zone" do
30
30
  zone = @zones.get($zone_id)
31
- zone[:id].should eq($zone_id.to_i)
32
- zone[:name].should eq($name)
33
- zone[:site_id].should eq($site_id)
34
- zone[:is_deleted].should eq(false)
31
+ expect(zone[:id]).to eq($zone_id.to_i)
32
+ expect(zone[:name]).to eq($name)
33
+ expect(zone[:site_id]).to eq($site_id)
34
+ expect(zone[:is_deleted]).to eq(false)
35
35
  end
36
36
 
37
37
  it "should update a zone" do
@@ -40,24 +40,24 @@ describe "Zone API" do
40
40
  :name => $name,
41
41
  :site_id => $site_id,
42
42
  :is_deleted => false)
43
- zone[:id].should eq($zone_id.to_i)
44
- zone[:name].should eq($name)
45
- zone[:site_id].should eq($site_id)
46
- zone[:is_deleted].should eq(false)
43
+ expect(zone[:id]).to eq($zone_id.to_i)
44
+ expect(zone[:name]).to eq($name)
45
+ expect(zone[:site_id]).to eq($site_id)
46
+ expect(zone[:is_deleted]).to eq(false)
47
47
  end
48
48
 
49
49
  it "should list all zones" do
50
50
  result = @zones.list
51
- result.length.should > 0
52
- result[:items].last[:id].to_s.should == $zone_id
53
- result[:items].last[:name].should == $name
54
- result[:items].last[:site_id].should == $site_id
55
- result[:items].last[:is_deleted].should == false
51
+ expect(result.length).to be > 0
52
+ expect(result[:items].last[:id].to_s).to eq($zone_id)
53
+ expect(result[:items].last[:name]).to eq($name)
54
+ expect(result[:items].last[:site_id]).to eq($site_id)
55
+ expect(result[:items].last[:is_deleted]).to eq(false)
56
56
  end
57
57
 
58
58
  it "should delete a new zone" do
59
59
  response = @zones.delete($zone_id)
60
- response.body.should == '"Successfully deleted"'
60
+ expect(response.body).to eq('"Successfully deleted"')
61
61
  end
62
62
 
63
63
  end