rdstation-ruby-client 2.7.0 → 2.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -1
- data/README.md +26 -4
- data/lib/rdstation/analytics.rb +11 -4
- data/lib/rdstation/client.rb +4 -0
- data/lib/rdstation/landing_pages.rb +25 -0
- data/lib/rdstation/retryable_request.rb +1 -1
- data/lib/rdstation/version.rb +1 -1
- data/lib/rdstation-ruby-client.rb +1 -0
- data/spec/lib/rdstation/analytics_spec.rb +79 -2
- data/spec/lib/rdstation/landing_pages_spec.rb +85 -0
- data/spec/lib/rdstation/retryable_request_spec.rb +19 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 440807bc5aafd6c15cb69ad4c7ef4b50fbdcbddfac9e3441f4fff97675cf4ee3
|
4
|
+
data.tar.gz: 3c419ba39fd059e44d072c19b595147099f90295e69a946c02da95e4e856103e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c75f8c5d1957ccef3016093d1768e64b27e71ff7e47274efc9c6ee013cecb88befebfd2c38a476d4aecf68f1d92709747b882542ce9ea5bcd16cbc0faa7eee85
|
7
|
+
data.tar.gz: b66553b5cf10bc85f3f6c40704ebc999b3bd61ece59ef431bd903803e60cd29f27f88ea55750f4b650016c0173c88001ead4f305cfc313338fc1849d4b1fc05b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,30 @@
|
|
1
|
+
## 2.8.1
|
2
|
+
|
3
|
+
- Makes the retryable_request method also retry when a `RDStation::Error::Unauthorized` error happen
|
4
|
+
|
5
|
+
## 2.8.0
|
6
|
+
|
7
|
+
### Additions
|
8
|
+
|
9
|
+
#### 1. New Analytics client: conversions
|
10
|
+
|
11
|
+
Usage example:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
15
|
+
query_params = { start_date:'2022-11-13', end_date:'2022-11-15', assets_type:['LandingPage'] }
|
16
|
+
client.analytics.conversions(query_params)
|
17
|
+
```
|
18
|
+
|
19
|
+
#### 2. New landing_pages client
|
20
|
+
|
21
|
+
Usage example:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
25
|
+
client.landing_pages.all
|
26
|
+
```
|
27
|
+
|
1
28
|
## 2.7.0
|
2
29
|
|
3
30
|
### Additions
|
@@ -8,7 +35,7 @@ Usage example:
|
|
8
35
|
|
9
36
|
```ruby
|
10
37
|
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
11
|
-
|
38
|
+
query_params = { start_date:'2022-11-02', end_date:'2022-11-08' }
|
12
39
|
client.analytics.email_marketing(query_params)
|
13
40
|
```
|
14
41
|
|
data/README.md
CHANGED
@@ -19,7 +19,8 @@ Upgrading? Check the [migration guide](#Migration-guide) before bumping to a new
|
|
19
19
|
7. [Emails](#Emails)
|
20
20
|
8. [Segmentations](#Segmentations)
|
21
21
|
9. [Analytics](#Analytics)
|
22
|
-
10.
|
22
|
+
10.[LandingPages](#LandingPages)
|
23
|
+
11.[Errors](#Errors)
|
23
24
|
3. [Changelog](#Changelog)
|
24
25
|
4. [Migration guide](#Migration-guide)
|
25
26
|
1. [Upgrading from 1.2.x to 2.0.0](#Upgrading-from-1.2.x-to-2.0.0)
|
@@ -345,16 +346,37 @@ client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'ref
|
|
345
346
|
client.segmentations.contacts(segmentation_id)
|
346
347
|
```
|
347
348
|
### Analytics
|
348
|
-
Endpoints to [Analytics](https://developers.rdstation.com/reference/
|
349
|
+
Endpoints to [Analytics](https://developers.rdstation.com/reference/estatisticas) information in your RD Station account.
|
349
350
|
|
350
|
-
#### List all
|
351
|
+
#### => List all EMAIL MARKETING analytics data
|
352
|
+
Endpoints to [Analytics - Email marketing](https://developers.rdstation.com/reference/get_platform-analytics-emails) information in your RD Station account.
|
351
353
|
- NOTE: The query params `start_date`(yyyy-mm-dd) and `end_date`(yyyy-mm-dd) are required
|
352
354
|
|
353
355
|
```ruby
|
354
356
|
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
355
|
-
|
357
|
+
query_params = { start_date:'2022-11-02', end_date:'2022-11-08' }
|
356
358
|
client.analytics.email_marketing(query_params)
|
357
359
|
```
|
360
|
+
|
361
|
+
#### => List CONVERSIONS analytics data
|
362
|
+
Endpoints to [Analytics - Conversions](https://developers.rdstation.com/reference/get_platform-analytics-conversions) information in your RD Station account.
|
363
|
+
- NOTE: The query params `start_date`(yyyy-mm-dd) and `end_date`(yyyy-mm-dd) are required.
|
364
|
+
|
365
|
+
```ruby
|
366
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
367
|
+
query_params = { start_date:'2022-11-13', end_date:'2022-11-15', assets_type:['LandingPage'] }
|
368
|
+
client.analytics.conversions(query_params)
|
369
|
+
```
|
370
|
+
|
371
|
+
### LandingPages
|
372
|
+
Endpoints to [LandingPages](https://developers.rdstation.com/reference/get_platform-landing-pages) information in your RD Station account.
|
373
|
+
#### List all landing_pages
|
374
|
+
|
375
|
+
```ruby
|
376
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
377
|
+
client.landing_pages.all
|
378
|
+
```
|
379
|
+
|
358
380
|
### Errors
|
359
381
|
|
360
382
|
Each endpoint may raise errors accoording to the HTTP response code from RDStation:
|
data/lib/rdstation/analytics.rb
CHANGED
@@ -11,15 +11,22 @@ module RDStation
|
|
11
11
|
|
12
12
|
def email_marketing(query_params={})
|
13
13
|
retryable_request(@authorization) do |authorization|
|
14
|
-
response = self.class.get(base_url, headers: authorization.headers, query: query_params)
|
14
|
+
response = self.class.get(base_url('emails'), headers: authorization.headers, query: query_params)
|
15
|
+
ApiResponse.build(response)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def conversions(query_params={})
|
20
|
+
retryable_request(@authorization) do |authorization|
|
21
|
+
response = self.class.get(base_url('conversions'), headers: authorization.headers, query: query_params)
|
15
22
|
ApiResponse.build(response)
|
16
23
|
end
|
17
24
|
end
|
18
25
|
|
19
26
|
private
|
20
27
|
|
21
|
-
def base_url
|
22
|
-
"#{RDStation.host}/platform/analytics
|
28
|
+
def base_url(path='')
|
29
|
+
"#{RDStation.host}/platform/analytics/#{path}"
|
23
30
|
end
|
24
31
|
end
|
25
|
-
end
|
32
|
+
end
|
data/lib/rdstation/client.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RDStation
|
4
|
+
class LandingPages
|
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
|
+
private
|
20
|
+
|
21
|
+
def base_url(path='')
|
22
|
+
"#{RDStation.host}/platform/landing_pages/#{path}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -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
|
data/lib/rdstation/version.rb
CHANGED
@@ -5,8 +5,6 @@ RSpec.describe RDStation::Analytics do
|
|
5
5
|
described_class.new(authorization: RDStation::Authorization.new(access_token: 'access_token'))
|
6
6
|
end
|
7
7
|
|
8
|
-
let(:analytics_endpoint) { 'https://api.rd.services/platform/analytics/emails' }
|
9
|
-
|
10
8
|
let(:headers) do
|
11
9
|
{
|
12
10
|
Authorization: 'Bearer access_token',
|
@@ -23,6 +21,7 @@ RSpec.describe RDStation::Analytics do
|
|
23
21
|
end
|
24
22
|
|
25
23
|
describe '#email_marketing' do
|
24
|
+
let(:analytics_endpoint) { 'https://api.rd.services/platform/analytics/emails' }
|
26
25
|
let(:analytics_list) do
|
27
26
|
{
|
28
27
|
account_id: 1,
|
@@ -104,4 +103,82 @@ RSpec.describe RDStation::Analytics do
|
|
104
103
|
end
|
105
104
|
end
|
106
105
|
end
|
106
|
+
|
107
|
+
describe '#conversions' do
|
108
|
+
let(:analytics_endpoint) { 'https://api.rd.services/platform/analytics/conversions' }
|
109
|
+
let(:analytics_list) do
|
110
|
+
{
|
111
|
+
account_id: 3127612,
|
112
|
+
query_date: {
|
113
|
+
start_date: "2022-11-17",
|
114
|
+
end_date: "2022-11-17"
|
115
|
+
},
|
116
|
+
assets_type: "[LandingPage]",
|
117
|
+
conversions: [
|
118
|
+
{
|
119
|
+
asset_id: 1495004,
|
120
|
+
asset_identifier: "Como aumentar suas taxas de conversão",
|
121
|
+
asset_type: "LandingPage",
|
122
|
+
asset_created_at: "2022-06-30T19:11:05.191Z",
|
123
|
+
asset_updated_at: "2022-06-30T20:11:05.191Z",
|
124
|
+
visits_count: 1500,
|
125
|
+
conversions_count: 150,
|
126
|
+
conversion_rate: 10
|
127
|
+
}
|
128
|
+
]
|
129
|
+
}.to_json
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'calls retryable_request' do
|
133
|
+
expect(analytics_client).to receive(:retryable_request)
|
134
|
+
analytics_client.conversions
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'when the request is successful' do
|
138
|
+
before do
|
139
|
+
stub_request(:get, analytics_endpoint)
|
140
|
+
.with(headers: headers)
|
141
|
+
.to_return(status: 200, body: analytics_list.to_json)
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'returns all email marketing analytics data' do
|
145
|
+
response = analytics_client.conversions
|
146
|
+
expect(response).to eq(analytics_list)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context 'when the request contains query params' do
|
151
|
+
let(:query_params) do
|
152
|
+
{
|
153
|
+
start_date:'2022-11-17',
|
154
|
+
end_date:'2022-11-17',
|
155
|
+
asset_id: '1495004'
|
156
|
+
}
|
157
|
+
end
|
158
|
+
|
159
|
+
before do
|
160
|
+
stub_request(:get, analytics_endpoint)
|
161
|
+
.with(headers: headers, query: query_params)
|
162
|
+
.to_return(status: 200, body: analytics_list.to_json)
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'returns conversions analytics data filtered by the query params' do
|
166
|
+
response = analytics_client.conversions(query_params)
|
167
|
+
expect(response).to eq(analytics_list)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context 'when the response contains errors' do
|
172
|
+
before do
|
173
|
+
stub_request(:get, analytics_endpoint)
|
174
|
+
.with(headers: headers)
|
175
|
+
.to_return(status: 400, body: { 'errors' => ['all errors'] }.to_json)
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'calls raise_error on error handler' do
|
179
|
+
analytics_client.conversions
|
180
|
+
expect(error_handler).to have_received(:raise_error)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
107
184
|
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe RDStation::LandingPages do
|
4
|
+
let(:landing_pages_client) do
|
5
|
+
described_class.new(authorization: RDStation::Authorization.new(access_token: 'access_token'))
|
6
|
+
end
|
7
|
+
let(:landing_pages_endpoint) { 'https://api.rd.services/platform/landing_pages/' }
|
8
|
+
|
9
|
+
let(:headers) do
|
10
|
+
{
|
11
|
+
Authorization: 'Bearer access_token',
|
12
|
+
'Content-Type': 'application/json'
|
13
|
+
}
|
14
|
+
end
|
15
|
+
let(:error_handler) do
|
16
|
+
instance_double(RDStation::ErrorHandler, raise_error: 'mock raised errors')
|
17
|
+
end
|
18
|
+
|
19
|
+
before do
|
20
|
+
allow(RDStation::ErrorHandler).to receive(:new).and_return(error_handler)
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#all' do
|
24
|
+
let(:landing_pages_list) do
|
25
|
+
[
|
26
|
+
{
|
27
|
+
id: 1,
|
28
|
+
title: "Minha Primeira Landing Page",
|
29
|
+
created_at: "2021-09-22T14:14:04.510-03:00",
|
30
|
+
upated_at: "2021-09-24T14:14:04.510-03:00",
|
31
|
+
conversion_identifier: "dia-das-mães-2022",
|
32
|
+
status: "PUBLISHED",
|
33
|
+
has_active_experiment: false,
|
34
|
+
had_experiment: false
|
35
|
+
}
|
36
|
+
].to_json
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'calls retryable_request' do
|
40
|
+
expect(landing_pages_client).to receive(:retryable_request)
|
41
|
+
landing_pages_client.all
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when the request is successful' do
|
45
|
+
before do
|
46
|
+
stub_request(:get, landing_pages_endpoint)
|
47
|
+
.with(headers: headers)
|
48
|
+
.to_return(status: 200, body: landing_pages_list.to_json)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'returns all email marketing analytics data' do
|
52
|
+
response = landing_pages_client.all
|
53
|
+
expect(response).to eq(landing_pages_list)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when the request contains query params' do
|
58
|
+
let(:query_params) { { page: 1 } }
|
59
|
+
|
60
|
+
before do
|
61
|
+
stub_request(:get, landing_pages_endpoint)
|
62
|
+
.with(headers: headers, query: query_params)
|
63
|
+
.to_return(status: 200, body: landing_pages_list.to_json)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'returns email marketing analytics data filtered by the query params' do
|
67
|
+
response = landing_pages_client.all(query_params)
|
68
|
+
expect(response).to eq(landing_pages_list)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'when the response contains errors' do
|
73
|
+
before do
|
74
|
+
stub_request(:get, landing_pages_endpoint)
|
75
|
+
.with(headers: headers)
|
76
|
+
.to_return(status: 400, body: { 'errors' => ['all errors'] }.to_json)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'calls raise_error on error handler' do
|
80
|
+
landing_pages_client.all
|
81
|
+
expect(error_handler).to have_received(:raise_error)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
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.
|
4
|
+
version: 2.8.1
|
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-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -163,6 +163,7 @@ files:
|
|
163
163
|
- lib/rdstation/error_handler/unauthorized.rb
|
164
164
|
- lib/rdstation/events.rb
|
165
165
|
- lib/rdstation/fields.rb
|
166
|
+
- lib/rdstation/landing_pages.rb
|
166
167
|
- lib/rdstation/retryable_request.rb
|
167
168
|
- lib/rdstation/segmentations.rb
|
168
169
|
- lib/rdstation/version.rb
|
@@ -190,6 +191,7 @@ files:
|
|
190
191
|
- spec/lib/rdstation/error_spec.rb
|
191
192
|
- spec/lib/rdstation/events_spec.rb
|
192
193
|
- spec/lib/rdstation/fields_spec.rb
|
194
|
+
- spec/lib/rdstation/landing_pages_spec.rb
|
193
195
|
- spec/lib/rdstation/retryable_request_spec.rb
|
194
196
|
- spec/lib/rdstation/segmentations_spec.rb
|
195
197
|
- spec/lib/rdstation/webhooks_spec.rb
|
@@ -241,6 +243,7 @@ test_files:
|
|
241
243
|
- spec/lib/rdstation/error_spec.rb
|
242
244
|
- spec/lib/rdstation/events_spec.rb
|
243
245
|
- spec/lib/rdstation/fields_spec.rb
|
246
|
+
- spec/lib/rdstation/landing_pages_spec.rb
|
244
247
|
- spec/lib/rdstation/retryable_request_spec.rb
|
245
248
|
- spec/lib/rdstation/segmentations_spec.rb
|
246
249
|
- spec/lib/rdstation/webhooks_spec.rb
|