adzerk 0.11 → 0.16

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 97f5418d9439259df41a593c48dd6e595a4ba78c
4
- data.tar.gz: deb21140298faa1a0d1ec353f2aebac29457f761
2
+ SHA256:
3
+ metadata.gz: de13745f2fdeb568524fc13132ce9357b360b18b8f52441796ccba849936d325
4
+ data.tar.gz: 2012611e5f91cbb4660d9c52bfba65e1530bdacda6e2b28ab94eaad2d5d07943
5
5
  SHA512:
6
- metadata.gz: ee82eee6f0c3d3e6020fbd9745b0816c3e2337bf2163df816483234edbcef4aa08f9ee4e6b0e9894c943baab92613916344f195a6629c4a486c38ed868878ce6
7
- data.tar.gz: 357d24279331ac326bc876ddec6c6bead5b158d17f3aa64fafb2e374e948fc7705e67d61c4cc8a942e8dd92ec15b3ed3f663bffbfc59c99cc24e70adfe3527da
6
+ metadata.gz: 1ba9d92c3d94e1e991a6100c5c17aa5a4eb1bf466ce30d87ef52d3b37e2c3681ce913f25223c59448497989fb3352c9252f3a3669b2e1f526a9fd6b642a94d4f
7
+ data.tar.gz: 22c4cbb832d2f13023c29202691c437661f028c44bddf0e07805d4e92a7b936039313311a585b5c0d8c2263c002572d0f9c77fecfb1769e861b45d35b428f63f
data/lib/adzerk.rb CHANGED
@@ -18,3 +18,6 @@ require "adzerk/site_zone_targeting"
18
18
  require "adzerk/category"
19
19
  require "adzerk/client"
20
20
  require "adzerk/priority"
21
+ require "adzerk/campaign"
22
+ require "adzerk/instant_count"
23
+ require "adzerk/creative_template"
@@ -5,5 +5,15 @@ module Adzerk
5
5
  data = { 'advertiserName' => advertiser_name }
6
6
  parse_response(client.post_request(url, data))
7
7
  end
8
+
9
+ def instant_counts(advertiser_id)
10
+ url = "instantcounts/#{endpoint}/#{advertiser_id}?page=#{page}&pageSize=#{pageSize}"
11
+ parse_response(client.get_request(url))
12
+ end
13
+
14
+ def list_creatives(advertiser_id, page: 1, pageSize: 500)
15
+ url = "advertiser/#{advertiser_id}/creatives?page=#{page}&pageSize=#{pageSize}"
16
+ parse_response(@client.get_request(url))
17
+ end
8
18
  end
9
19
  end
@@ -14,8 +14,8 @@ module Adzerk
14
14
 
15
15
  def create(opts={}, subid=nil)
16
16
  e = (subid && subendpoint) ? "#{subendpoint}/#{subid}/#{endpoint}" : endpoint
17
- data = { datakey => camelize_data(opts).to_json }
18
- response = @client.post_request(e, data)
17
+ data = camelize_data(opts)
18
+ response = @client.post_json_request(e, data)
19
19
  parse_response(response)
20
20
  end
21
21
 
@@ -24,16 +24,17 @@ module Adzerk
24
24
  parse_response(response)
25
25
  end
26
26
 
27
- def list(subid=nil)
27
+ def list(subid=nil, page: 1, pageSize: 500)
28
28
  e = (subid && subendpoint) ? "#{subendpoint}/#{subid}/#{endpoint}" : endpoint
29
+ e = "#{e}?page=#{page}&pageSize=#{pageSize}"
29
30
  response = @client.get_request(e)
30
31
  parse_response(response)
31
32
  end
32
33
 
33
34
  def update(opts={})
34
35
  id = opts[:id].to_s
35
- data = { datakey => camelize_data(opts).to_json }
36
- response = @client.put_request("#{endpoint}/#{id}", data)
36
+ data = camelize_data(opts)
37
+ response = @client.put_json_request("#{endpoint}/#{id}", data)
37
38
  parse_response(response)
38
39
  end
39
40
 
@@ -0,0 +1,8 @@
1
+ module Adzerk
2
+ class Campaign < ApiEndpoint
3
+ def instant_counts(campaign_id)
4
+ url = "instantcounts/#{endpoint}/#{campaign_id}"
5
+ parse_response(client.get_request(url))
6
+ end
7
+ end
8
+ end
@@ -20,13 +20,13 @@ module Adzerk
20
20
  @client.get_request(url)
21
21
  end
22
22
 
23
- def listAll
23
+ def listAll(page: 1, pageSize: 500)
24
24
  response = client.get_request('categories')
25
25
  parse_response(response)
26
26
  end
27
27
 
28
- def list(flight_id)
29
- url = "flight/#{flight_id}/categories"
28
+ def list(flight_id, page: 1, pageSize: 500)
29
+ url = "flight/#{flight_id}/categories?page=#{page}&pageSize=#{pageSize}"
30
30
  response = client.get_request(url)
31
31
  parse_response(response)
32
32
  end
@@ -21,7 +21,7 @@ module Adzerk
21
21
  response = parse_response(response)
22
22
  end
23
23
 
24
- def list
24
+ def list(page: 1, pageSize: 500)
25
25
  response = client.get_request('channelSite')
26
26
  parse_response(response)
27
27
  end
data/lib/adzerk/client.rb CHANGED
@@ -6,11 +6,20 @@ module Adzerk
6
6
  attr_reader :sites, :ad_types, :zones, :campaigns, :channels, :priorities,
7
7
  :advertisers, :flights, :creatives, :creative_maps,
8
8
  :publishers, :invitations, :reports, :channel_site_maps,
9
- :logins, :geotargetings, :sitezonetargetings, :categories
9
+ :logins, :geotargetings, :sitezonetargetings, :categories,
10
+ :instant_counts, :ads, :creative_templates
11
+
12
+ VERSION = Gem.loaded_specs['adzerk'].version.to_s
13
+ SDK_HEADER_NAME = 'X-Adzerk-Sdk-Version'
14
+ SDK_HEADER_VALUE = "adzerk-management-sdk-ruby:#{VERSION}"
15
+ BASE_SLEEP = 0.25
16
+ MAX_SLEEP = 5
17
+ MAX_ATTEMPTS = 10
10
18
 
11
19
  DEFAULTS = {
12
- :host => ENV["ADZERK_API_HOST"] || 'https://api.adzerk.net/v1/',
13
- :header => 'X-Adzerk-ApiKey'
20
+ :host => ENV["ADZERK_API_HOST"] || 'https://api.adzerk.net/',
21
+ :header => 'X-Adzerk-ApiKey',
22
+ :include_creative_templates => true
14
23
  }
15
24
 
16
25
  def initialize(key, opts = {})
@@ -19,72 +28,127 @@ module Adzerk
19
28
  @logins = Adzerk::ApiEndpoint.new(:client => self, :endpoint => 'login')
20
29
  @sites = Adzerk::ApiEndpoint.new(:client => self, :endpoint => 'site')
21
30
  @ad_types = Adzerk::ApiEndpoint.new(:client => self, :endpoint => 'adtypes', :subendpoint => 'channel', :datakey => 'adtype')
22
- @flights = Adzerk::ApiEndpoint.new(:client => self, :endpoint => 'flight')
31
+ @flights = Adzerk::Flight.new(:client => self, :endpoint => 'flight')
23
32
  @zones = Adzerk::ApiEndpoint.new(:client => self, :endpoint => 'zone')
24
- @campaigns = Adzerk::ApiEndpoint.new(:client => self, :endpoint => 'campaign')
33
+ @campaigns = Adzerk::Campaign.new(:client => self, :endpoint => 'campaign')
25
34
  @channels = Adzerk::ApiEndpoint.new(:client => self, :endpoint => 'channel')
26
35
  @priorities = Adzerk::Priority.new(:client => self, :endpoint => 'priority')
27
36
  @advertisers = Adzerk::Advertiser.new(:client => self, :endpoint => 'advertiser')
28
37
  @publishers = Adzerk::Publisher.new(:client => self, :endpoint => 'publisher')
29
38
  @creatives = Adzerk::Creative.new(:client => self, :endpoint => 'creative')
30
39
  @creative_maps = Adzerk::CreativeMap.new(:client => self)
40
+ @ads = @creative_maps
31
41
  @invitations = Adzerk::Invitation.new(:client => self)
32
42
  @reports = Adzerk::Reporting.new(:client => self)
33
43
  @channel_site_maps = Adzerk::ChannelSiteMap.new(:client => self)
34
44
  @geotargetings = Adzerk::GeoTargeting.new(:client => self, :endpoint => 'geotargeting')
35
45
  @sitezonetargetings = Adzerk::SiteZoneTargeting.new(:client => self, :endpoint => 'sitezone')
36
46
  @categories = Adzerk::Category.new(:client => self, :endpoint => 'category')
37
-
47
+ @instant_counts = Adzerk::InstantCount.new(:client => self)
48
+ @creative_templates = Adzerk::CreativeTemplate.new(:client => self)
38
49
  end
39
50
 
40
- def get_request(url)
41
- uri = URI.parse(@config[:host] + url)
51
+ def get_request(url, version: 'v1')
52
+ uri = URI.parse("#{@config[:host]}#{version}/#{url}")
42
53
  request = Net::HTTP::Get.new(uri.request_uri)
43
54
  request.add_field(@config[:header], @api_key)
55
+ request.add_field(SDK_HEADER_NAME, SDK_HEADER_VALUE)
44
56
  send_request(request, uri)
45
57
  end
46
58
 
47
- def post_request(url, data)
48
- uri = URI.parse(@config[:host] + url)
59
+ def post_request(url, data, version: 'v1')
60
+ uri = URI.parse("#{@config[:host]}#{version}/#{url}")
49
61
  request = Net::HTTP::Post.new(uri.request_uri)
50
62
  request.add_field(@config[:header], @api_key)
63
+ request.add_field(SDK_HEADER_NAME, SDK_HEADER_VALUE)
51
64
  request.set_form_data(data)
52
65
  send_request(request, uri)
53
66
  end
54
67
 
55
- def put_request(url, data)
56
- uri = URI.parse(@config[:host] + url)
68
+ def post_json_request(url, data, version: 'v1')
69
+ uri = URI.parse("#{@config[:host]}#{version}/#{url}")
70
+ request = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json')
71
+ request.add_field(@config[:header], @api_key)
72
+ request.add_field(SDK_HEADER_NAME, SDK_HEADER_VALUE)
73
+ request.body = data.to_json
74
+ send_request(request, uri)
75
+ end
76
+
77
+ def put_request(url, data, version: 'v1')
78
+ uri = URI.parse("#{@config[:host]}#{version}/#{url}")
57
79
  request = Net::HTTP::Put.new(uri.request_uri)
58
80
  request.add_field(@config[:header], @api_key)
81
+ request.add_field(SDK_HEADER_NAME, SDK_HEADER_VALUE)
59
82
  request.set_form_data(data)
60
83
  send_request(request, uri)
61
84
  end
62
85
 
63
- def create_creative(data={}, image_path='')
64
- response = RestClient.post(@config[:host] + 'creative',
65
- {:creative => camelize_data(data).to_json},
66
- :X_Adzerk_ApiKey => @api_key,
67
- :accept => :json)
86
+ def put_json_request(url, data, version: 'v1')
87
+ uri = URI.parse("#{@config[:host]}#{version}/#{url}")
88
+ request = Net::HTTP::Put.new(uri.request_uri, 'Content-Type' => 'application/json')
89
+ request.add_field(@config[:header], @api_key)
90
+ request.add_field(SDK_HEADER_NAME, SDK_HEADER_VALUE)
91
+ request.body = data.to_json
92
+ send_request(request, uri)
93
+ end
94
+
95
+ def create_creative(data={}, image_path='', version: 'v1')
96
+ response = nil
97
+ attempt = 0
98
+
99
+ loop do
100
+ response = RestClient.post(@config[:host] + version + '/creative',
101
+ {:creative => camelize_data(data).to_json},
102
+ :X_Adzerk_ApiKey => @api_key,
103
+ :X_Adzerk_Sdk_Version => SDK_HEADER_VALUE,
104
+ :accept => :json)
105
+ break if response.code != 429 or attempt >= (@config[:max_attempts] || MAX_ATTEMPTS)
106
+ sleep(rand(0.0..[MAX_SLEEP, BASE_SLEEP * 2 ** attempt].min()))
107
+ attempt += 1
108
+ end
68
109
  response = upload_creative(JSON.parse(response)["Id"], image_path) unless image_path.empty?
69
110
  response
70
111
  end
71
112
 
72
- def upload_creative(id, image_path)
113
+ def upload_creative(id, image_path, size_override: false, version: 'v1')
114
+ response = nil
115
+ attempt = 0
73
116
  image = File.new(image_path, 'rb')
74
- RestClient.post(@config[:host] + 'creative/' + id.to_s + '/upload',
75
- {:image => image},
76
- "X-Adzerk-ApiKey" => @api_key,
77
- :accept => :mime)
117
+ url = @config[:host] + version + '/creative/' + id.to_s + '/upload'
118
+ url += '?sizeOverride=true' if size_override
119
+ loop do
120
+ response = RestClient.post(url,
121
+ {:image => image},
122
+ "X-Adzerk-ApiKey" => @api_key,
123
+ SDK_HEADER_NAME => SDK_HEADER_VALUE,
124
+ :accept => :mime)
125
+
126
+ break if response.code != 429 or attempt >= (@config[:max_attempts] || MAX_ATTEMPTS)
127
+ sleep(rand(0.0..[MAX_SLEEP, BASE_SLEEP * 2 ** attempt].min()))
128
+ attempt += 1
129
+ end
130
+ response
78
131
  end
79
132
 
80
133
  def send_request(request, uri)
134
+ response = nil
135
+ attempt = 0
81
136
  http = Net::HTTP.new(uri.host, uri.port)
82
137
  http.use_ssl = uri.scheme == 'https'
83
- response = http.request(request)
84
- if response.kind_of? Net::HTTPClientError
138
+
139
+ loop do
140
+ response = http.request(request)
141
+ break if response.code != "429" or attempt >= (@config[:max_attempts] || MAX_ATTEMPTS)
142
+ sleep(rand(0.0..[MAX_SLEEP, BASE_SLEEP * 2 ** attempt].min()))
143
+ attempt += 1
144
+ end
145
+
146
+ if response.kind_of? Net::HTTPClientError or response.kind_of? Net::HTTPServerError
85
147
  error_response = JSON.parse(response.body)
86
- raise Adzerk::ApiError.new(error_response["message"])
148
+ msg = error_response["message"] || error_response["Error"] || response.body
149
+ raise Adzerk::ApiError.new(msg)
87
150
  end
151
+
88
152
  response
89
153
  end
90
154
 
@@ -8,8 +8,8 @@ module Adzerk
8
8
  uncamelize_data(JSON.parse(response))
9
9
  end
10
10
 
11
- def list(advertiserId)
12
- url = 'advertiser/' + advertiserId.to_s + "/creatives"
11
+ def list(advertiserId, page: 1, pageSize: 500)
12
+ url = "advertiser/#{advertiserId}/creatives?page=#{page}&pageSize=#{pageSize}"
13
13
  parse_response(@client.get_request(url))
14
14
  end
15
15
 
@@ -18,8 +18,8 @@ module Adzerk
18
18
  parse_response(@client.get_request(url))
19
19
  end
20
20
 
21
- def list(flight_id)
22
- url = "flight/#{flight_id}/creatives"
21
+ def list(flight_id, page: 1, pageSize: 500)
22
+ url = "flight/#{flight_id}/creatives?page=#{page}&#pageSize=#{pageSize}"
23
23
  parse_response(@client.get_request(url))
24
24
  end
25
25
 
@@ -34,5 +34,10 @@ module Adzerk
34
34
  @client.get_request(url)
35
35
  end
36
36
 
37
+ def instant_counts(creative_map_id)
38
+ url = "instantcounts/#{endpoint}/#{creative_map_id}"
39
+ parse_response(client.get_request(url))
40
+ end
41
+
37
42
  end
38
43
  end
@@ -0,0 +1,30 @@
1
+ module Adzerk
2
+ class CreativeTemplate
3
+
4
+ include Adzerk::Util
5
+
6
+ attr_reader :client
7
+
8
+ def initialize(args={})
9
+ @client = args[:client]
10
+ end
11
+
12
+ def create(data={})
13
+ parse_response(@client.post_json_request("creative-templates", camelize_data(data), version: 'v2'))
14
+ end
15
+
16
+ def update(id, data={})
17
+ url = "creative-templates/#{id}/update"
18
+ parse_response(@client.post_json_request(url, camelize_data(data), version: 'v2'))
19
+ end
20
+
21
+ def get(id)
22
+ parse_response(@client.get_request("creative-templates/#{id}", version: 'v2'))
23
+ end
24
+
25
+ def list(page: 1, pageSize: 100)
26
+ url = "creative-templates?page=#{page}&pageSize=#{pageSize}"
27
+ parse_response(@client.get_request(url, version: 'v2'))
28
+ end
29
+ end
30
+ end
data/lib/adzerk/flight.rb CHANGED
@@ -8,5 +8,18 @@ module Adzerk
8
8
  url = 'region/' + region
9
9
  parse_reponse(@client.get_request(url))
10
10
  end
11
+
12
+ def instant_counts(flight_id)
13
+ url = "instantcounts/#{endpoint}/#{flight_id}"
14
+ parse_response(client.get_request(url))
15
+ end
16
+
17
+ def list_for_campaign(campaign_id, is_active = nil)
18
+ url = "campaign/#{campaign_id}/flight"
19
+ if !is_active.nil?
20
+ url = "#{url}?isActive=#{is_active}"
21
+ end
22
+ parse_response(@client.get_request(url))
23
+ end
11
24
  end
12
25
  end
@@ -0,0 +1,15 @@
1
+ module Adzerk
2
+ class InstantCount
3
+ include Adzerk::Util
4
+
5
+ def initialize(args={})
6
+ @client = args[:client]
7
+ end
8
+
9
+ def bulk(data={})
10
+ url = "instantcounts/bulk"
11
+ response = @client.post_json_request(url, data)
12
+ parse_response(response)
13
+ end
14
+ end
15
+ end
@@ -13,5 +13,19 @@ module Adzerk
13
13
  parse_response(response)
14
14
  end
15
15
 
16
+ def create(opts={}, subid=nil)
17
+ e = (subid && subendpoint) ? "#{subendpoint}/#{subid}/#{endpoint}" : endpoint
18
+ data = { datakey => camelize_data(opts).to_json }
19
+ response = @client.post_request(e, data)
20
+ parse_response(response)
21
+ end
22
+
23
+ def update(opts={})
24
+ id = opts[:id].to_s
25
+ data = { datakey => camelize_data(opts).to_json }
26
+ response = @client.put_request("#{endpoint}/#{id}", data)
27
+ parse_response(response)
28
+ end
29
+
16
30
  end
17
31
  end
data/lib/adzerk/util.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Adzerk
2
2
  module Util
3
- extend self
3
+ extend self
4
4
 
5
5
  def camelize_data(data)
6
6
  return data unless data.respond_to?(:reduce)
@@ -1,3 +1,3 @@
1
1
  module Adzerk
2
- VERSION = "0.11"
2
+ VERSION = "0.16"
3
3
  end
@@ -73,7 +73,8 @@ describe "Campaign API" do
73
73
  :name => "Test",
74
74
  :priority_id => $priority_id,
75
75
  :impressions => 10000,
76
- :is_deleted => false
76
+ :is_deleted => false,
77
+ :goal_type => 1
77
78
  }]
78
79
  new1_campaign = {
79
80
  :name => $campaign_name,
@@ -88,8 +89,6 @@ describe "Campaign API" do
88
89
  campaign = @campaigns.create(new1_campaign)
89
90
  $campaign_id_1 = campaign[:id].to_s
90
91
  expect($campaign_name).to eq(campaign[:name])
91
- # JSON.parse(response.body)["StartDate"].should == "/Date(1293858000000-0500)/"
92
- # JSON.parse(response.body)["EndDate"].should == "/Date(1325307600000-0500)/"
93
92
  expect($campaign_is_active).to eq(campaign[:is_active])
94
93
  expect(campaign[:is_deleted]).to eq(false)
95
94
  expect($campaign_price.to_f).to eq(campaign[:price])
@@ -154,7 +153,9 @@ describe "Campaign API" do
154
153
  }
155
154
 
156
155
  expect{ @campaigns.create(new_campaign) }.to raise_error("This advertiser is not part of your network")
156
+ end
157
157
 
158
+ it "should not update a campaign with a new advertiserId" do
158
159
  updated_campaign = {
159
160
  :id => $campaign_id,
160
161
  :name => 'Test campaign ' + rand(1000000).to_s,
@@ -167,11 +168,11 @@ describe "Campaign API" do
167
168
  :is_deleted => false
168
169
  }
169
170
 
170
- expect{ @campaigns.update(updated_campaign) }.to raise_error("This advertiser is not part of your network")
171
+ expect{ @campaigns.update(updated_campaign) }.to raise_error("This campaign belongs to advertiser #{$advertiserId}; a different advertiser cannot be specified.")
171
172
  end
172
173
 
173
174
  it "should not retrieve a campaign with a advertiserId that doesn't belong to it" do
174
- expect { @campaigns.get('123') }.to raise_error("This campaign is not part of your network")
175
+ expect { @campaigns.get('123') }.to raise_error("Campaign not found.")
175
176
  end
176
177
 
177
178
  it "should delete a new campaign" do
@@ -106,9 +106,13 @@ describe "Category API" do
106
106
  @category.create(bad_id, $new_category)
107
107
  }.to raise_error "Flight is not a part of your network"
108
108
 
109
- expect {
110
- @category.list(bad_id)
111
- }.to raise_error "Flight is not a part of your network"
109
+ # Disabling this assertion temporarily.
110
+ # The API is no longer returning an error bur rather an empty list.
111
+ # Once the bug in API is fixed, this needs to be re-enabled.
112
+ #
113
+ # expect {
114
+ # @category.list(bad_id)
115
+ # }.to raise_error "Flight is not a part of your network"
112
116
 
113
117
  expect {
114
118
  @category.delete(bad_id,$category_id)
@@ -74,7 +74,7 @@ describe "Channel API" do
74
74
  expect(last_channel[:engine]).to eq($u_channel_engine)
75
75
  expect(last_channel[:keywords]).to eq($u_channel_keywords)
76
76
  expect(last_channel[:cpm]).to eq($u_channel_CPM.to_f)
77
- expect(last_channel[:ad_types]).to eq($u_channel_AdTypes)
77
+ expect(last_channel[:ad_types]).to match_array($u_channel_AdTypes)
78
78
  end
79
79
 
80
80
  it "should delete a new channel" do
@@ -332,7 +332,7 @@ describe "Creative Flight API" do
332
332
  end
333
333
 
334
334
  it "should not get a map in a different network" do
335
- expect{ @creative_maps.get(123, @flight_id) }.to raise_error "This PassCreativeMap does not belong to your network."
335
+ expect{ @creative_maps.get(123, @flight_id) }.to raise_error Adzerk::ApiError
336
336
  end
337
337
 
338
338
  it "should get a map that's been deleted" do
@@ -382,37 +382,6 @@ describe "Creative Flight API" do
382
382
  }.to raise_error "This creative map has been deleted"
383
383
  end
384
384
 
385
- it "should fail when creating a map for a campaign in a different network" do
386
- expect {
387
- creative_map = @creative_maps.create(
388
- :campaign_id => 123,
389
- :flight_id => @flight_id,
390
- :size_override => false,
391
- :iframe => false,
392
- :impressions => 100000,
393
- :percentage => 50,
394
- :siteId => @site_id,
395
- :zoneId => @zone_id,
396
- :distributionType => 1,
397
- :isActive => true,
398
- :isDeleted => false,
399
- :creative => {
400
- :title => "Creative Title",
401
- :url => "http://www.adzerk.com",
402
- :body => "Test Body",
403
- :advertiser_id => @advertiser_id,
404
- :ad_type_id => 18,
405
- 'IsHTMLJS' => true,
406
- :script_body => "<html></html>",
407
- :is_active => true,
408
- :alt => "alt text",
409
- :is_deleted => false,
410
- :is_sync => false
411
- }
412
- )
413
- }.to raise_error "This campaign is not part of your network"
414
- end
415
-
416
385
  it "should fail when creating a map for a site in a different network" do
417
386
  expect {
418
387
  creative_map = @creative_maps.create(
@@ -0,0 +1,100 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Creative Template API" do
4
+
5
+ before do
6
+ @creative_templates = Adzerk::Client.new(API_KEY).creative_templates
7
+ end
8
+
9
+ it "should create a new creative template" do
10
+ expected = {
11
+ description: 'Creative Template Description',
12
+ name: 'API Test Creative Template Name 1',
13
+ is_archived: false,
14
+ fields: [{
15
+ name: 'Title',
16
+ description: 'The Creative Template Title',
17
+ type: 'String',
18
+ variable: 'ctTitle',
19
+ required: true,
20
+ ad_query: false
21
+ }, {
22
+ name: 'Thumbnail',
23
+ description: 'The URL of a Thumbnail Image',
24
+ type: 'String',
25
+ variable: 'ctThumbnailUrl',
26
+ required: false,
27
+ ad_query: true
28
+ }],
29
+ contents: [{
30
+ type: 'Raw',
31
+ body: '{"title": "{{ctTitle}}", "thumbnailUrl": "{{ctThumbnailUrl}}" }'
32
+ }]
33
+ }
34
+
35
+ result = @creative_templates.create(expected)
36
+
37
+ $creative_template_id = result[:id].to_s
38
+
39
+ expect(result).to include(:id)
40
+ expect(result[:description]).to eq(expected[:description])
41
+ expect(result[:name]).to eq(expected[:name])
42
+ expect(result[:is_archived]).to eq(expected[:is_archived])
43
+ expect(result[:fields]).to match_array(expected[:fields])
44
+ end
45
+
46
+ it "should list existing creative templates" do
47
+ result = @creative_templates.list
48
+
49
+ expect(result[:page]).to eq(1)
50
+ expect(result[:page_size]).to eq(100)
51
+ expect(result[:total_items]).to be >= 1
52
+ end
53
+
54
+ it "should get an existing creative template" do
55
+ expected = {
56
+ description: 'Creative Template Description',
57
+ name: 'API Test Creative Template Name 1',
58
+ is_archived: false,
59
+ fields: [{
60
+ name: 'Title',
61
+ description: 'The Creative Template Title',
62
+ type: 'String',
63
+ variable: 'ctTitle',
64
+ required: true,
65
+ ad_query: false,
66
+ }, {
67
+ name: 'Thumbnail',
68
+ description: 'The URL of a Thumbnail Image',
69
+ type: 'String',
70
+ variable: 'ctThumbnailUrl',
71
+ required: false,
72
+ ad_query: true,
73
+ }],
74
+ contents: [{
75
+ type: 'Raw',
76
+ body: '{"title": "{{ctTitle}}", "thumbnailUrl": "{{ctThumbnailUrl}}" }'
77
+ }]
78
+ }
79
+
80
+ result = @creative_templates.get($creative_template_id)
81
+
82
+ expect(result[:description]).to eq(expected[:description])
83
+ expect(result[:name]).to eq(expected[:name])
84
+ expect(result[:is_archived]).to eq(expected[:is_archived])
85
+ expect(result[:fields]).to match_array(expected[:fields])
86
+ end
87
+
88
+ it "should update an existing creative template" do
89
+ update = {
90
+ updates: [{
91
+ path: ['IsArchived'],
92
+ value: true
93
+ }]
94
+ }
95
+
96
+ result = @creative_templates.update($creative_template_id, update)
97
+
98
+ expect(result[:is_archived]).to eq(true)
99
+ end
100
+ end
@@ -159,7 +159,8 @@ describe "Flight API" do
159
159
  :start_date => $flight_StartDate,
160
160
  :goal_type => $flight_GoalType,
161
161
  :impressions => $flight_Impressions,
162
- :is_companion => false)
162
+ :is_companion => false,
163
+ :end_date => $flight_EndDate)
163
164
  expect(flight[:name]).to eq("New Flight Name")
164
165
  expect(flight[:is_companion]).to be false
165
166
  end
@@ -112,7 +112,7 @@ describe "GeoTargeting API" do
112
112
  it "should error when deleting a geotargeting that does not exist" do
113
113
  expect {
114
114
  @geotargetings.delete($flight_id, 1)
115
- }.to raise_error "Couldn't find network for model: PassLocation, id: 1"
115
+ }.to raise_error "This PassLocation does not exist in your network."
116
116
  end
117
117
 
118
118
  it "should check if a flight is not a part of your network" do
@@ -0,0 +1,25 @@
1
+ require 'pp'
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+
4
+ describe "Instant Count API" do
5
+ before(:all) do
6
+ client = Adzerk::Client.new(API_KEY)
7
+ @instant_counts = client.instant_counts
8
+ end
9
+
10
+ it "should fetch bulk instant counts" do
11
+ advertiser_id = 1065290
12
+ campaign_id = 1582611
13
+
14
+ counts = @instant_counts.bulk({
15
+ :advertisers => [advertiser_id],
16
+ :campaigns => [campaign_id]
17
+ })
18
+
19
+ expect(counts).to have_key(:advertisers)
20
+ expect(counts[:advertisers]).to have_key(advertiser_id.to_s.to_sym)
21
+
22
+ expect(counts).to have_key(:campaigns)
23
+ expect(counts[:campaigns]).to have_key(campaign_id.to_s.to_sym)
24
+ end
25
+ end
@@ -1,5 +1,9 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
+ def random_email
4
+ "test@email-#{rand(1000000)}.com"
5
+ end
6
+
3
7
  describe "Login_API" do
4
8
 
5
9
  before do
@@ -7,13 +11,14 @@ describe "Login_API" do
7
11
  end
8
12
 
9
13
  it "should create a new login" do
10
- email = "test@email_#{rand(1000000)}.com"
14
+ email = random_email()
11
15
  login = @logins.create(:email => email,
12
16
  :password => '1234567',
13
17
  :name => "John Doe")
14
18
  $login_id = login[:id]
15
19
  expect(login[:email]).to eq(email)
16
- expect(login[:password]).to eq("1234567")
20
+ # Password is redacted in the response.
21
+ expect(login[:password]).to eq("")
17
22
  expect(login[:name]).to eq("John Doe")
18
23
  end
19
24
 
@@ -28,8 +33,10 @@ describe "Login_API" do
28
33
  end
29
34
 
30
35
  it "should update a login" do
36
+ new_email = random_email()
31
37
  login = @logins.update(:id => $login_id,
32
- :name => "New Name")
38
+ :name => "New Name",
39
+ :email => new_email)
33
40
  expect(login[:name]).to eq("New Name")
34
41
  end
35
42
 
@@ -63,7 +63,7 @@ describe "Priority API" do
63
63
  end
64
64
 
65
65
  it "should not allow selection algorithm to be updated" do
66
- expect { @priorities.update(selection_algorithm: 1) }.to raise_error
66
+ expect { @priorities.update(selection_algorithm: 1) }.to raise_error JSON::ParserError
67
67
  end
68
68
 
69
69
  it "should list all priorities" do
@@ -6,7 +6,7 @@ describe "Report API" do
6
6
  @reports = Adzerk::Client.new(API_KEY).reports
7
7
 
8
8
  $new_report = {
9
- :start_date => "1/15/2011",
9
+ :start_date => "01/15/2011",
10
10
  :end_date => "12/31/2011",
11
11
  :group_by => ['month'],
12
12
  'Top30countries' => false,
@@ -36,7 +36,7 @@ describe "Report API" do
36
36
  end
37
37
 
38
38
  it "should return a status of 1 if the report isn't ready yet" do
39
- bigger_report = $new_report.update(start_date: "1/1/2014", end_date: "10/1/2018")
39
+ bigger_report = $new_report.update(start_date: "01/01/2014", end_date: "10/01/2018")
40
40
  report_id = @reports.create_queued_report(bigger_report)[:id]
41
41
  # immediately poll for the result
42
42
  response = @reports.retrieve_queued_report(report_id)
@@ -127,7 +127,7 @@ describe "SiteZoneTargeting API" do
127
127
  it "should error when deleting a sitezone targeting that does not exist" do
128
128
  expect {
129
129
  @sitezonetargeting.delete($flight_id,1)
130
- }.to raise_error "Couldn't find network for model: PassSiteMap, id: 1"
130
+ }.to raise_error "This PassSiteMap does not exist in your network."
131
131
  end
132
132
 
133
133
  it "should check if a flight is not a part of your network" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adzerk
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.11'
4
+ version: '0.16'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kacy Fortner
@@ -17,7 +17,7 @@ authors:
17
17
  autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
- date: 2017-03-14 00:00:00.000000000 Z
20
+ date: 2021-04-14 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rspec
@@ -25,28 +25,28 @@ dependencies:
25
25
  requirements:
26
26
  - - '='
27
27
  - !ruby/object:Gem::Version
28
- version: 2.11.0
28
+ version: 3.5.0
29
29
  type: :development
30
30
  prerelease: false
31
31
  version_requirements: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - '='
34
34
  - !ruby/object:Gem::Version
35
- version: 2.11.0
35
+ version: 3.5.0
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
38
  requirement: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - '='
41
41
  - !ruby/object:Gem::Version
42
- version: 12.0.0
42
+ version: 12.3.3
43
43
  type: :development
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - '='
48
48
  - !ruby/object:Gem::Version
49
- version: 12.0.0
49
+ version: 12.3.3
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: json
52
52
  requirement: !ruby/object:Gem::Requirement
@@ -81,14 +81,14 @@ dependencies:
81
81
  requirements:
82
82
  - - "~>"
83
83
  - !ruby/object:Gem::Version
84
- version: '3.2'
84
+ version: '5.1'
85
85
  type: :runtime
86
86
  prerelease: false
87
87
  version_requirements: !ruby/object:Gem::Requirement
88
88
  requirements:
89
89
  - - "~>"
90
90
  - !ruby/object:Gem::Version
91
- version: '3.2'
91
+ version: '5.1'
92
92
  description: Ruby library for the Adzerk API
93
93
  email: engineering@adzerk.com
94
94
  executables: []
@@ -98,14 +98,17 @@ files:
98
98
  - lib/adzerk.rb
99
99
  - lib/adzerk/advertiser.rb
100
100
  - lib/adzerk/api_endpoint.rb
101
+ - lib/adzerk/campaign.rb
101
102
  - lib/adzerk/category.rb
102
103
  - lib/adzerk/channel_site_map.rb
103
104
  - lib/adzerk/client.rb
104
105
  - lib/adzerk/creative.rb
105
106
  - lib/adzerk/creative_map.rb
107
+ - lib/adzerk/creative_template.rb
106
108
  - lib/adzerk/errors.rb
107
109
  - lib/adzerk/flight.rb
108
110
  - lib/adzerk/geo_targeting.rb
111
+ - lib/adzerk/instant_count.rb
109
112
  - lib/adzerk/invitation.rb
110
113
  - lib/adzerk/priority.rb
111
114
  - lib/adzerk/publisher.rb
@@ -121,8 +124,10 @@ files:
121
124
  - test/channel_site_map_api_spec.rb
122
125
  - test/creative_api_spec.rb
123
126
  - test/creative_map_api_spec.rb
127
+ - test/creative_template_spec.rb
124
128
  - test/flight_api_spec.rb
125
129
  - test/geo_targeting_api_spec.rb
130
+ - test/instant_count_api_spec.rb
126
131
  - test/invitation_api_spec.rb
127
132
  - test/login_api_spec.rb
128
133
  - test/priority_api_spec.rb
@@ -136,7 +141,8 @@ files:
136
141
  - test/util_spec.rb
137
142
  - test/zone_api_spec.rb
138
143
  homepage: http://adzerk.com
139
- licenses: []
144
+ licenses:
145
+ - Apache-2.0
140
146
  metadata: {}
141
147
  post_install_message:
142
148
  rdoc_options: []
@@ -153,8 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
159
  - !ruby/object:Gem::Version
154
160
  version: '0'
155
161
  requirements: []
156
- rubyforge_project:
157
- rubygems_version: 2.5.1
162
+ rubygems_version: 3.1.2
158
163
  signing_key:
159
164
  specification_version: 4
160
165
  summary: Adzerk API