rdstation-ruby-client 2.5.3 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +2 -2
- data/.gitignore +1 -0
- data/CHANGELOG.md +36 -0
- data/README.md +54 -1
- data/lib/rdstation/analytics.rb +25 -0
- data/lib/rdstation/client.rb +12 -0
- data/lib/rdstation/emails.rb +32 -0
- data/lib/rdstation/segmentations.rb +30 -0
- data/lib/rdstation/version.rb +1 -1
- data/lib/rdstation-ruby-client.rb +3 -0
- data/spec/lib/rdstation/analytics_spec.rb +107 -0
- data/spec/lib/rdstation/emails_spec.rb +165 -0
- data/spec/lib/rdstation/fields_spec.rb +6 -0
- data/spec/lib/rdstation/segmentations_spec.rb +138 -0
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f95c666afffacdbac2a2903c5b8909999bb24bba716f89d4646ee19c165bc262
|
4
|
+
data.tar.gz: 1beded8e2c402f5bb89523e3e20d5ee8ed485f6687819317f558f958bdd90353
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4803cf2a2f16e6982c84d84d9109c03130f8df4ff4d92ecfc9b5500e96383afdf6527b7dd834d7d1256d9947ab67f4aeed6d70591a2a86c3edf9b10ad7cced70
|
7
|
+
data.tar.gz: 344733aa7473f0d0db3391e26fc4a00648b9123ded0a5713549ab67462fdc528ef1a3256774d728aa2df6490cbdc989e65c2538e9a81c3f9829ab6f0622c303f
|
data/.circleci/config.yml
CHANGED
@@ -22,7 +22,7 @@ jobs:
|
|
22
22
|
# Download and cache dependencies
|
23
23
|
- restore_cache:
|
24
24
|
keys:
|
25
|
-
- v1-dependencies-{{ checksum "
|
25
|
+
- v1-dependencies-{{ checksum "rdstation-ruby-client.gemspec" }}
|
26
26
|
# fallback to using the latest cache if no exact match is found
|
27
27
|
- v1-dependencies-
|
28
28
|
|
@@ -34,7 +34,7 @@ jobs:
|
|
34
34
|
- save_cache:
|
35
35
|
paths:
|
36
36
|
- ./vendor/bundle
|
37
|
-
key: v1-dependencies-{{ checksum "
|
37
|
+
key: v1-dependencies-{{ checksum "rdstation-ruby-client.gemspec" }}
|
38
38
|
|
39
39
|
# run tests!
|
40
40
|
- run:
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,39 @@
|
|
1
|
+
## 2.7.0
|
2
|
+
|
3
|
+
### Additions
|
4
|
+
|
5
|
+
#### 1. New Analytics client
|
6
|
+
|
7
|
+
Usage example:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
11
|
+
query_parms = { start_date:'2022-11-02', end_date:'2022-11-08' }
|
12
|
+
client.analytics.email_marketing(query_params)
|
13
|
+
```
|
14
|
+
|
15
|
+
## 2.6.0
|
16
|
+
|
17
|
+
### Additions
|
18
|
+
|
19
|
+
#### 1. New Emails client
|
20
|
+
|
21
|
+
Usage example:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
25
|
+
client.emails.all
|
26
|
+
```
|
27
|
+
|
28
|
+
#### 2. New Segmentations client
|
29
|
+
|
30
|
+
Usage example:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
34
|
+
client.segmentations.all
|
35
|
+
```
|
36
|
+
|
1
37
|
## 2.5.1
|
2
38
|
|
3
39
|
- Fixed checking `empty?` for nil values inside of InvalidRefreshToken class
|
data/README.md
CHANGED
@@ -16,7 +16,10 @@ 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. [Analytics](#Analytics)
|
22
|
+
10. [Errors](#Errors)
|
20
23
|
3. [Changelog](#Changelog)
|
21
24
|
4. [Migration guide](#Migration-guide)
|
22
25
|
1. [Upgrading from 1.2.x to 2.0.0](#Upgrading-from-1.2.x-to-2.0.0)
|
@@ -302,6 +305,56 @@ client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'ref
|
|
302
305
|
client.webhooks.delete('WEBHOOK_UUID')
|
303
306
|
```
|
304
307
|
|
308
|
+
### Emails
|
309
|
+
Endpoints to [Email](https://developers.rdstation.com/reference/get_platform-emails) information in your RD Station account.
|
310
|
+
|
311
|
+
#### List all emails
|
312
|
+
|
313
|
+
```ruby
|
314
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
315
|
+
client.emails.all
|
316
|
+
```
|
317
|
+
|
318
|
+
#### List emails using query params
|
319
|
+
```ruby
|
320
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
321
|
+
query_params = {page_size: 10, page: 1}
|
322
|
+
client.emails.all(query_params)
|
323
|
+
```
|
324
|
+
|
325
|
+
#### Get email by id
|
326
|
+
|
327
|
+
```ruby
|
328
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
329
|
+
client.emails.by_id(id)
|
330
|
+
```
|
331
|
+
|
332
|
+
### Segmentations
|
333
|
+
Endpoints to [Segmentation](https://developers.rdstation.com/reference/segmenta%C3%A7%C3%B5es) information in your RD Station account.
|
334
|
+
#### List all segmentations
|
335
|
+
|
336
|
+
```ruby
|
337
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
338
|
+
client.segmentations.all
|
339
|
+
```
|
340
|
+
|
341
|
+
#### Get the contact list with a specific segmentation
|
342
|
+
|
343
|
+
```ruby
|
344
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
345
|
+
client.segmentations.contacts(segmentation_id)
|
346
|
+
```
|
347
|
+
### Analytics
|
348
|
+
Endpoints to [Analytics](https://developers.rdstation.com/reference/get_platform-analytics-emails) information in your RD Station account.
|
349
|
+
|
350
|
+
#### List all email marketing analytics data
|
351
|
+
- NOTE: The query params `start_date`(yyyy-mm-dd) and `end_date`(yyyy-mm-dd) are required
|
352
|
+
|
353
|
+
```ruby
|
354
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
355
|
+
query_parms = { start_date:'2022-11-02', end_date:'2022-11-08' }
|
356
|
+
client.analytics.email_marketing(query_params)
|
357
|
+
```
|
305
358
|
### Errors
|
306
359
|
|
307
360
|
Each endpoint may raise errors accoording to the HTTP response code from RDStation:
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RDStation
|
4
|
+
class Analytics
|
5
|
+
include HTTParty
|
6
|
+
include ::RDStation::RetryableRequest
|
7
|
+
|
8
|
+
def initialize(authorization:)
|
9
|
+
@authorization = authorization
|
10
|
+
end
|
11
|
+
|
12
|
+
def email_marketing(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
|
+
private
|
20
|
+
|
21
|
+
def base_url
|
22
|
+
"#{RDStation.host}/platform/analytics/emails"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/rdstation/client.rb
CHANGED
@@ -24,6 +24,18 @@ 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
|
+
|
35
|
+
def analytics
|
36
|
+
@analytics ||= RDStation::Analytics.new(authorization: @authorization)
|
37
|
+
end
|
38
|
+
|
27
39
|
private
|
28
40
|
|
29
41
|
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
|
@@ -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
@@ -13,6 +13,9 @@ require 'rdstation/contacts'
|
|
13
13
|
require 'rdstation/events'
|
14
14
|
require 'rdstation/fields'
|
15
15
|
require 'rdstation/webhooks'
|
16
|
+
require 'rdstation/segmentations'
|
17
|
+
require 'rdstation/emails'
|
18
|
+
require 'rdstation/analytics'
|
16
19
|
|
17
20
|
# Error handling
|
18
21
|
require 'rdstation/error'
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe RDStation::Analytics do
|
4
|
+
let(:analytics_client) do
|
5
|
+
described_class.new(authorization: RDStation::Authorization.new(access_token: 'access_token'))
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:analytics_endpoint) { 'https://api.rd.services/platform/analytics/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 '#email_marketing' do
|
26
|
+
let(:analytics_list) do
|
27
|
+
{
|
28
|
+
account_id: 1,
|
29
|
+
query_date: {
|
30
|
+
start_date: "2022-11-08",
|
31
|
+
end_date: "2022-11-08"
|
32
|
+
},
|
33
|
+
emails: [
|
34
|
+
{
|
35
|
+
campaign_id: 6061281,
|
36
|
+
campaign_name: "Desconto",
|
37
|
+
send_at: "2021-08-06T17:26:39-03:00",
|
38
|
+
contacts_count: 1000,
|
39
|
+
email_dropped_count: 3,
|
40
|
+
email_delivered_count: 997,
|
41
|
+
email_bounced_count: 5,
|
42
|
+
email_opened_count: 500,
|
43
|
+
email_clicked_count: 500,
|
44
|
+
email_unsubscribed_count: 4,
|
45
|
+
email_spam_reported_count: 1,
|
46
|
+
email_delivered_rate: 98.7,
|
47
|
+
email_opened_rate: 46.9,
|
48
|
+
email_clicked_rate: 36.5,
|
49
|
+
email_spam_reported_rate: 0
|
50
|
+
}
|
51
|
+
]
|
52
|
+
}.to_json
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'calls retryable_request' do
|
56
|
+
expect(analytics_client).to receive(:retryable_request)
|
57
|
+
analytics_client.email_marketing
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'when the request is successful' do
|
61
|
+
before do
|
62
|
+
stub_request(:get, analytics_endpoint)
|
63
|
+
.with(headers: headers)
|
64
|
+
.to_return(status: 200, body: analytics_list.to_json)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'returns all email marketing analytics data' do
|
68
|
+
response = analytics_client.email_marketing
|
69
|
+
expect(response).to eq(analytics_list)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'when the request contains query params' do
|
74
|
+
let(:query_params) do
|
75
|
+
{
|
76
|
+
start_date:'2022-11-2',
|
77
|
+
end_date:'2022-11-8',
|
78
|
+
campaign_id: '6061281'
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
before do
|
83
|
+
stub_request(:get, analytics_endpoint)
|
84
|
+
.with(headers: headers, query: query_params)
|
85
|
+
.to_return(status: 200, body: analytics_list.to_json)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'returns email marketing analytics data filtered by the query params' do
|
89
|
+
response = analytics_client.email_marketing(query_params)
|
90
|
+
expect(response).to eq(analytics_list)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'when the response contains errors' do
|
95
|
+
before do
|
96
|
+
stub_request(:get, analytics_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
|
+
analytics_client.email_marketing
|
103
|
+
expect(error_handler).to have_received(:raise_error)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -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
|
@@ -9,6 +9,12 @@ RSpec.describe RDStation::Fields do
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
after do
|
13
|
+
RDStation.configure do |config|
|
14
|
+
config.base_host = 'https://api.rd.services'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
12
18
|
let(:valid_access_token) { 'valid_access_token' }
|
13
19
|
let(:rdstation_fields_with_valid_token) do
|
14
20
|
described_class.new(authorization: RDStation::Authorization.new(access_token: valid_access_token))
|
@@ -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.7.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-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -141,12 +141,14 @@ files:
|
|
141
141
|
- Rakefile
|
142
142
|
- lib/rdstation-ruby-client.rb
|
143
143
|
- lib/rdstation.rb
|
144
|
+
- lib/rdstation/analytics.rb
|
144
145
|
- lib/rdstation/api_response.rb
|
145
146
|
- lib/rdstation/authentication.rb
|
146
147
|
- lib/rdstation/authorization.rb
|
147
148
|
- lib/rdstation/builder/field.rb
|
148
149
|
- lib/rdstation/client.rb
|
149
150
|
- lib/rdstation/contacts.rb
|
151
|
+
- lib/rdstation/emails.rb
|
150
152
|
- lib/rdstation/error.rb
|
151
153
|
- lib/rdstation/error/format.rb
|
152
154
|
- lib/rdstation/error/formatter.rb
|
@@ -162,16 +164,19 @@ files:
|
|
162
164
|
- lib/rdstation/events.rb
|
163
165
|
- lib/rdstation/fields.rb
|
164
166
|
- lib/rdstation/retryable_request.rb
|
167
|
+
- lib/rdstation/segmentations.rb
|
165
168
|
- lib/rdstation/version.rb
|
166
169
|
- lib/rdstation/webhooks.rb
|
167
170
|
- rdstation-ruby-client.gemspec
|
168
171
|
- spec/lib/rdstation-ruby-client_spec.rb
|
172
|
+
- spec/lib/rdstation/analytics_spec.rb
|
169
173
|
- spec/lib/rdstation/api_response_spec.rb
|
170
174
|
- spec/lib/rdstation/authentication_spec.rb
|
171
175
|
- spec/lib/rdstation/authorization_spec.rb
|
172
176
|
- spec/lib/rdstation/builder/field_spec.rb
|
173
177
|
- spec/lib/rdstation/client_spec.rb
|
174
178
|
- spec/lib/rdstation/contacts_spec.rb
|
179
|
+
- spec/lib/rdstation/emails_spec.rb
|
175
180
|
- spec/lib/rdstation/error/format_spec.rb
|
176
181
|
- spec/lib/rdstation/error/formatter_spec.rb
|
177
182
|
- spec/lib/rdstation/error_handler/conflicting_field_spec.rb
|
@@ -186,6 +191,7 @@ files:
|
|
186
191
|
- spec/lib/rdstation/events_spec.rb
|
187
192
|
- spec/lib/rdstation/fields_spec.rb
|
188
193
|
- spec/lib/rdstation/retryable_request_spec.rb
|
194
|
+
- spec/lib/rdstation/segmentations_spec.rb
|
189
195
|
- spec/lib/rdstation/webhooks_spec.rb
|
190
196
|
- spec/lib/rdstation_spec.rb
|
191
197
|
- spec/spec_helper.rb
|
@@ -214,12 +220,14 @@ specification_version: 4
|
|
214
220
|
summary: Ruby API wrapper for RD Station
|
215
221
|
test_files:
|
216
222
|
- spec/lib/rdstation-ruby-client_spec.rb
|
223
|
+
- spec/lib/rdstation/analytics_spec.rb
|
217
224
|
- spec/lib/rdstation/api_response_spec.rb
|
218
225
|
- spec/lib/rdstation/authentication_spec.rb
|
219
226
|
- spec/lib/rdstation/authorization_spec.rb
|
220
227
|
- spec/lib/rdstation/builder/field_spec.rb
|
221
228
|
- spec/lib/rdstation/client_spec.rb
|
222
229
|
- spec/lib/rdstation/contacts_spec.rb
|
230
|
+
- spec/lib/rdstation/emails_spec.rb
|
223
231
|
- spec/lib/rdstation/error/format_spec.rb
|
224
232
|
- spec/lib/rdstation/error/formatter_spec.rb
|
225
233
|
- spec/lib/rdstation/error_handler/conflicting_field_spec.rb
|
@@ -234,6 +242,7 @@ test_files:
|
|
234
242
|
- spec/lib/rdstation/events_spec.rb
|
235
243
|
- spec/lib/rdstation/fields_spec.rb
|
236
244
|
- spec/lib/rdstation/retryable_request_spec.rb
|
245
|
+
- spec/lib/rdstation/segmentations_spec.rb
|
237
246
|
- spec/lib/rdstation/webhooks_spec.rb
|
238
247
|
- spec/lib/rdstation_spec.rb
|
239
248
|
- spec/spec_helper.rb
|