rdstation-ruby-client 2.8.1 → 2.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +22 -12
- data/lib/rdstation/account.rb +25 -0
- data/lib/rdstation/client.rb +4 -0
- data/lib/rdstation/error/format.rb +1 -1
- data/lib/rdstation/error/formatter.rb +12 -3
- data/lib/rdstation/error_handler.rb +1 -1
- data/lib/rdstation/version.rb +1 -1
- data/lib/rdstation-ruby-client.rb +1 -0
- data/rdstation-ruby-client.gemspec +1 -1
- data/spec/lib/rdstation/account_spec.rb +57 -0
- data/spec/lib/rdstation/client_spec.rb +5 -0
- data/spec/lib/rdstation/error/formatter_spec.rb +48 -19
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3de60aebf7582be38403250a4d049f3428241b66a18acb085cdd71f542cb8a0
|
4
|
+
data.tar.gz: '0829e4b85cae5dd80c64395f6e460ebb315fee92853d81a5feb263adaa2e3efe'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1206caba197401915572f9bb66dd2c45ad2c019d8ce5899d0667753043066cce96edfc39207054549de900cf57e3eb1179c6e4bcf58bed5bac459ef37d49cc12
|
7
|
+
data.tar.gz: c27a1e2c5d5d3ef4ddc3cfc1f0369f9be0cf09c040147fe1409bcc6d77a3c4d2fc7f697f3d40db2f83fbc2a0c79cad61e9378d4cbc3eedc9df0fe9ec9eaa91ef
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
## 2.9.0
|
2
|
+
|
3
|
+
### Additions
|
4
|
+
|
5
|
+
#### 1. New Account client
|
6
|
+
|
7
|
+
Usage example:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
11
|
+
client.account.info
|
12
|
+
```
|
13
|
+
|
14
|
+
|
15
|
+
## 2.8.2
|
16
|
+
|
17
|
+
- Fix TooManyRequest handler
|
18
|
+
|
1
19
|
## 2.8.1
|
2
20
|
|
3
21
|
- Makes the retryable_request method also retry when a `RDStation::Error::Unauthorized` error happen
|
data/README.md
CHANGED
@@ -20,7 +20,8 @@ Upgrading? Check the [migration guide](#Migration-guide) before bumping to a new
|
|
20
20
|
8. [Segmentations](#Segmentations)
|
21
21
|
9. [Analytics](#Analytics)
|
22
22
|
10.[LandingPages](#LandingPages)
|
23
|
-
11.[
|
23
|
+
11.[Account](#Account)
|
24
|
+
12.[Errors](#Errors)
|
24
25
|
3. [Changelog](#Changelog)
|
25
26
|
4. [Migration guide](#Migration-guide)
|
26
27
|
1. [Upgrading from 1.2.x to 2.0.0](#Upgrading-from-1.2.x-to-2.0.0)
|
@@ -55,7 +56,7 @@ RDStation.configure do |config|
|
|
55
56
|
end
|
56
57
|
```
|
57
58
|
|
58
|
-
For details on what `client_id` and `client_secret` are, check the [developers portal](https://developers.rdstation.com/
|
59
|
+
For details on what `client_id` and `client_secret` are, check the [developers portal](https://developers.rdstation.com/reference/autenticacao).
|
59
60
|
|
60
61
|
### Authentication
|
61
62
|
|
@@ -123,7 +124,7 @@ client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'ref
|
|
123
124
|
client.contacts.by_uuid('uuid')
|
124
125
|
```
|
125
126
|
|
126
|
-
More info: https://developers.rdstation.com/
|
127
|
+
More info: https://developers.rdstation.com/reference/get_platform-contacts-identifier-value
|
127
128
|
|
128
129
|
#### Getting a Contact by Email
|
129
130
|
|
@@ -134,7 +135,7 @@ client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'ref
|
|
134
135
|
client.contacts.by_email('email')
|
135
136
|
```
|
136
137
|
|
137
|
-
More info:
|
138
|
+
More info: https://developers.rdstation.com/pt-BR/reference/contacts#methodGetDetailsuuid
|
138
139
|
|
139
140
|
#### Update a Contact by UUID
|
140
141
|
|
@@ -160,7 +161,7 @@ Contact Default Parameters
|
|
160
161
|
- website
|
161
162
|
- tags
|
162
163
|
|
163
|
-
More info: https://developers.rdstation.com/
|
164
|
+
More info: https://developers.rdstation.com/reference/patch_platform-contacts-identifier-value
|
164
165
|
|
165
166
|
|
166
167
|
#### Upsert a Contact by identifier and value
|
@@ -179,7 +180,7 @@ client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'ref
|
|
179
180
|
client.contacts.upsert(identifier, identifier_value, contact_info)
|
180
181
|
```
|
181
182
|
|
182
|
-
More info: https://developers.rdstation.com/
|
183
|
+
More info: https://developers.rdstation.com/reference/patch_platform-contacts-identifier-value
|
183
184
|
|
184
185
|
### Events
|
185
186
|
|
@@ -189,7 +190,7 @@ The events endpoint are responsible for receiving different event types in which
|
|
189
190
|
|
190
191
|
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
192
|
|
192
|
-
Check the [developers portal](https://developers.rdstation.com/
|
193
|
+
Check the [developers portal](https://developers.rdstation.com/reference/eventos) to learn about the required payload structure and which events are available.
|
193
194
|
|
194
195
|
This creates a new event on RDSM:
|
195
196
|
|
@@ -201,7 +202,7 @@ client.events.create(payload)
|
|
201
202
|
|
202
203
|
### Fields
|
203
204
|
|
204
|
-
Endpoints to [manage Contact Fields](https://developers.rdstation.com/
|
205
|
+
Endpoints to [manage Contact Fields](https://developers.rdstation.com/reference/get_platform-contacts-fields) information in your RD Station account.
|
205
206
|
|
206
207
|
#### List all fields
|
207
208
|
|
@@ -287,7 +288,7 @@ client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'ref
|
|
287
288
|
client.webhooks.create(payload)
|
288
289
|
```
|
289
290
|
|
290
|
-
The required strucutre of the payload is [described here](https://developers.rdstation.com/
|
291
|
+
The required strucutre of the payload is [described here](https://developers.rdstation.com/reference/post_integrations-webhooks).
|
291
292
|
|
292
293
|
#### Updating a webhook
|
293
294
|
|
@@ -297,7 +298,7 @@ client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'ref
|
|
297
298
|
client.webhooks.create('WEBHOOK_UUID', payload)
|
298
299
|
```
|
299
300
|
|
300
|
-
The required strucutre of the payload is [described here](https://developers.rdstation.com/
|
301
|
+
The required strucutre of the payload is [described here](https://developers.rdstation.com/reference/put_integrations-webhooks-uuid)
|
301
302
|
|
302
303
|
#### Deleting a webhook
|
303
304
|
|
@@ -377,6 +378,16 @@ client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'ref
|
|
377
378
|
client.landing_pages.all
|
378
379
|
```
|
379
380
|
|
381
|
+
### Account
|
382
|
+
|
383
|
+
Returns the account information.
|
384
|
+
|
385
|
+
```ruby
|
386
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
387
|
+
client.account.info
|
388
|
+
=> {"name"=>"www.rdstation.com"}
|
389
|
+
```
|
390
|
+
|
380
391
|
### Errors
|
381
392
|
|
382
393
|
Each endpoint may raise errors accoording to the HTTP response code from RDStation:
|
@@ -434,8 +445,7 @@ So, here is a step-by-step guide on how to upgrade your app:
|
|
434
445
|
|
435
446
|
## Maintainers
|
436
447
|
|
437
|
-
- [
|
438
|
-
- [João Hornburg](mailto:joao@rdstation.com)
|
448
|
+
- [EcoSystem API Team](mailto:ecosystem@rdstation.com)
|
439
449
|
|
440
450
|
## Reference
|
441
451
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RDStation
|
4
|
+
class Account
|
5
|
+
include HTTParty
|
6
|
+
include ::RDStation::RetryableRequest
|
7
|
+
|
8
|
+
def initialize(authorization:)
|
9
|
+
@authorization = authorization
|
10
|
+
end
|
11
|
+
|
12
|
+
def info
|
13
|
+
retryable_request(@authorization) do |authorization|
|
14
|
+
response = self.class.get(base_url, headers: authorization.headers)
|
15
|
+
ApiResponse.build(response)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def base_url(_path = '')
|
22
|
+
"#{RDStation.host}/marketing/account_info"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/rdstation/client.rb
CHANGED
@@ -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
|
data/lib/rdstation/version.rb
CHANGED
@@ -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 = "
|
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($/)
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe RDStation::Account do
|
4
|
+
let(:client) do
|
5
|
+
described_class.new(authorization: RDStation::Authorization.new(access_token: 'access_token'))
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:endpoint) { 'https://api.rd.services/marketing/account_info' }
|
9
|
+
|
10
|
+
let(:headers) do
|
11
|
+
{
|
12
|
+
'Authorization' => 'Bearer access_token',
|
13
|
+
'Content-Type' => 'application/json'
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:error_handler) do
|
18
|
+
instance_double(RDStation::ErrorHandler, raise_error: 'mock raised errors')
|
19
|
+
end
|
20
|
+
|
21
|
+
before do
|
22
|
+
allow(RDStation::ErrorHandler).to receive(:new).and_return(error_handler)
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#info' do
|
26
|
+
it 'calls retryable_request' do
|
27
|
+
expect(client).to receive(:retryable_request)
|
28
|
+
client.info
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when the request is successful' do
|
32
|
+
before do
|
33
|
+
stub_request(:get, endpoint)
|
34
|
+
.with(headers: headers)
|
35
|
+
.to_return(status: 200, body: {name: 'www.rdstation.com'}.to_json)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'return RDSM account information' do
|
39
|
+
response = client.info
|
40
|
+
expect(response).to eq({ 'name' => 'www.rdstation.com'})
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when the response contains errors' do
|
45
|
+
before do
|
46
|
+
stub_request(:get, endpoint)
|
47
|
+
.with(headers: headers)
|
48
|
+
.to_return(status: 404, body: { 'errors' => ['not found'] }.to_json)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'calls raise_error on error handler' do
|
52
|
+
client.info
|
53
|
+
expect(error_handler).to have_received(:raise_error)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -27,6 +27,11 @@ RSpec.describe RDStation::Client do
|
|
27
27
|
expect(RDStation::Webhooks).to receive(:new).with({ authorization: mock_authorization }).and_call_original
|
28
28
|
expect(client.webhooks).to be_instance_of RDStation::Webhooks
|
29
29
|
end
|
30
|
+
|
31
|
+
it 'returns Account endpoint' do
|
32
|
+
expect(RDStation::Account).to receive(:new).with({ authorization: mock_authorization }).and_call_original
|
33
|
+
expect(client.account).to be_instance_of RDStation::Account
|
34
|
+
end
|
30
35
|
end
|
31
36
|
|
32
37
|
context "when access_token isn't given" do
|
@@ -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
|
-
|
234
|
-
|
223
|
+
context 'when response comes from RDSM' do
|
224
|
+
let(:error_response) do
|
235
225
|
{
|
236
|
-
'
|
237
|
-
'
|
238
|
-
'
|
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
|
-
|
244
|
-
|
245
|
-
|
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
|
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.
|
4
|
+
version: 2.9.0
|
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:
|
11
|
+
date: 2023-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- Rakefile
|
142
142
|
- lib/rdstation-ruby-client.rb
|
143
143
|
- lib/rdstation.rb
|
144
|
+
- lib/rdstation/account.rb
|
144
145
|
- lib/rdstation/analytics.rb
|
145
146
|
- lib/rdstation/api_response.rb
|
146
147
|
- lib/rdstation/authentication.rb
|
@@ -170,6 +171,7 @@ files:
|
|
170
171
|
- lib/rdstation/webhooks.rb
|
171
172
|
- rdstation-ruby-client.gemspec
|
172
173
|
- spec/lib/rdstation-ruby-client_spec.rb
|
174
|
+
- spec/lib/rdstation/account_spec.rb
|
173
175
|
- spec/lib/rdstation/analytics_spec.rb
|
174
176
|
- spec/lib/rdstation/api_response_spec.rb
|
175
177
|
- spec/lib/rdstation/authentication_spec.rb
|
@@ -197,7 +199,7 @@ files:
|
|
197
199
|
- spec/lib/rdstation/webhooks_spec.rb
|
198
200
|
- spec/lib/rdstation_spec.rb
|
199
201
|
- spec/spec_helper.rb
|
200
|
-
homepage:
|
202
|
+
homepage: https://github.com/ResultadosDigitais/rdstation-ruby-client
|
201
203
|
licenses:
|
202
204
|
- MIT
|
203
205
|
metadata: {}
|
@@ -222,6 +224,7 @@ specification_version: 4
|
|
222
224
|
summary: Ruby API wrapper for RD Station
|
223
225
|
test_files:
|
224
226
|
- spec/lib/rdstation-ruby-client_spec.rb
|
227
|
+
- spec/lib/rdstation/account_spec.rb
|
225
228
|
- spec/lib/rdstation/analytics_spec.rb
|
226
229
|
- spec/lib/rdstation/api_response_spec.rb
|
227
230
|
- spec/lib/rdstation/authentication_spec.rb
|