rdstation-ruby-client 2.8.0 → 2.8.2

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: f9c55a165bdad7cd10471e913f2f531d429e4200c7180b291d55695e5370c585
4
- data.tar.gz: f88b126bc80b46bb3b7ffd5f5d424190251f8d93f3c787aeefb291c6ccdec544
3
+ metadata.gz: 365408ab365bf2acacec98dfa4765b19b642a90a1d6fce3edccd09db8e10e0e3
4
+ data.tar.gz: 9296202984e88f88c38114be6fca87e68f4d87a3693fc7d4f2765c5f63b4821c
5
5
  SHA512:
6
- metadata.gz: bc9a5c11adcc7d45451b2b069b3634c08bb3a47a9af4b473f7d2a39222969764cf80cd746d4d74cf723a6ff46b03f3983a1257f72f5a6a6f88085d2bc7929785
7
- data.tar.gz: 17df3fc0b5abaa008377680764ef12a9fadb99a1d44a1fdbc3d76ea656776f07a51da3a348c00fc2982691b517f89d596d0d6e1fd1ca553bb5fd8e007c80ccac
6
+ metadata.gz: 324fc169085b6b89ef45d509807f4286b8358f8f72e35a944659fef19623bb3280a316d1f3d50178275f2a8c0e39b6d15621ac7e7b01b9fc90ff0bac10601944
7
+ data.tar.gz: 7ea2fc324339bcd68c22a0d9b0560e00fdd2289e7feda605819c22e516c566b6a2d80af0f14ef57b02de044a1f451a159ee727cc17457dd9197e44f255aaa2fc
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 2.8.2
2
+
3
+ - Fix TooManyRequest handler
4
+
5
+ ## 2.8.1
6
+
7
+ - Makes the retryable_request method also retry when a `RDStation::Error::Unauthorized` error happen
8
+
1
9
  ## 2.8.0
2
10
 
3
11
  ### Additions
data/README.md CHANGED
@@ -55,7 +55,7 @@ RDStation.configure do |config|
55
55
  end
56
56
  ```
57
57
 
58
- For details on what `client_id` and `client_secret` are, check the [developers portal](https://developers.rdstation.com/en/authentication).
58
+ For details on what `client_id` and `client_secret` are, check the [developers portal](https://developers.rdstation.com/reference/autenticacao).
59
59
 
60
60
  ### Authentication
61
61
 
@@ -123,7 +123,7 @@ client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'ref
123
123
  client.contacts.by_uuid('uuid')
124
124
  ```
125
125
 
126
- More info: https://developers.rdstation.com/pt-BR/reference/contacts#methodGetDetailsuuid
126
+ More info: https://developers.rdstation.com/reference/get_platform-contacts-identifier-value
127
127
 
128
128
  #### Getting a Contact by Email
129
129
 
@@ -134,7 +134,7 @@ client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'ref
134
134
  client.contacts.by_email('email')
135
135
  ```
136
136
 
137
- More info: https://developers.rdstation.com/pt-BR/reference/contacts#methodGetDetailsemail
137
+ More info: https://developers.rdstation.com/pt-BR/reference/contacts#methodGetDetailsuuid
138
138
 
139
139
  #### Update a Contact by UUID
140
140
 
@@ -160,7 +160,7 @@ Contact Default Parameters
160
160
  - website
161
161
  - tags
162
162
 
163
- More info: https://developers.rdstation.com/pt-BR/reference/contacts#methodPatchDetails
163
+ More info: https://developers.rdstation.com/reference/patch_platform-contacts-identifier-value
164
164
 
165
165
 
166
166
  #### Upsert a Contact by identifier and value
@@ -179,7 +179,7 @@ client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'ref
179
179
  client.contacts.upsert(identifier, identifier_value, contact_info)
180
180
  ```
181
181
 
182
- More info: https://developers.rdstation.com/pt-BR/reference/contacts#methodPatchUpsertDetails
182
+ More info: https://developers.rdstation.com/reference/patch_platform-contacts-identifier-value
183
183
 
184
184
  ### Events
185
185
 
@@ -189,7 +189,7 @@ The events endpoint are responsible for receiving different event types in which
189
189
 
190
190
  It is possible to send default events to RD Station such as conversion events, lifecycle events and won and lost events. Also, RD Station supports the possibility of receiving different event types, for instance, chat events, ecommerce ones and others.
191
191
 
192
- Check the [developers portal](https://developers.rdstation.com/en/reference/events) to learn about the required payload structure and which events are available.
192
+ Check the [developers portal](https://developers.rdstation.com/reference/eventos) to learn about the required payload structure and which events are available.
193
193
 
194
194
  This creates a new event on RDSM:
195
195
 
@@ -201,7 +201,7 @@ client.events.create(payload)
201
201
 
202
202
  ### Fields
203
203
 
204
- Endpoints to [manage Contact Fields](https://developers.rdstation.com/en/reference/fields) information in your RD Station account.
204
+ Endpoints to [manage Contact Fields](https://developers.rdstation.com/reference/get_platform-contacts-fields) information in your RD Station account.
205
205
 
206
206
  #### List all fields
207
207
 
@@ -287,7 +287,7 @@ client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'ref
287
287
  client.webhooks.create(payload)
288
288
  ```
289
289
 
290
- The required strucutre of the payload is [described here](https://developers.rdstation.com/en/reference/webhooks#methodPostDetails).
290
+ The required strucutre of the payload is [described here](https://developers.rdstation.com/reference/post_integrations-webhooks).
291
291
 
292
292
  #### Updating a webhook
293
293
 
@@ -297,7 +297,7 @@ client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'ref
297
297
  client.webhooks.create('WEBHOOK_UUID', payload)
298
298
  ```
299
299
 
300
- The required strucutre of the payload is [described here](https://developers.rdstation.com/en/reference/webhooks#methodPutDetails).
300
+ The required strucutre of the payload is [described here](https://developers.rdstation.com/reference/put_integrations-webhooks-uuid)
301
301
 
302
302
  #### Deleting a webhook
303
303
 
@@ -434,8 +434,7 @@ So, here is a step-by-step guide on how to upgrade your app:
434
434
 
435
435
  ## Maintainers
436
436
 
437
- - [Filipe Nascimento](mailto:filipe.nascimento@resultadosdigitais.com.br)
438
- - [João Hornburg](mailto:joao@rdstation.com)
437
+ - [EcoSystem API Team](mailto:ecosystem@rdstation.com)
439
438
 
440
439
  ## Reference
441
440
 
@@ -29,7 +29,7 @@ module RDStation
29
29
  def single_hash?
30
30
  return unless @errors.is_a?(Hash)
31
31
 
32
- @errors.key?('error')
32
+ @errors.key?('error') || @errors.key?('message')
33
33
  end
34
34
 
35
35
  def flat_hash?
@@ -5,8 +5,9 @@ require_relative './format'
5
5
  module RDStation
6
6
  class Error
7
7
  class Formatter
8
- def initialize(error_response)
8
+ def initialize(error_response, headers = {})
9
9
  @error_response = error_response
10
+ @headers = headers
10
11
  end
11
12
 
12
13
  def to_array
@@ -30,13 +31,13 @@ module RDStation
30
31
 
31
32
  def from_single_hash
32
33
  error_hash = @error_response.dup
33
- error_message = error_hash.delete('error')
34
+ error_message = error_hash.delete('error') || error_hash.delete('message')
34
35
 
35
36
  [
36
37
  {
37
38
  'error_type' => 'TOO_MANY_REQUESTS',
38
39
  'error_message' => error_message,
39
- 'details' => error_hash
40
+ 'details' => error_hash.key?('max') ? error_hash : error_details
40
41
  }
41
42
  ]
42
43
  end
@@ -102,6 +103,14 @@ module RDStation
102
103
  array_of_errors.push(*errors)
103
104
  end
104
105
  end
106
+
107
+ def error_details
108
+ {
109
+ max: @headers.fetch('ratelimit-limit-quotas', 0),
110
+ usage: @headers.fetch('ratelimit-limit-quotas', 0),
111
+ remaining_time: @headers.fetch('retry-after-quotas', 0)
112
+ }
113
+ end
105
114
  end
106
115
  end
107
116
  end
@@ -54,7 +54,7 @@ module RDStation
54
54
  end
55
55
 
56
56
  def error_formatter
57
- @error_formatter = RDStation::Error::Formatter.new(response_errors)
57
+ @error_formatter = RDStation::Error::Formatter.new(response_errors, response.headers)
58
58
  end
59
59
 
60
60
  def additional_error_attributes
@@ -7,7 +7,7 @@ module RDStation
7
7
  retries = 0
8
8
  begin
9
9
  yield authorization
10
- rescue ::RDStation::Error::ExpiredAccessToken => e
10
+ rescue ::RDStation::Error::ExpiredAccessToken, ::RDStation::Error::Unauthorized => e
11
11
  raise if !retry_possible?(authorization) || retries >= MAX_RETRIES
12
12
 
13
13
  retries += 1
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RDStation
4
- VERSION = '2.8.0'
4
+ VERSION = '2.8.2'
5
5
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["paulo.casaretto@resultadosdigitais.com.br"]
11
11
  spec.description = "Ruby API wrapper for RD Station"
12
12
  spec.summary = "Ruby API wrapper for RD Station"
13
- spec.homepage = "http://resultadosdigitais.com.br"
13
+ spec.homepage = "https://github.com/ResultadosDigitais/rdstation-ruby-client"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -218,31 +218,60 @@ RSpec.describe RDStation::Error::Formatter do
218
218
 
219
219
  context 'when receives a single hash of errors' do
220
220
  let(:error_format) { instance_double(RDStation::Error::Format, format: RDStation::Error::Format::SINGLE_HASH) }
221
-
222
- let(:error_response) do
223
- {
224
- 'error' => "'lead_limiter' rate limit exceeded for 86400 second(s) period for key",
225
- 'max' => 24,
226
- 'usage' => 55,
227
- 'remaining_time' => 20745
228
- }
229
- end
230
-
231
221
  let(:error_formatter) { described_class.new(error_response) }
232
222
 
233
- let(:expected_result) do
234
- [
223
+ context 'when response comes from RDSM' do
224
+ let(:error_response) do
235
225
  {
236
- 'error_type' => 'TOO_MANY_REQUESTS',
237
- 'error_message' => "'lead_limiter' rate limit exceeded for 86400 second(s) period for key",
238
- 'details' => { 'max' => 24, 'usage' => 55, 'remaining_time' => 20745 }
226
+ 'error' => "'lead_limiter' rate limit exceeded for 86400 second(s) period for key",
227
+ 'max' => 24,
228
+ 'usage' => 55,
229
+ 'remaining_time' => 20745
239
230
  }
240
- ]
231
+ end
232
+
233
+ let(:expected_result) do
234
+ [
235
+ {
236
+ 'error_type' => 'TOO_MANY_REQUESTS',
237
+ 'error_message' => "'lead_limiter' rate limit exceeded for 86400 second(s) period for key",
238
+ 'details' => { 'max' => 24, 'usage' => 55, 'remaining_time' => 20745 }
239
+ }
240
+ ]
241
+ end
242
+
243
+ it 'returns an array of errors' do
244
+ result = error_formatter.to_array
245
+ expect(result).to eq(expected_result)
246
+ end
241
247
  end
242
248
 
243
- it 'returns an array of errors' do
244
- result = error_formatter.to_array
245
- expect(result).to eq(expected_result)
249
+ context 'when response comes from API Gateway' do
250
+ let(:error_formatter) { described_class.new(error_response, response_headers) }
251
+ let(:error_response) do
252
+ { 'message' => 'API rate limit exceeded' }
253
+ end
254
+ let(:response_headers) do
255
+ {
256
+ 'ratelimit-limit-quotas' => 120,
257
+ 'retry-after-quotas' => 20745
258
+ }
259
+ end
260
+
261
+ let(:expected_result) do
262
+ [
263
+ {
264
+ 'error_type' => 'TOO_MANY_REQUESTS',
265
+ 'error_message' => 'API rate limit exceeded',
266
+ 'details' => { max: 120, usage: 120, remaining_time: 20745 }
267
+ }
268
+ ]
269
+ end
270
+
271
+ it 'returns an array of errors' do
272
+ result = error_formatter.to_array
273
+ expect(result).to eq(expected_result)
274
+ end
246
275
  end
247
276
  end
248
277
  end
@@ -56,7 +56,7 @@ RSpec.describe RDStation::RetryableRequest do
56
56
  and_return(new_credentials)
57
57
  end
58
58
 
59
- it 'refreshes the access_token and retries the request' do
59
+ it 'refreshes the access_token and retries the request when an ExpiredAccessToken error happen' do
60
60
  dummy_request = double("dummy_request")
61
61
  expect(dummy_request).to receive(:call).twice do |auth|
62
62
  expired_token = ::RDStation::Error::ExpiredAccessToken.new({'error_message' => 'x'})
@@ -74,6 +74,24 @@ RSpec.describe RDStation::RetryableRequest do
74
74
  end.not_to raise_error
75
75
  end
76
76
 
77
+ it 'refreshes the access_token and retries the request an Unauthorized error happen' do
78
+ dummy_request = double("dummy_request")
79
+ expect(dummy_request).to receive(:call).twice do |auth|
80
+ expired_token = ::RDStation::Error::Unauthorized.new({'error_message' => 'x'})
81
+ raise expired_token unless auth.access_token == new_access_token
82
+ end
83
+
84
+ expect(RDStation.configuration.access_token_refresh_callback)
85
+ .to receive(:call)
86
+ .once do |authorization|
87
+ expect(authorization.access_token).to eq new_access_token
88
+ end
89
+
90
+ expect do
91
+ subject.retryable_request(auth) { |yielded_auth| dummy_request.call(yielded_auth) }
92
+ end.not_to raise_error
93
+ end
94
+
77
95
  context 'and keeps raising retryable exception event after token refreshed' do
78
96
  it 'retries only once' do
79
97
  dummy_request = double("dummy_request")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdstation-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.0
4
+ version: 2.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo L F Casaretto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-18 00:00:00.000000000 Z
11
+ date: 2023-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -197,7 +197,7 @@ files:
197
197
  - spec/lib/rdstation/webhooks_spec.rb
198
198
  - spec/lib/rdstation_spec.rb
199
199
  - spec/spec_helper.rb
200
- homepage: http://resultadosdigitais.com.br
200
+ homepage: https://github.com/ResultadosDigitais/rdstation-ruby-client
201
201
  licenses:
202
202
  - MIT
203
203
  metadata: {}