adzerk 0.15 → 0.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b08fcf724937ddb370874ccdf50506ca1f6e16be79cde06dc8777d1e1d99bfd6
4
- data.tar.gz: 28776f7247b58b93c4590fa1689737288a738240403e0d0af18bebd381f9b97d
3
+ metadata.gz: de13745f2fdeb568524fc13132ce9357b360b18b8f52441796ccba849936d325
4
+ data.tar.gz: 2012611e5f91cbb4660d9c52bfba65e1530bdacda6e2b28ab94eaad2d5d07943
5
5
  SHA512:
6
- metadata.gz: 4763be769dac520c65beb9e7e6049089633635a75fc20f9480428d1b286cbeaa2bd543d5a16e4ae4d4a40c5674ae3e6963e2f2d5f5141ab574686829d8511630
7
- data.tar.gz: 5e6e08ec68228782bf1acdecc0c035ac66567f0886adcbde45ba77e03a073321d375287b1e4e316aee2a6d65ba7cb20c4812d1a4597567ae0eeb8a6dbc783090
6
+ metadata.gz: 1ba9d92c3d94e1e991a6100c5c17aa5a4eb1bf466ce30d87ef52d3b37e2c3681ce913f25223c59448497989fb3352c9252f3a3669b2e1f526a9fd6b642a94d4f
7
+ data.tar.gz: 22c4cbb832d2f13023c29202691c437661f028c44bddf0e07805d4e92a7b936039313311a585b5c0d8c2263c002572d0f9c77fecfb1769e861b45d35b428f63f
data/lib/adzerk/client.rb CHANGED
@@ -12,6 +12,9 @@ module Adzerk
12
12
  VERSION = Gem.loaded_specs['adzerk'].version.to_s
13
13
  SDK_HEADER_NAME = 'X-Adzerk-Sdk-Version'
14
14
  SDK_HEADER_VALUE = "adzerk-management-sdk-ruby:#{VERSION}"
15
+ BASE_SLEEP = 0.25
16
+ MAX_SLEEP = 5
17
+ MAX_ATTEMPTS = 10
15
18
 
16
19
  DEFAULTS = {
17
20
  :host => ENV["ADZERK_API_HOST"] || 'https://api.adzerk.net/',
@@ -90,35 +93,62 @@ module Adzerk
90
93
  end
91
94
 
92
95
  def create_creative(data={}, image_path='', version: 'v1')
93
- response = RestClient.post(@config[:host] + version + '/creative',
94
- {:creative => camelize_data(data).to_json},
95
- :X_Adzerk_ApiKey => @api_key,
96
- :X_Adzerk_Sdk_Version => SDK_HEADER_VALUE,
97
- :accept => :json)
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
98
109
  response = upload_creative(JSON.parse(response)["Id"], image_path) unless image_path.empty?
99
110
  response
100
111
  end
101
112
 
102
113
  def upload_creative(id, image_path, size_override: false, version: 'v1')
114
+ response = nil
115
+ attempt = 0
103
116
  image = File.new(image_path, 'rb')
104
117
  url = @config[:host] + version + '/creative/' + id.to_s + '/upload'
105
118
  url += '?sizeOverride=true' if size_override
106
- RestClient.post(url,
107
- {:image => image},
108
- "X-Adzerk-ApiKey" => @api_key,
109
- SDK_HEADER_NAME => SDK_HEADER_VALUE,
110
- :accept => :mime)
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
111
131
  end
112
132
 
113
133
  def send_request(request, uri)
134
+ response = nil
135
+ attempt = 0
114
136
  http = Net::HTTP.new(uri.host, uri.port)
115
137
  http.use_ssl = uri.scheme == 'https'
116
- response = http.request(request)
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
+
117
146
  if response.kind_of? Net::HTTPClientError or response.kind_of? Net::HTTPServerError
118
147
  error_response = JSON.parse(response.body)
119
148
  msg = error_response["message"] || error_response["Error"] || response.body
120
149
  raise Adzerk::ApiError.new(msg)
121
150
  end
151
+
122
152
  response
123
153
  end
124
154
 
@@ -1,3 +1,3 @@
1
1
  module Adzerk
2
- VERSION = "0.15"
2
+ VERSION = "0.16"
3
3
  end
@@ -172,7 +172,7 @@ describe "Campaign API" do
172
172
  end
173
173
 
174
174
  it "should not retrieve a campaign with a advertiserId that doesn't belong to it" do
175
- 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.")
176
176
  end
177
177
 
178
178
  it "should delete a new campaign" do
@@ -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
@@ -17,12 +17,14 @@ describe "Creative Template API" do
17
17
  type: 'String',
18
18
  variable: 'ctTitle',
19
19
  required: true,
20
+ ad_query: false
20
21
  }, {
21
22
  name: 'Thumbnail',
22
23
  description: 'The URL of a Thumbnail Image',
23
24
  type: 'String',
24
25
  variable: 'ctThumbnailUrl',
25
26
  required: false,
27
+ ad_query: true
26
28
  }],
27
29
  contents: [{
28
30
  type: 'Raw',
@@ -60,12 +62,14 @@ describe "Creative Template API" do
60
62
  type: 'String',
61
63
  variable: 'ctTitle',
62
64
  required: true,
65
+ ad_query: false,
63
66
  }, {
64
67
  name: 'Thumbnail',
65
68
  description: 'The URL of a Thumbnail Image',
66
69
  type: 'String',
67
70
  variable: 'ctThumbnailUrl',
68
71
  required: false,
72
+ ad_query: true,
69
73
  }],
70
74
  contents: [{
71
75
  type: 'Raw',
@@ -38,7 +38,6 @@ describe "Login_API" do
38
38
  :name => "New Name",
39
39
  :email => new_email)
40
40
  expect(login[:name]).to eq("New Name")
41
- expect(login[:email]).to eq(new_email)
42
41
  end
43
42
 
44
43
  end
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.15'
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: 2021-01-22 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