adzerk 0.15 → 0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/adzerk/client.rb +41 -11
- data/lib/adzerk/version.rb +1 -1
- data/test/campaign_api_spec.rb +1 -1
- data/test/channel_api_spec.rb +1 -1
- data/test/creative_template_spec.rb +4 -0
- data/test/login_api_spec.rb +0 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de13745f2fdeb568524fc13132ce9357b360b18b8f52441796ccba849936d325
|
4
|
+
data.tar.gz: 2012611e5f91cbb4660d9c52bfba65e1530bdacda6e2b28ab94eaad2d5d07943
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 =
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
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
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
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
|
-
|
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
|
|
data/lib/adzerk/version.rb
CHANGED
data/test/campaign_api_spec.rb
CHANGED
@@ -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("
|
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
|
data/test/channel_api_spec.rb
CHANGED
@@ -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
|
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',
|
data/test/login_api_spec.rb
CHANGED
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.
|
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-
|
20
|
+
date: 2021-04-14 00:00:00.000000000 Z
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
23
|
name: rspec
|