rdstation-ruby-client 2.5.2 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +22 -0
- data/README.md +43 -1
- data/lib/rdstation/authentication.rb +2 -4
- data/lib/rdstation/client.rb +8 -0
- data/lib/rdstation/emails.rb +32 -0
- data/lib/rdstation/events.rb +9 -3
- data/lib/rdstation/fields.rb +5 -6
- data/lib/rdstation/segmentations.rb +30 -0
- data/lib/rdstation/version.rb +3 -1
- data/lib/rdstation-ruby-client.rb +2 -0
- data/spec/lib/rdstation/emails_spec.rb +165 -0
- data/spec/lib/rdstation/fields_spec.rb +9 -1
- data/spec/lib/rdstation/segmentations_spec.rb +138 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eeaf9150717e1481fce77233ad549b2cd9a7d573f7c9f1e180a2c228c05ef374
|
4
|
+
data.tar.gz: 79c04cb05e857cadb56d6b201ac12e22c30c35920fb1ddf473ea30700168c4fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7e70fb319205bc1ae61cb7567e82f6c7dae6050fedb403689589ea1b19dc9ca8d8699daa0287bb38f12797c41cb6bfbe20bf832989f2020c70673e4e9f655d9
|
7
|
+
data.tar.gz: 4ab3bc836989453fd41cedebd1fc3aea0d6720fb390b62be913af5029e619c61484cf8c29f20c5228f050304d7cb4dcb641404fb899cdcd1878c0028f1b42fa4
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
## 2.6.0
|
2
|
+
|
3
|
+
### Additions
|
4
|
+
|
5
|
+
#### 1. New Emails client
|
6
|
+
|
7
|
+
Usage example:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
11
|
+
client.emails.all
|
12
|
+
```
|
13
|
+
|
14
|
+
#### 2. New Segmentations client
|
15
|
+
|
16
|
+
Usage example:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
20
|
+
client.segmentations.all
|
21
|
+
```
|
22
|
+
|
1
23
|
## 2.5.1
|
2
24
|
|
3
25
|
- Fixed checking `empty?` for nil values inside of InvalidRefreshToken class
|
data/README.md
CHANGED
@@ -16,7 +16,9 @@ Upgrading? Check the [migration guide](#Migration-guide) before bumping to a new
|
|
16
16
|
4. [Events](#Events)
|
17
17
|
5. [Fields](#Fields)
|
18
18
|
6. [Webhooks](#Webhooks)
|
19
|
-
7. [
|
19
|
+
7. [Emails](#Emails)
|
20
|
+
8. [Segmentations](#Segmentations)
|
21
|
+
9. [Errors](#Errors)
|
20
22
|
3. [Changelog](#Changelog)
|
21
23
|
4. [Migration guide](#Migration-guide)
|
22
24
|
1. [Upgrading from 1.2.x to 2.0.0](#Upgrading-from-1.2.x-to-2.0.0)
|
@@ -302,6 +304,46 @@ client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'ref
|
|
302
304
|
client.webhooks.delete('WEBHOOK_UUID')
|
303
305
|
```
|
304
306
|
|
307
|
+
### Emails
|
308
|
+
Endpoints to [Email](https://developers.rdstation.com/reference/get_platform-emails) information in your RD Station account.
|
309
|
+
|
310
|
+
#### List all emails
|
311
|
+
|
312
|
+
```ruby
|
313
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
314
|
+
client.emails.all
|
315
|
+
```
|
316
|
+
|
317
|
+
#### List emails using query params
|
318
|
+
```ruby
|
319
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
320
|
+
query_params = {page_size: 10, page: 1}
|
321
|
+
client.emails.all(query_params)
|
322
|
+
```
|
323
|
+
|
324
|
+
#### Get email by id
|
325
|
+
|
326
|
+
```ruby
|
327
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
328
|
+
client.emails.by_id(id)
|
329
|
+
```
|
330
|
+
|
331
|
+
### Segmentations
|
332
|
+
Endpoints to [Segmentation](https://developers.rdstation.com/reference/segmenta%C3%A7%C3%B5es) information in your RD Station account.
|
333
|
+
#### List all segmentations
|
334
|
+
|
335
|
+
```ruby
|
336
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
337
|
+
client.segmentations.all
|
338
|
+
```
|
339
|
+
|
340
|
+
#### Get the contact list with a specific segmentation
|
341
|
+
|
342
|
+
```ruby
|
343
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
344
|
+
client.segmentations.contacts(segmentation_id)
|
345
|
+
```
|
346
|
+
|
305
347
|
### Errors
|
306
348
|
|
307
349
|
Each endpoint may raise errors accoording to the HTTP response code from RDStation:
|
@@ -3,9 +3,7 @@ module RDStation
|
|
3
3
|
class Authentication
|
4
4
|
include HTTParty
|
5
5
|
|
6
|
-
AUTH_TOKEN_URL = "#{RDStation.host}/auth/token".freeze
|
7
6
|
DEFAULT_HEADERS = { 'Content-Type' => 'application/json' }.freeze
|
8
|
-
REVOKE_URL = "#{RDStation.host}/auth/revoke".freeze
|
9
7
|
|
10
8
|
def initialize(client_id = nil, client_secret = nil)
|
11
9
|
warn_deprecation if client_id || client_secret
|
@@ -51,7 +49,7 @@ module RDStation
|
|
51
49
|
|
52
50
|
def self.revoke(access_token:)
|
53
51
|
response = self.post(
|
54
|
-
|
52
|
+
"#{RDStation.host}/auth/revoke",
|
55
53
|
body: revoke_body(access_token),
|
56
54
|
headers: revoke_headers(access_token)
|
57
55
|
)
|
@@ -79,7 +77,7 @@ module RDStation
|
|
79
77
|
body = default_body.merge(params)
|
80
78
|
|
81
79
|
self.class.post(
|
82
|
-
|
80
|
+
"#{RDStation.host}/auth/token",
|
83
81
|
body: body.to_json,
|
84
82
|
headers: DEFAULT_HEADERS
|
85
83
|
)
|
data/lib/rdstation/client.rb
CHANGED
@@ -24,6 +24,14 @@ module RDStation
|
|
24
24
|
@webhooks ||= RDStation::Webhooks.new(authorization: @authorization)
|
25
25
|
end
|
26
26
|
|
27
|
+
def segmentations
|
28
|
+
@segmentations ||= RDStation::Segmentations.new(authorization: @authorization)
|
29
|
+
end
|
30
|
+
|
31
|
+
def emails
|
32
|
+
@emails ||= RDStation::Emails.new(authorization: @authorization)
|
33
|
+
end
|
34
|
+
|
27
35
|
private
|
28
36
|
|
29
37
|
def warn_deprecation
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RDStation
|
4
|
+
class Emails
|
5
|
+
include HTTParty
|
6
|
+
include ::RDStation::RetryableRequest
|
7
|
+
|
8
|
+
def initialize(authorization:)
|
9
|
+
@authorization = authorization
|
10
|
+
end
|
11
|
+
|
12
|
+
def all(query_params={})
|
13
|
+
retryable_request(@authorization) do |authorization|
|
14
|
+
response = self.class.get(base_url, headers: authorization.headers, query: query_params)
|
15
|
+
ApiResponse.build(response)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def by_id(id)
|
20
|
+
retryable_request(@authorization) do |authorization|
|
21
|
+
response = self.class.get(base_url(id), headers: authorization.headers)
|
22
|
+
ApiResponse.build(response)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def base_url(path='')
|
29
|
+
"#{RDStation.host}/platform/emails/#{path}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/rdstation/events.rb
CHANGED
@@ -1,19 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RDStation
|
2
4
|
class Events
|
3
5
|
include HTTParty
|
4
6
|
include ::RDStation::RetryableRequest
|
5
7
|
|
6
|
-
EVENTS_ENDPOINT = "#{RDStation.host}/platform/events".freeze
|
7
|
-
|
8
8
|
def initialize(authorization:)
|
9
9
|
@authorization = authorization
|
10
10
|
end
|
11
11
|
|
12
12
|
def create(payload)
|
13
13
|
retryable_request(@authorization) do |authorization|
|
14
|
-
response = self.class.post(
|
14
|
+
response = self.class.post(base_url, headers: authorization.headers, body: payload.to_json)
|
15
15
|
ApiResponse.build(response)
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def base_url
|
22
|
+
"#{RDStation.host}/platform/events"
|
23
|
+
end
|
18
24
|
end
|
19
25
|
end
|
data/lib/rdstation/fields.rb
CHANGED
@@ -1,26 +1,25 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module RDStation
|
3
4
|
# More info: https://developers.rdstation.com/pt-BR/reference/fields
|
4
5
|
class Fields
|
5
6
|
include HTTParty
|
6
7
|
include ::RDStation::RetryableRequest
|
7
8
|
|
8
|
-
BASE_URL = "#{RDStation.host}/platform/contacts/fields".freeze
|
9
|
-
|
10
9
|
def initialize(authorization:)
|
11
10
|
@authorization = authorization
|
12
11
|
end
|
13
12
|
|
14
13
|
def all
|
15
14
|
retryable_request(@authorization) do |authorization|
|
16
|
-
response = self.class.get(
|
15
|
+
response = self.class.get(base_url, headers: authorization.headers)
|
17
16
|
ApiResponse.build(response)
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
21
20
|
def create(payload)
|
22
21
|
retryable_request(@authorization) do |authorization|
|
23
|
-
response = self.class.post(
|
22
|
+
response = self.class.post(base_url, headers: authorization.headers, body: payload.to_json)
|
24
23
|
ApiResponse.build(response)
|
25
24
|
end
|
26
25
|
end
|
@@ -42,7 +41,7 @@ module RDStation
|
|
42
41
|
private
|
43
42
|
|
44
43
|
def base_url(path = '')
|
45
|
-
"#{
|
44
|
+
"#{RDStation.host}/platform/contacts/fields/#{path}"
|
46
45
|
end
|
47
46
|
end
|
48
47
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module RDStation
|
2
|
+
class Segmentations
|
3
|
+
include HTTParty
|
4
|
+
include ::RDStation::RetryableRequest
|
5
|
+
|
6
|
+
def initialize(authorization:)
|
7
|
+
@authorization = authorization
|
8
|
+
end
|
9
|
+
|
10
|
+
def all
|
11
|
+
retryable_request(@authorization) do |authorization|
|
12
|
+
response = self.class.get(base_url, headers: authorization.headers)
|
13
|
+
ApiResponse.build(response)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def contacts(segmentation_id)
|
18
|
+
retryable_request(@authorization) do |authorization|
|
19
|
+
response = self.class.get(base_url("#{segmentation_id}/contacts"), headers: authorization.headers)
|
20
|
+
ApiResponse.build(response)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def base_url(path = '')
|
27
|
+
"#{RDStation.host}/platform/segmentations/#{path}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/rdstation/version.rb
CHANGED
@@ -0,0 +1,165 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe RDStation::Emails do
|
4
|
+
let(:emails_client) do
|
5
|
+
described_class.new(authorization: RDStation::Authorization.new(access_token: 'access_token'))
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:emails_endpoint) { 'https://api.rd.services/platform/emails/' }
|
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 '#all' do
|
26
|
+
let(:emails_list) do
|
27
|
+
{
|
28
|
+
items: [
|
29
|
+
{
|
30
|
+
id: 123,
|
31
|
+
name: 'Marketing email',
|
32
|
+
created_at: '2017-11-21T20:00:00-02:00',
|
33
|
+
updated_at: '2017-11-21T20:00:00-02:00',
|
34
|
+
send_at: '2017-11-21T20:00:00-02:00',
|
35
|
+
leads_count: 55_000,
|
36
|
+
status: 'FINISHED',
|
37
|
+
type: 'email_model',
|
38
|
+
is_predictive_sending: false,
|
39
|
+
sending_is_imminent: false,
|
40
|
+
behavior_score_info: {
|
41
|
+
disengaged: false,
|
42
|
+
engaged: false,
|
43
|
+
indeterminate: false
|
44
|
+
},
|
45
|
+
campaign_id: 123,
|
46
|
+
component_template_id: 123
|
47
|
+
}
|
48
|
+
],
|
49
|
+
total: 1
|
50
|
+
}.to_json
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'calls retryable_request' do
|
54
|
+
expect(emails_client).to receive(:retryable_request)
|
55
|
+
emails_client.all
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when the request is successful' do
|
59
|
+
before do
|
60
|
+
stub_request(:get, emails_endpoint)
|
61
|
+
.with(headers: headers)
|
62
|
+
.to_return(status: 200, body: emails_list.to_json)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'returns all emails' do
|
66
|
+
response = emails_client.all
|
67
|
+
expect(response).to eq(emails_list)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when the request contains query params' do
|
72
|
+
let(:query_params) do
|
73
|
+
{
|
74
|
+
page: 1,
|
75
|
+
page_size: 10,
|
76
|
+
query: 'Test',
|
77
|
+
ids: '123, 456',
|
78
|
+
types: 'CAMPAIGN_EMAIL'
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
before do
|
83
|
+
stub_request(:get, emails_endpoint)
|
84
|
+
.with(headers: headers, query: query_params)
|
85
|
+
.to_return(status: 200, body: emails_list.to_json)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'returns emails filtered by the query params' do
|
89
|
+
response = emails_client.all(query_params)
|
90
|
+
expect(response).to eq(emails_list)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'when the response contains errors' do
|
95
|
+
before do
|
96
|
+
stub_request(:get, emails_endpoint)
|
97
|
+
.with(headers: headers)
|
98
|
+
.to_return(status: 400, body: { 'errors' => ['all errors'] }.to_json)
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'calls raise_error on error handler' do
|
102
|
+
emails_client.all
|
103
|
+
expect(error_handler).to have_received(:raise_error)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe '#by_id' do
|
109
|
+
let(:id) { 123 }
|
110
|
+
let(:emails_endpoint_by_id) { emails_endpoint + id.to_s }
|
111
|
+
|
112
|
+
it 'calls retryable_request' do
|
113
|
+
expect(emails_client).to receive(:retryable_request)
|
114
|
+
emails_client.by_id(id)
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'when the request is successful' do
|
118
|
+
let(:email) do
|
119
|
+
{
|
120
|
+
id: 123,
|
121
|
+
name: 'Marketing email',
|
122
|
+
created_at: '2017-11-21T20:00:00-02:00',
|
123
|
+
updated_at: '2017-11-21T20:00:00-02:00',
|
124
|
+
send_at: '2017-11-21T20:00:00-02:00',
|
125
|
+
leads_count: 55_000,
|
126
|
+
status: 'FINISHED',
|
127
|
+
type: 'email_model',
|
128
|
+
is_predictive_sending: false,
|
129
|
+
sending_is_imminent: false,
|
130
|
+
behavior_score_info: {
|
131
|
+
disengaged: false,
|
132
|
+
engaged: false,
|
133
|
+
indeterminate: false
|
134
|
+
},
|
135
|
+
campaign_id: 123,
|
136
|
+
component_template_id: 123
|
137
|
+
}.to_json
|
138
|
+
end
|
139
|
+
|
140
|
+
before do
|
141
|
+
stub_request(:get, emails_endpoint_by_id)
|
142
|
+
.with(headers: headers)
|
143
|
+
.to_return(status: 200, body: email.to_json)
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'returns the email' do
|
147
|
+
response = emails_client.by_id(id)
|
148
|
+
expect(response).to eq(email)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context 'when the response contains errors' do
|
153
|
+
before do
|
154
|
+
stub_request(:get, emails_endpoint_by_id)
|
155
|
+
.with(headers: headers)
|
156
|
+
.to_return(status: 400, body: { 'errors' => ['all errors'] }.to_json)
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'calls raise_error on error handler' do
|
160
|
+
emails_client.by_id(id)
|
161
|
+
expect(error_handler).to have_received(:raise_error)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
@@ -1,6 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
RSpec.describe RDStation::Fields do
|
6
|
+
before do
|
7
|
+
RDStation.configure do |config|
|
8
|
+
config.base_host = 'https://sample.rd.services'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
4
12
|
let(:valid_access_token) { 'valid_access_token' }
|
5
13
|
let(:rdstation_fields_with_valid_token) do
|
6
14
|
described_class.new(authorization: RDStation::Authorization.new(access_token: valid_access_token))
|
@@ -14,7 +22,7 @@ RSpec.describe RDStation::Fields do
|
|
14
22
|
end
|
15
23
|
|
16
24
|
describe '#all' do
|
17
|
-
let(:fields_endpoint) { 'https://
|
25
|
+
let(:fields_endpoint) { 'https://sample.rd.services/platform/contacts/fields/' }
|
18
26
|
let(:all_account_fields) do
|
19
27
|
{
|
20
28
|
'fields' => [
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe RDStation::Segmentations do
|
4
|
+
let(:segmentations_client) do
|
5
|
+
described_class.new(authorization: RDStation::Authorization.new(access_token: 'access_token'))
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:segmentations_endpoint) { 'https://api.rd.services/platform/segmentations/' }
|
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 '#all' do
|
26
|
+
it 'calls retryable_request' do
|
27
|
+
expect(segmentations_client).to receive(:retryable_request)
|
28
|
+
segmentations_client.all
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when the request is successful' do
|
32
|
+
let(:segmentations) do
|
33
|
+
{
|
34
|
+
segmentations: [
|
35
|
+
{
|
36
|
+
id: 1,
|
37
|
+
name: 'Todos os contatos da base',
|
38
|
+
standard: true,
|
39
|
+
created_at: '2021-09-24T14:14:04.510-03:00',
|
40
|
+
updated_at: '2021-09-24T14:14:04.510-03:00',
|
41
|
+
process_status: 'processed',
|
42
|
+
links: [
|
43
|
+
{
|
44
|
+
rel: 'SELF',
|
45
|
+
href: 'https://api.rd.services/platform/segmentations/1/contacts',
|
46
|
+
media: 'application/json',
|
47
|
+
type: 'GET'
|
48
|
+
}
|
49
|
+
]
|
50
|
+
}
|
51
|
+
]
|
52
|
+
}.to_json
|
53
|
+
end
|
54
|
+
|
55
|
+
before do
|
56
|
+
stub_request(:get, segmentations_endpoint)
|
57
|
+
.with(headers: headers)
|
58
|
+
.to_return(status: 200, body: segmentations.to_json)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns all segmentations' do
|
62
|
+
response = segmentations_client.all
|
63
|
+
expect(response).to eq(segmentations)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when the response contains errors' do
|
68
|
+
before do
|
69
|
+
stub_request(:get, segmentations_endpoint)
|
70
|
+
.with(headers: headers)
|
71
|
+
.to_return(status: 400, body: { 'errors' => ['all errors'] }.to_json)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'calls raise_error on error handler' do
|
75
|
+
segmentations_client.all
|
76
|
+
expect(error_handler).to have_received(:raise_error)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#contacts' do
|
82
|
+
let(:segmentation_id) { 123 }
|
83
|
+
let(:segmentations_endpoint_by_contacts) { segmentations_endpoint + "#{segmentation_id}/contacts" }
|
84
|
+
|
85
|
+
it 'calls retryable_request' do
|
86
|
+
expect(segmentations_client).to receive(:retryable_request)
|
87
|
+
segmentations_client.contacts(segmentation_id)
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'when the request is successful' do
|
91
|
+
let(:contact) do
|
92
|
+
{
|
93
|
+
contacts: [
|
94
|
+
{
|
95
|
+
uuid: '5408c5a3-4711-4f2e-8d0b-13407a3e30f3',
|
96
|
+
name: 'Lead Example 1',
|
97
|
+
email: 'leadexample1@example.com',
|
98
|
+
last_conversion_date: '2021-09-13T15:01:06.325-03:00',
|
99
|
+
created_at: '2021-09-13T15:01:06.325-03:00',
|
100
|
+
links: [
|
101
|
+
{
|
102
|
+
rel: 'SELF',
|
103
|
+
href: 'https://api.rd.services/platform/contacts/5408c5a3-4711-4f2e-8d0b-13407a3e30f3',
|
104
|
+
media: 'application/json',
|
105
|
+
type: 'GET'
|
106
|
+
}
|
107
|
+
]
|
108
|
+
}
|
109
|
+
]
|
110
|
+
}.to_json
|
111
|
+
end
|
112
|
+
|
113
|
+
before do
|
114
|
+
stub_request(:get, segmentations_endpoint_by_contacts)
|
115
|
+
.with(headers: headers)
|
116
|
+
.to_return(status: 200, body: contact.to_json)
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'returns the contact' do
|
120
|
+
response = segmentations_client.contacts(segmentation_id)
|
121
|
+
expect(response).to eq(contact)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context 'when the response contains errors' do
|
126
|
+
before do
|
127
|
+
stub_request(:get, segmentations_endpoint_by_contacts)
|
128
|
+
.with(headers: headers)
|
129
|
+
.to_return(status: 400, body: { 'errors' => ['all errors'] }.to_json)
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'calls raise_error on error handler' do
|
133
|
+
segmentations_client.contacts(segmentation_id)
|
134
|
+
expect(error_handler).to have_received(:raise_error)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
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.6.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: 2022-
|
11
|
+
date: 2022-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -147,6 +147,7 @@ files:
|
|
147
147
|
- lib/rdstation/builder/field.rb
|
148
148
|
- lib/rdstation/client.rb
|
149
149
|
- lib/rdstation/contacts.rb
|
150
|
+
- lib/rdstation/emails.rb
|
150
151
|
- lib/rdstation/error.rb
|
151
152
|
- lib/rdstation/error/format.rb
|
152
153
|
- lib/rdstation/error/formatter.rb
|
@@ -162,6 +163,7 @@ files:
|
|
162
163
|
- lib/rdstation/events.rb
|
163
164
|
- lib/rdstation/fields.rb
|
164
165
|
- lib/rdstation/retryable_request.rb
|
166
|
+
- lib/rdstation/segmentations.rb
|
165
167
|
- lib/rdstation/version.rb
|
166
168
|
- lib/rdstation/webhooks.rb
|
167
169
|
- rdstation-ruby-client.gemspec
|
@@ -172,6 +174,7 @@ files:
|
|
172
174
|
- spec/lib/rdstation/builder/field_spec.rb
|
173
175
|
- spec/lib/rdstation/client_spec.rb
|
174
176
|
- spec/lib/rdstation/contacts_spec.rb
|
177
|
+
- spec/lib/rdstation/emails_spec.rb
|
175
178
|
- spec/lib/rdstation/error/format_spec.rb
|
176
179
|
- spec/lib/rdstation/error/formatter_spec.rb
|
177
180
|
- spec/lib/rdstation/error_handler/conflicting_field_spec.rb
|
@@ -186,6 +189,7 @@ files:
|
|
186
189
|
- spec/lib/rdstation/events_spec.rb
|
187
190
|
- spec/lib/rdstation/fields_spec.rb
|
188
191
|
- spec/lib/rdstation/retryable_request_spec.rb
|
192
|
+
- spec/lib/rdstation/segmentations_spec.rb
|
189
193
|
- spec/lib/rdstation/webhooks_spec.rb
|
190
194
|
- spec/lib/rdstation_spec.rb
|
191
195
|
- spec/spec_helper.rb
|
@@ -220,6 +224,7 @@ test_files:
|
|
220
224
|
- spec/lib/rdstation/builder/field_spec.rb
|
221
225
|
- spec/lib/rdstation/client_spec.rb
|
222
226
|
- spec/lib/rdstation/contacts_spec.rb
|
227
|
+
- spec/lib/rdstation/emails_spec.rb
|
223
228
|
- spec/lib/rdstation/error/format_spec.rb
|
224
229
|
- spec/lib/rdstation/error/formatter_spec.rb
|
225
230
|
- spec/lib/rdstation/error_handler/conflicting_field_spec.rb
|
@@ -234,6 +239,7 @@ test_files:
|
|
234
239
|
- spec/lib/rdstation/events_spec.rb
|
235
240
|
- spec/lib/rdstation/fields_spec.rb
|
236
241
|
- spec/lib/rdstation/retryable_request_spec.rb
|
242
|
+
- spec/lib/rdstation/segmentations_spec.rb
|
237
243
|
- spec/lib/rdstation/webhooks_spec.rb
|
238
244
|
- spec/lib/rdstation_spec.rb
|
239
245
|
- spec/spec_helper.rb
|