rdstation-ruby-client 2.5.3 → 2.6.0

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: a86741ab9503d0df23891a8c5f5624ecfa1aa16239bdcceff547b38600490ce3
4
- data.tar.gz: ee42acbda82c510a976cc6219eba9ac84761cdcbc74923f3c6ba59047ac25102
3
+ metadata.gz: eeaf9150717e1481fce77233ad549b2cd9a7d573f7c9f1e180a2c228c05ef374
4
+ data.tar.gz: 79c04cb05e857cadb56d6b201ac12e22c30c35920fb1ddf473ea30700168c4fa
5
5
  SHA512:
6
- metadata.gz: d8bfed006377c6561dfc35e5951a303d8efa17b049d20523abcf6a580b467280b30a8072d320756fbaa7420af142e7c2c99f9d5f7b93732bc0dcbcb2a41fbdde
7
- data.tar.gz: 182cda1194b7fad1a853663c0eed931615acaf9c13dc60f60ff378f63765175a3a622e9e349801cda369d06aff84b2b0ca2541f7fe3fa755c8122e31f81b9220
6
+ metadata.gz: e7e70fb319205bc1ae61cb7567e82f6c7dae6050fedb403689589ea1b19dc9ca8d8699daa0287bb38f12797c41cb6bfbe20bf832989f2020c70673e4e9f655d9
7
+ data.tar.gz: 4ab3bc836989453fd41cedebd1fc3aea0d6720fb390b62be913af5029e619c61484cf8c29f20c5228f050304d7cb4dcb641404fb899cdcd1878c0028f1b42fa4
data/.gitignore CHANGED
@@ -11,6 +11,7 @@ spec/reports
11
11
  test/tmp
12
12
  test/version_tmp
13
13
  tmp
14
+ Gemfile.lock
14
15
 
15
16
  # YARD artifacts
16
17
  .yardoc
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. [Errors](#Errors)
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:
@@ -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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RDStation
4
- VERSION = '2.5.3'
4
+ VERSION = '2.6.0'
5
5
  end
@@ -13,6 +13,8 @@ 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'
16
18
 
17
19
  # Error handling
18
20
  require 'rdstation/error'
@@ -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
@@ -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.5.3
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-10-04 00:00:00.000000000 Z
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