zendesk_api 1.32.0 → 1.33.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: 3a9cc4118166019441137ca3a0ddbabd9444b7b32b26ca1f3ed83b9cddb5dea0
4
- data.tar.gz: 1fbaf93e103deb403cbcf81cdb031e0461de68ed532ad6abd061d8d7cf6462c8
3
+ metadata.gz: ac58a5fc63f870e31bd1a7d33ce398aef60c203fc5ec7bba79b1422b81aa3402
4
+ data.tar.gz: 1a315f8e08e96b2f1d1c20decb998459ec5f7ddc7ee233cb6cdaa7c0374da452
5
5
  SHA512:
6
- metadata.gz: 51e1b589e97fd42c532ef1225b9c2a0cfeabb6f7560739fad4adde015defc73f3908d4ab2049135ca219d5e210965fc1c6e644914e73ac886fb5b50ad810a7e6
7
- data.tar.gz: ef264143b1c4236505bff73e11d846ea4eb6bb27721bc848b6031e641c031f9827d9e32546ba2480bbddd8cf86f84bc6a62e0ff802e3157546d0b0a6c3c9f792
6
+ metadata.gz: e4021bc4c21f5b0ac9257ef8a8c0ee34e22244865f8737167be27aa057505f240d9c6996d262162cce3734759ac8b93eacf3ab3c9454066976ae1e835e5631fa
7
+ data.tar.gz: 750d62cb5fc7f404a034ff8c5cc5e3c85c59a5852e4d46d55facb224dcfc7b3f41daf29ab7cb228d06993158108cba7a76ae72c50b0acbf9ee03adcab83e73f6
@@ -181,7 +181,7 @@ module ZendeskAPI
181
181
  builder.use ZendeskAPI::Middleware::Request::EncodeJson
182
182
 
183
183
  # Should always be first in the stack
184
- builder.use ZendeskAPI::Middleware::Request::Retry, :logger => config.logger if config.retry
184
+ builder.use ZendeskAPI::Middleware::Request::Retry, :logger => config.logger, :retry_codes => config.retry_codes, :retry_on_exception => config.retry_on_exception if config.retry
185
185
  if config.raise_error_when_rate_limited
186
186
  builder.use ZendeskAPI::Middleware::Request::RaiseRateLimited, :logger => config.logger
187
187
  end
@@ -45,6 +45,12 @@ module ZendeskAPI
45
45
  # @return [Boolean] Whether to use resource_cache or not
46
46
  attr_accessor :use_resource_cache
47
47
 
48
+ # specify the server error codes in which you want a retry to be attempted
49
+ attr_accessor :retry_codes
50
+
51
+ # specify if you want a (network layer) exception to elicit a retry
52
+ attr_accessor :retry_on_exception
53
+
48
54
  def initialize
49
55
  @client_options = {}
50
56
  @use_resource_cache = true
@@ -1,5 +1,4 @@
1
1
  require "faraday/middleware"
2
-
3
2
  module ZendeskAPI
4
3
  module Middleware
5
4
  # @private
@@ -8,19 +7,37 @@ module ZendeskAPI
8
7
  # @private
9
8
  class Retry < Faraday::Middleware
10
9
  DEFAULT_RETRY_AFTER = 10
11
- ERROR_CODES = [429, 503]
10
+ DEFAULT_ERROR_CODES = [429, 503]
12
11
 
13
12
  def initialize(app, options = {})
14
13
  super(app)
15
14
  @logger = options[:logger]
15
+ @error_codes = options.key?(:retry_codes) && options[:retry_codes] ? options[:retry_codes] : DEFAULT_ERROR_CODES
16
+ @retry_on_exception = options.key?(:retry_on_exception) && options[:retry_on_exception] ? options[:retry_on_exception] : false
16
17
  end
17
18
 
18
19
  def call(env)
19
20
  original_env = env.dup
20
- response = @app.call(env)
21
+ exception_happened = false
22
+ if @retry_on_exception
23
+ begin
24
+ response = @app.call(env)
25
+ rescue StandardError => e
26
+ exception_happened = true
27
+ end
28
+ else
29
+ response = @app.call(env)
30
+ end
31
+
32
+ if exception_happened || @error_codes.include?(response.env[:status])
33
+
34
+ if exception_happened
35
+ seconds_left = DEFAULT_RETRY_AFTER.to_i
36
+ @logger.warn "An exception happened, waiting #{seconds_left} seconds... #{e}" if @logger
37
+ else
38
+ seconds_left = (response.env[:response_headers][:retry_after] || DEFAULT_RETRY_AFTER).to_i
39
+ end
21
40
 
22
- if ERROR_CODES.include?(response.env[:status])
23
- seconds_left = (response.env[:response_headers][:retry_after] || DEFAULT_RETRY_AFTER).to_i
24
41
  @logger.warn "You have been rate limited. Retrying in #{seconds_left} seconds..." if @logger
25
42
 
26
43
  seconds_left.times do |i|
@@ -1,3 +1,3 @@
1
1
  module ZendeskAPI
2
- VERSION = "1.32.0"
2
+ VERSION = "1.33.0"
3
3
  end
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.32.0
4
+ version: 1.33.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Davidovitz
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-08-02 00:00:00.000000000 Z
12
+ date: 2021-08-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -143,9 +143,9 @@ licenses:
143
143
  - Apache-2.0
144
144
  metadata:
145
145
  bug_tracker_uri: https://github.com/zendesk/zendesk_api_client_rb/issues
146
- changelog_uri: https://github.com/zendesk/zendesk_api_client_rb/blob/v1.32.0/CHANGELOG.md
147
- documentation_uri: https://www.rubydoc.info/gems/zendesk_api/1.32.0
148
- source_code_uri: https://github.com/zendesk/zendesk_api_client_rb/tree/v1.32.0
146
+ changelog_uri: https://github.com/zendesk/zendesk_api_client_rb/blob/v1.33.0/CHANGELOG.md
147
+ documentation_uri: https://www.rubydoc.info/gems/zendesk_api/1.33.0
148
+ source_code_uri: https://github.com/zendesk/zendesk_api_client_rb/tree/v1.33.0
149
149
  wiki_uri: https://github.com/zendesk/zendesk_api_client_rb/wiki
150
150
  post_install_message:
151
151
  rdoc_options: []
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
162
  - !ruby/object:Gem::Version
163
163
  version: 1.3.6
164
164
  requirements: []
165
- rubygems_version: 3.0.3
165
+ rubygems_version: 3.1.2
166
166
  signing_key:
167
167
  specification_version: 4
168
168
  summary: Zendesk REST API Client