hubspot-api-client 14.4.0 → 14.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +1 -1
- data/README.md +22 -0
- data/lib/hubspot/discovery/base_api_client.rb +32 -2
- data/lib/hubspot/version.rb +1 -1
- data/spec/discovery/base_api_client_spec.rb +38 -2
- 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: 1d8b685b37efbc5b2140970f793514d482f2c1b3cc1e7da8bb0f22d6814a4e72
|
4
|
+
data.tar.gz: 5db20fc0ccb46c3e201751171f08fc1f052b48053ae64e1ff8a09ab9b6cc1705
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63275e727159844f6841460d15c9a672f103295693bb010a7c0dd8a178bce450e5a1f0995f0f98b93fb6698d920d6d31d385a3b54330f74498dfc59a37dc930d
|
7
|
+
data.tar.gz: e94d656b76d0782d533e7378416652378a36a2194386ac67496fc142a6713293a8ac858ff1e3fb88f7a1017c34080513938a17b2d7fbb61cde3e730f3006792d
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## [14.5.1] - 2022-09-30
|
9
|
+
### Changed
|
10
|
+
|
11
|
+
- with_http methods were added to the discovery classes
|
12
|
+
|
13
|
+
## [14.5.0] - 2022-09-30
|
14
|
+
### Changed
|
15
|
+
|
16
|
+
- handling ApiError with retries
|
17
|
+
|
8
18
|
## [14.4.0] - 2022-09-27
|
9
19
|
### Changed
|
10
20
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -196,6 +196,28 @@ api_client = ::Hubspot::Crm::Companies::ApiClient.new(config)
|
|
196
196
|
basic_api = ::Hubspot::Crm::Companies::BasicApi.new(api_client)
|
197
197
|
```
|
198
198
|
|
199
|
+
for new discovery classes since version 14.5
|
200
|
+
|
201
|
+
Available params:
|
202
|
+
- max_retries (maximum number of retries)
|
203
|
+
- seconds_delay (pause in seconds between retries)
|
204
|
+
- passing a block (block that handles errors occured)
|
205
|
+
|
206
|
+
|
207
|
+
```ruby
|
208
|
+
require 'hubspot-api-client'
|
209
|
+
|
210
|
+
# Set handlers of statuses you want to handle
|
211
|
+
retry_config = {
|
212
|
+
500..530 => { max_retries: 2, seconds_delay: 2 },
|
213
|
+
400 => { max_retries: 3, seconds_delay: 3 }
|
214
|
+
}
|
215
|
+
|
216
|
+
client = Hubspot::Client.new(access_token: 'your_access_token')
|
217
|
+
|
218
|
+
contacts = client.crm.contacts.basic_api.get_page(retry: retry_config) { |error| error.code }
|
219
|
+
```
|
220
|
+
|
199
221
|
### Sample apps
|
200
222
|
|
201
223
|
Please, take a look at our [Sample apps](https://github.com/HubSpot/sample-apps-list)
|
@@ -11,7 +11,10 @@ module Hubspot
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def api_methods
|
14
|
-
api.methods.grep(/with_http_info/).
|
14
|
+
api.methods.grep(/with_http_info/).inject([]) do |methods, method|
|
15
|
+
methods << method
|
16
|
+
methods << method.to_s.gsub('_with_http_info', '').to_sym
|
17
|
+
end
|
15
18
|
end
|
16
19
|
|
17
20
|
def config
|
@@ -59,6 +62,32 @@ module Hubspot
|
|
59
62
|
yield(e)
|
60
63
|
end
|
61
64
|
|
65
|
+
def call_api_with_retry(api_method, params_to_pass, retry_config, &block)
|
66
|
+
call_api_with_rescue(api_method, params_to_pass) do |error|
|
67
|
+
opts = retry_config.detect{ |k,v| k === error.code }&.last
|
68
|
+
retries = opts&.dig(:max_retries) || 5
|
69
|
+
|
70
|
+
block.call(error) unless block.nil?
|
71
|
+
|
72
|
+
response = error
|
73
|
+
|
74
|
+
while retries > 0 && opts
|
75
|
+
sleep opts[:seconds_delay] if opts[:seconds_delay]
|
76
|
+
response = call_api_with_rescue(api_method, params_to_pass) do |e|
|
77
|
+
block.call(e) unless block.nil?
|
78
|
+
e
|
79
|
+
end
|
80
|
+
|
81
|
+
return response unless response.respond_to?(:code)
|
82
|
+
|
83
|
+
opts = retry_config.detect{ |k,v| k === response.code }&.last
|
84
|
+
retries -= 1
|
85
|
+
end
|
86
|
+
|
87
|
+
response
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
62
91
|
def define_methods
|
63
92
|
define_api_methods
|
64
93
|
end
|
@@ -82,7 +111,7 @@ module Hubspot
|
|
82
111
|
|
83
112
|
signature_param_names = signature_params.map { |_, param| param }
|
84
113
|
params_with_defaults.each do |param_name, param_value|
|
85
|
-
params_with_defaults[:opts][param_name] = param_value if !signature_param_names.include?(param_name) && param_name != :body
|
114
|
+
params_with_defaults[:opts][param_name] = param_value if !signature_param_names.include?(param_name) && param_name != :body && param_name != :retry
|
86
115
|
end
|
87
116
|
|
88
117
|
params_to_pass = signature_params.map do |req, param|
|
@@ -94,6 +123,7 @@ module Hubspot
|
|
94
123
|
params_with_defaults[param]
|
95
124
|
end
|
96
125
|
|
126
|
+
return call_api_with_retry(api_method, params_to_pass, params[:retry], &block) unless params[:retry].nil?
|
97
127
|
return call_api_with_rescue(api_method, params_to_pass, &block) unless block.nil?
|
98
128
|
call_api(api_method, params_to_pass)
|
99
129
|
end
|
data/lib/hubspot/version.rb
CHANGED
@@ -29,6 +29,16 @@ describe 'Hubspot::Discovery::BaseApiClient' do
|
|
29
29
|
|
30
30
|
def raise_error_with_http_info
|
31
31
|
end
|
32
|
+
|
33
|
+
def raise_error_on_third_call
|
34
|
+
@calls_count ||= 0
|
35
|
+
@calls_count += 1
|
36
|
+
raise Hubspot::ApiError if @calls_count < 3
|
37
|
+
'ok'
|
38
|
+
end
|
39
|
+
|
40
|
+
def raise_error_on_third_call_with_http_info
|
41
|
+
end
|
32
42
|
end
|
33
43
|
|
34
44
|
class Hubspot::ApiClient
|
@@ -40,6 +50,10 @@ describe 'Hubspot::Discovery::BaseApiClient' do
|
|
40
50
|
def message
|
41
51
|
'test error'
|
42
52
|
end
|
53
|
+
|
54
|
+
def code
|
55
|
+
429
|
56
|
+
end
|
43
57
|
end
|
44
58
|
|
45
59
|
class Hubspot::SimplePublicObjectInput
|
@@ -61,8 +75,8 @@ describe 'Hubspot::Discovery::BaseApiClient' do
|
|
61
75
|
|
62
76
|
it { is_expected.to respond_to(:get) }
|
63
77
|
it { is_expected.to respond_to(:update) }
|
64
|
-
it { is_expected.
|
65
|
-
it { is_expected.
|
78
|
+
it { is_expected.to respond_to(:get_with_http_info) }
|
79
|
+
it { is_expected.to respond_to(:update_with_http_info) }
|
66
80
|
|
67
81
|
describe '#get' do
|
68
82
|
subject(:get) { client.get(params) }
|
@@ -127,4 +141,26 @@ describe 'Hubspot::Discovery::BaseApiClient' do
|
|
127
141
|
|
128
142
|
it { is_expected.to eq('test error') }
|
129
143
|
end
|
144
|
+
|
145
|
+
describe '#raise_error_on_third_call' do
|
146
|
+
subject(:raise_error_on_third_call) { client.raise_error_on_third_call(retry: retry_config) }
|
147
|
+
|
148
|
+
context 'with 2 retries' do
|
149
|
+
let(:retry_config) { {429 => { max_retries: 2 }} }
|
150
|
+
|
151
|
+
it { is_expected.to eq('ok') }
|
152
|
+
|
153
|
+
context 'with range config' do
|
154
|
+
let(:retry_config) { {429..442 => { max_retries: 2 }} }
|
155
|
+
|
156
|
+
it { is_expected.to eq('ok') }
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'with 1 retry' do
|
161
|
+
let(:retry_config) { {429 => { max_retries: 1 }} }
|
162
|
+
|
163
|
+
it { is_expected.to have_attributes(code: 429, message: 'test error') }
|
164
|
+
end
|
165
|
+
end
|
130
166
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hubspot-api-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 14.
|
4
|
+
version: 14.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HubSpot
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|