zendesk_api 1.18.0 → 1.19.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d251a3a7a6b3e5830ef96e225b17cab2955918438ba819e2148fc1e5d233870
|
4
|
+
data.tar.gz: 3ae7a4241ab08f7b83833341368050ea52b8877ae0fdabaed97ed4d7d6054032
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11e3c75f505d736d00a6124867fcdd521a9545b7c3d1a60a72f4a0404db33c08048752f0a251513428e14ea909a37eda5a727cbf99ac514eb20106c497ae0ca9
|
7
|
+
data.tar.gz: 41cb490e567057b7b6938670561827401e6a9a8fd244298fd2180dc57af97c3eec129e4c64042f382232165680a998517eab60d0398e249f21c9a38d4d15ab4f
|
data/lib/zendesk_api/client.rb
CHANGED
@@ -8,6 +8,7 @@ require 'zendesk_api/lru_cache'
|
|
8
8
|
require 'zendesk_api/silent_mash'
|
9
9
|
require 'zendesk_api/middleware/request/etag_cache'
|
10
10
|
require 'zendesk_api/middleware/request/retry'
|
11
|
+
require 'zendesk_api/middleware/request/raise_rate_limited'
|
11
12
|
require 'zendesk_api/middleware/request/upload'
|
12
13
|
require 'zendesk_api/middleware/request/encode_json'
|
13
14
|
require 'zendesk_api/middleware/request/url_based_access_token'
|
@@ -93,6 +94,8 @@ module ZendeskAPI
|
|
93
94
|
|
94
95
|
config.retry = !!config.retry # nil -> false
|
95
96
|
|
97
|
+
set_raise_error_when_rated_limited
|
98
|
+
|
96
99
|
set_token_auth
|
97
100
|
|
98
101
|
set_default_logger
|
@@ -171,7 +174,12 @@ module ZendeskAPI
|
|
171
174
|
builder.use ZendeskAPI::Middleware::Request::Upload
|
172
175
|
builder.request :multipart
|
173
176
|
builder.use ZendeskAPI::Middleware::Request::EncodeJson
|
174
|
-
|
177
|
+
|
178
|
+
# Should always be first in the stack
|
179
|
+
builder.use ZendeskAPI::Middleware::Request::Retry, :logger => config.logger if config.retry
|
180
|
+
if config.raise_error_when_rate_limited
|
181
|
+
builder.use ZendeskAPI::Middleware::Request::RaiseRateLimited, :logger => config.logger
|
182
|
+
end
|
175
183
|
|
176
184
|
builder.adapter(*adapter)
|
177
185
|
end
|
@@ -190,6 +198,14 @@ module ZendeskAPI
|
|
190
198
|
end
|
191
199
|
end
|
192
200
|
|
201
|
+
def set_raise_error_when_rated_limited
|
202
|
+
config.raise_error_when_rate_limited = if config.retry
|
203
|
+
false
|
204
|
+
else
|
205
|
+
!!config.raise_error_when_rate_limited
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
193
209
|
def set_token_auth
|
194
210
|
if config.token && !config.password
|
195
211
|
config.password = config.token
|
@@ -16,6 +16,9 @@ module ZendeskAPI
|
|
16
16
|
# @return [Boolean] Whether to attempt to retry when rate-limited (http status: 429).
|
17
17
|
attr_accessor :retry
|
18
18
|
|
19
|
+
# @return [Boolean] Whether to raise error when rate-limited (http status: 429).
|
20
|
+
attr_accessor :raise_error_when_rate_limited
|
21
|
+
|
19
22
|
# @return [Logger] Logger to use when logging requests.
|
20
23
|
attr_accessor :logger
|
21
24
|
|
data/lib/zendesk_api/error.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'faraday/middleware'
|
2
|
+
require 'zendesk_api/error'
|
3
|
+
|
4
|
+
module ZendeskAPI
|
5
|
+
module Middleware
|
6
|
+
# @private
|
7
|
+
module Request
|
8
|
+
# Faraday middleware to handle HTTP Status 429 (rate limiting) / 503 (maintenance)
|
9
|
+
# @private
|
10
|
+
class RaiseRateLimited < Faraday::Middleware
|
11
|
+
ERROR_CODES = [429, 503].freeze
|
12
|
+
|
13
|
+
def initialize(app, options = {})
|
14
|
+
super(app)
|
15
|
+
@logger = options[:logger]
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(env)
|
19
|
+
response = @app.call(env)
|
20
|
+
|
21
|
+
if ERROR_CODES.include?(response.env[:status])
|
22
|
+
@logger.warn 'You have been rate limited. Raising error...' if @logger
|
23
|
+
raise Error::RateLimited.new(env)
|
24
|
+
else
|
25
|
+
response
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/zendesk_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zendesk_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.19.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Davidovitz
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- lib/zendesk_api/lru_cache.rb
|
110
110
|
- lib/zendesk_api/middleware/request/encode_json.rb
|
111
111
|
- lib/zendesk_api/middleware/request/etag_cache.rb
|
112
|
+
- lib/zendesk_api/middleware/request/raise_rate_limited.rb
|
112
113
|
- lib/zendesk_api/middleware/request/retry.rb
|
113
114
|
- lib/zendesk_api/middleware/request/upload.rb
|
114
115
|
- lib/zendesk_api/middleware/request/url_based_access_token.rb
|