zendesk_api 1.30.0 → 1.34.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: 793f89bec6ccc7c03d9fe870346da6f50dc0dd8cde3b46aca5b37cc6504adb3a
4
- data.tar.gz: a03de27f833f3d9395bd44f574e70f8c3d9c6e10a06f4b89f71c2e393c0ea1a8
3
+ metadata.gz: 8e138461b731cb580a6e11cd2a67a5864e909d13da934cb42623debe9a4fda60
4
+ data.tar.gz: f3ba385fd7563be3e6cce8afc22576a9fd81cd358cbc70635fdf2a30aee27e5b
5
5
  SHA512:
6
- metadata.gz: e4426a2dfad01605c661fbe4f71312e86bc444479dc4c293876273c5003169d32774e79b55e2f7c67b54a7cbb48ce0feb32887484f02f73da536c366dc8ac5c7
7
- data.tar.gz: f561f3b726990c014aeaa095c21f6065063100bf033c3ce1fafaaa8fa062240dbe068960d9482cab632579e8890986e24db205bdcf40f1034468d94db37b7864
6
+ metadata.gz: 61c2fcf9df4c4a6ffc77042ee63b0cfc11895619083b5e9d80a7c569aac87478a6aa989f4aa8305c853226e260e64741f536247f9dec58237d333571bd1bf3c0
7
+ data.tar.gz: 78ee9bb11b950f2abcecd4b792199ffbf7b4cbfe6aef5bb9026dd371bf0f2a27a7b955250f88f9188938ed4e8a51a0310cb225f505fcd75a9cdd2ffcf4c8906c
@@ -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
@@ -198,7 +198,7 @@ module ZendeskAPI
198
198
  end
199
199
 
200
200
  def check_url
201
- if !config.allow_http && config.url !~ /^https/
201
+ if !config.allow_http && !config.url.start_with?('https://')
202
202
  raise ArgumentError, "zendesk_api is ssl only; url must begin with https://"
203
203
  end
204
204
  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
@@ -20,7 +20,7 @@ module ZendeskAPI
20
20
  super
21
21
 
22
22
  if response[:body].is_a?(Hash)
23
- @errors = response[:body]["details"] || response[:body]["description"]
23
+ @errors = response[:body]["details"] || generate_error_msg(response[:body])
24
24
  end
25
25
 
26
26
  @errors ||= {}
@@ -29,6 +29,17 @@ module ZendeskAPI
29
29
  def to_s
30
30
  "#{self.class.name}: #{@errors}"
31
31
  end
32
+
33
+ private
34
+
35
+ def generate_error_msg(response_body)
36
+ return unless response_body["description"] || response_body["message"]
37
+
38
+ [
39
+ response_body["description"],
40
+ response_body["message"]
41
+ ].compact.join(" - ")
42
+ end
32
43
  end
33
44
 
34
45
  class NetworkError < ClientError; end
@@ -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|
@@ -5,7 +5,6 @@ module ZendeskAPI
5
5
  class User < Resource; end
6
6
  class UserRelated < DataResource; end
7
7
  class Category < Resource; end
8
- class OrganizationMembership < ReadResource; end
9
8
  class OrganizationSubscription < ReadResource; end
10
9
 
11
10
  # @internal Begin actual Resource definitions
@@ -126,6 +125,10 @@ module ZendeskAPI
126
125
 
127
126
  class OrganizationRelated < DataResource; end
128
127
 
128
+ class OrganizationMembership < ReadResource
129
+ extend CreateOrUpdate
130
+ end
131
+
129
132
  class Organization < Resource
130
133
  extend CreateMany
131
134
  extend CreateOrUpdate
@@ -1,3 +1,3 @@
1
1
  module ZendeskAPI
2
- VERSION = "1.30.0"
2
+ VERSION = "1.34.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.30.0
4
+ version: 1.34.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-06-10 00:00:00.000000000 Z
12
+ date: 2022-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -40,7 +40,7 @@ dependencies:
40
40
  version: 3.5.2
41
41
  - - "<"
42
42
  - !ruby/object:Gem::Version
43
- version: 5.0.0
43
+ version: 6.0.0
44
44
  type: :runtime
45
45
  prerelease: false
46
46
  version_requirements: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  version: 3.5.2
51
51
  - - "<"
52
52
  - !ruby/object:Gem::Version
53
- version: 5.0.0
53
+ version: 6.0.0
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: inflection
56
56
  requirement: !ruby/object:Gem::Requirement
@@ -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.30.0/CHANGELOG.md
147
- documentation_uri: https://www.rubydoc.info/gems/zendesk_api/1.30.0
148
- source_code_uri: https://github.com/zendesk/zendesk_api_client_rb/tree/v1.30.0
146
+ changelog_uri: https://github.com/zendesk/zendesk_api_client_rb/blob/v1.34.0/CHANGELOG.md
147
+ documentation_uri: https://www.rubydoc.info/gems/zendesk_api/1.34.0
148
+ source_code_uri: https://github.com/zendesk/zendesk_api_client_rb/tree/v1.34.0
149
149
  wiki_uri: https://github.com/zendesk/zendesk_api_client_rb/wiki
150
150
  post_install_message:
151
151
  rdoc_options: []