basecrm 1.3.10 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/basecrm/configuration.rb +4 -0
- data/lib/basecrm/http_client.rb +9 -1
- data/lib/basecrm/version.rb +1 -1
- data/spec/http_client_spec.rb +15 -0
- data/spec/support/client_helpers.rb +4 -0
- metadata +48 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cbaf008b35c02a9330bcc937cce7b22193ae82a12aedfbdad924701490227c0
|
4
|
+
data.tar.gz: fed5a5badb4163c281be2f271503507f17cc385bca983e9489519f074a8d9da6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d70a8c2558153ba60f3af7fd27d8ecd25ee116c7f21a9438c1785e80668761c1773a5fb8b2794219c9a5a11b39800363e548971d6d25016aa468c6d1e0260cd
|
7
|
+
data.tar.gz: 595a8e756d8b3638901165380d07e491f6f65c3ec6e181dcb7295a92487a4393e4db48711ed3fa99f7a634daf4af1e2580af0de0c2814f8c40de74bc6897a85f
|
data/README.md
CHANGED
@@ -49,6 +49,8 @@ The following options are available while instantiating a client:
|
|
49
49
|
* __timeout__: Request timeout
|
50
50
|
* __verbose__: Verbose/debug mode
|
51
51
|
* __logger__: Logger used in verbose mode
|
52
|
+
* __max_retry__: Number of retries on failed requests. Passed to Faraday
|
53
|
+
* __retry_statuses__: By default only timeout error will be retries. This allows to retry on specific HTTP statuses. Passed to Faraday
|
52
54
|
|
53
55
|
### Architecture
|
54
56
|
|
@@ -7,6 +7,8 @@ module BaseCRM
|
|
7
7
|
attr_reader :user_agent
|
8
8
|
attr_reader :timeout
|
9
9
|
attr_reader :verify_ssl
|
10
|
+
attr_reader :max_retry
|
11
|
+
attr_reader :retry_statuses
|
10
12
|
|
11
13
|
attr_reader :logger, :verbose
|
12
14
|
alias_method :debug?, :verbose
|
@@ -19,6 +21,8 @@ module BaseCRM
|
|
19
21
|
@verbose = !!options[:verbose]
|
20
22
|
@timeout = options[:timeout] || 30
|
21
23
|
@verify_ssl = options.fetch(:verify_ssl, true)
|
24
|
+
@max_retry = options[:max_retry]
|
25
|
+
@retry_statuses = options[:retry_statuses]
|
22
26
|
end
|
23
27
|
|
24
28
|
def validate!
|
data/lib/basecrm/http_client.rb
CHANGED
@@ -22,6 +22,7 @@ module BaseCRM
|
|
22
22
|
options[:ssl] = { verify: false } unless config.verify_ssl
|
23
23
|
|
24
24
|
@client = Faraday.new(config.base_url, options) do |faraday|
|
25
|
+
faraday.request :retry, retry_options
|
25
26
|
faraday.use BaseCRM::Middlewares::OAuthBearerToken, config.access_token
|
26
27
|
faraday.use BaseCRM::Middlewares::RaiseError
|
27
28
|
faraday.response :logger, config.logger if config.debug?
|
@@ -74,7 +75,7 @@ module BaseCRM
|
|
74
75
|
body = extract_body(res)
|
75
76
|
@config.logger.debug body if @config.debug? && body && @config.logger
|
76
77
|
[res.status, res.headers, body]
|
77
|
-
rescue Faraday::
|
78
|
+
rescue Faraday::ConnectionFailed => e
|
78
79
|
raise ConnectionError, e.message
|
79
80
|
end
|
80
81
|
|
@@ -89,5 +90,12 @@ module BaseCRM
|
|
89
90
|
content_type = res.headers['Content-Type']
|
90
91
|
content_type && content_type.include?('json') ? JSON.parse(res.body, symbolize_names: true) : res.body
|
91
92
|
end
|
93
|
+
|
94
|
+
def retry_options
|
95
|
+
retry_options = {}
|
96
|
+
retry_options[:max] = @config.max_retry if @config.max_retry
|
97
|
+
retry_options[:retry_statuses] = @config.retry_statuses if @config.retry_statuses
|
98
|
+
retry_options
|
99
|
+
end
|
92
100
|
end
|
93
101
|
end
|
data/lib/basecrm/version.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BaseCRM::HttpClient do
|
4
|
+
describe 'Retries' do
|
5
|
+
let(:statuses_to_retry) { [503] }
|
6
|
+
let(:max_retry) { 3 }
|
7
|
+
subject(:client_with_retry) { client_with_basic_retry(max_retry: max_retry, on_statuses: statuses_to_retry) }
|
8
|
+
|
9
|
+
it "should pass retry statues to Faraday and do a valid request" do
|
10
|
+
expect(client_with_retry.http_client.client.app.options.retry_statuses).to match_array(statuses_to_retry)
|
11
|
+
expect(client_with_retry.http_client.client.app.options.max).to eq(max_retry)
|
12
|
+
expect(client_with_retry.accounts.self).to be_instance_of BaseCRM::Account
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -3,6 +3,10 @@ module ClientHelpers
|
|
3
3
|
@client ||= BaseCRM::Client.new(access_token: access_token, base_url: base_url)
|
4
4
|
end
|
5
5
|
|
6
|
+
def client_with_basic_retry(max_retry: 1, on_statuses: [])
|
7
|
+
@client_with_basic_retry ||= BaseCRM::Client.new(access_token: access_token, base_url: base_url, max_retry: max_retry, retry_statuses: on_statuses)
|
8
|
+
end
|
9
|
+
|
6
10
|
def access_token
|
7
11
|
@access_token ||= ENV.fetch("BASECRM_ACCESS_TOKEN") { raise '"BASECRM_ACCESS_TOKEN" has not been found.' }
|
8
12
|
end
|
metadata
CHANGED
@@ -1,35 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: basecrm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zendesk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.9.0
|
20
17
|
- - "~>"
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version: '0
|
19
|
+
version: '1.0'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 0.9.0
|
30
24
|
- - "~>"
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version: '0
|
26
|
+
version: '1.0'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: json
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -211,6 +205,7 @@ files:
|
|
211
205
|
- spec/factories/tag.rb
|
212
206
|
- spec/factories/task.rb
|
213
207
|
- spec/factories/text_message.rb
|
208
|
+
- spec/http_client_spec.rb
|
214
209
|
- spec/middlewares/raise_error_spec.rb
|
215
210
|
- spec/models/sync_meta_spec.rb
|
216
211
|
- spec/services/accounts_service_spec.rb
|
@@ -267,54 +262,55 @@ signing_key:
|
|
267
262
|
specification_version: 4
|
268
263
|
summary: Zendesk Sell Official API V2 library client for ruby
|
269
264
|
test_files:
|
270
|
-
- spec/models/sync_meta_spec.rb
|
271
|
-
- spec/factories/associated_contact.rb
|
272
|
-
- spec/factories/tag.rb
|
273
|
-
- spec/factories/contact.rb
|
274
|
-
- spec/factories/deal_source.rb
|
275
|
-
- spec/factories/lead_unqualified_reason.rb
|
276
|
-
- spec/factories/loss_reason.rb
|
277
|
-
- spec/factories/line_item.rb
|
278
|
-
- spec/factories/product.rb
|
279
|
-
- spec/factories/deal_unqualified_reason.rb
|
280
|
-
- spec/factories/order.rb
|
281
|
-
- spec/factories/source.rb
|
282
|
-
- spec/factories/task.rb
|
283
|
-
- spec/factories/lead_source.rb
|
284
|
-
- spec/factories/text_message.rb
|
285
|
-
- spec/factories/call.rb
|
286
|
-
- spec/factories/deal.rb
|
287
|
-
- spec/factories/note.rb
|
288
|
-
- spec/factories/lead.rb
|
289
|
-
- spec/basecrm/sync_spec.rb
|
290
|
-
- spec/support/client_helpers.rb
|
291
265
|
- spec/spec_helper.rb
|
292
|
-
- spec/
|
293
|
-
- spec/
|
294
|
-
- spec/utils/coercion.rb
|
295
|
-
- spec/services/line_items_service_spec.rb
|
296
|
-
- spec/services/deal_unqualified_reasons_service_spec.rb
|
266
|
+
- spec/services/calls_service_spec.rb
|
267
|
+
- spec/services/deals_service_spec.rb
|
297
268
|
- spec/services/stages_service_spec.rb
|
269
|
+
- spec/services/users_service_spec.rb
|
270
|
+
- spec/services/tasks_service_spec.rb
|
271
|
+
- spec/services/lead_unqualified_reasons_service_spec.rb
|
272
|
+
- spec/services/deal_sources_service_spec.rb
|
273
|
+
- spec/services/products_service_spec.rb
|
274
|
+
- spec/services/accounts_service_spec.rb
|
298
275
|
- spec/services/call_outcomes_service_spec.rb
|
299
|
-
- spec/services/lead_sources_service_spec.rb
|
300
276
|
- spec/services/pipelines_service_spec.rb
|
301
|
-
- spec/services/lead_unqualified_reasons_service_spec.rb
|
302
|
-
- spec/services/text_messages_service_spec.rb
|
303
|
-
- spec/services/sources_service_spec.rb
|
304
277
|
- spec/services/contacts_service_spec.rb
|
305
|
-
- spec/services/loss_reasons_service_spec.rb
|
306
|
-
- spec/services/deals_service_spec.rb
|
307
|
-
- spec/services/calls_service_spec.rb
|
308
|
-
- spec/services/sync_service_spec.rb
|
309
|
-
- spec/services/associated_contacts_service_spec.rb
|
310
278
|
- spec/services/orders_service_spec.rb
|
279
|
+
- spec/services/visits_service_spec.rb
|
311
280
|
- spec/services/leads_service_spec.rb
|
312
|
-
- spec/services/
|
313
|
-
- spec/services/
|
314
|
-
- spec/services/
|
315
|
-
- spec/services/accounts_service_spec.rb
|
281
|
+
- spec/services/sources_service_spec.rb
|
282
|
+
- spec/services/lead_sources_service_spec.rb
|
283
|
+
- spec/services/sync_service_spec.rb
|
316
284
|
- spec/services/visit_outcomes_service_spec.rb
|
317
|
-
- spec/services/
|
318
|
-
- spec/services/
|
285
|
+
- spec/services/loss_reasons_service_spec.rb
|
286
|
+
- spec/services/associated_contacts_service_spec.rb
|
287
|
+
- spec/services/notes_service_spec.rb
|
288
|
+
- spec/services/deal_unqualified_reasons_service_spec.rb
|
319
289
|
- spec/services/tags_service_spec.rb
|
320
|
-
- spec/services/
|
290
|
+
- spec/services/line_items_service_spec.rb
|
291
|
+
- spec/services/text_messages_service_spec.rb
|
292
|
+
- spec/basecrm/sync_spec.rb
|
293
|
+
- spec/support/client_helpers.rb
|
294
|
+
- spec/factories/lead_unqualified_reason.rb
|
295
|
+
- spec/factories/order.rb
|
296
|
+
- spec/factories/tag.rb
|
297
|
+
- spec/factories/deal.rb
|
298
|
+
- spec/factories/source.rb
|
299
|
+
- spec/factories/text_message.rb
|
300
|
+
- spec/factories/task.rb
|
301
|
+
- spec/factories/contact.rb
|
302
|
+
- spec/factories/associated_contact.rb
|
303
|
+
- spec/factories/line_item.rb
|
304
|
+
- spec/factories/deal_source.rb
|
305
|
+
- spec/factories/deal_unqualified_reason.rb
|
306
|
+
- spec/factories/call.rb
|
307
|
+
- spec/factories/note.rb
|
308
|
+
- spec/factories/lead_source.rb
|
309
|
+
- spec/factories/loss_reason.rb
|
310
|
+
- spec/factories/product.rb
|
311
|
+
- spec/factories/lead.rb
|
312
|
+
- spec/utils/coercion.rb
|
313
|
+
- spec/utils/coercion_spec.rb
|
314
|
+
- spec/models/sync_meta_spec.rb
|
315
|
+
- spec/http_client_spec.rb
|
316
|
+
- spec/middlewares/raise_error_spec.rb
|