rdstation-ruby-client 2.6.0 → 2.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eeaf9150717e1481fce77233ad549b2cd9a7d573f7c9f1e180a2c228c05ef374
4
- data.tar.gz: 79c04cb05e857cadb56d6b201ac12e22c30c35920fb1ddf473ea30700168c4fa
3
+ metadata.gz: f9c55a165bdad7cd10471e913f2f531d429e4200c7180b291d55695e5370c585
4
+ data.tar.gz: f88b126bc80b46bb3b7ffd5f5d424190251f8d93f3c787aeefb291c6ccdec544
5
5
  SHA512:
6
- metadata.gz: e7e70fb319205bc1ae61cb7567e82f6c7dae6050fedb403689589ea1b19dc9ca8d8699daa0287bb38f12797c41cb6bfbe20bf832989f2020c70673e4e9f655d9
7
- data.tar.gz: 4ab3bc836989453fd41cedebd1fc3aea0d6720fb390b62be913af5029e619c61484cf8c29f20c5228f050304d7cb4dcb641404fb899cdcd1878c0028f1b42fa4
6
+ metadata.gz: bc9a5c11adcc7d45451b2b069b3634c08bb3a47a9af4b473f7d2a39222969764cf80cd746d4d74cf723a6ff46b03f3983a1257f72f5a6a6f88085d2bc7929785
7
+ data.tar.gz: 17df3fc0b5abaa008377680764ef12a9fadb99a1d44a1fdbc3d76ea656776f07a51da3a348c00fc2982691b517f89d596d0d6e1fd1ca553bb5fd8e007c80ccac
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 "Gemfile.lock" }}
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 "Gemfile.lock" }}
37
+ key: v1-dependencies-{{ checksum "rdstation-ruby-client.gemspec" }}
38
38
 
39
39
  # run tests!
40
40
  - run:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,40 @@
1
+ ## 2.8.0
2
+
3
+ ### Additions
4
+
5
+ #### 1. New Analytics client: conversions
6
+
7
+ Usage example:
8
+
9
+ ```ruby
10
+ client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
11
+ query_params = { start_date:'2022-11-13', end_date:'2022-11-15', assets_type:['LandingPage'] }
12
+ client.analytics.conversions(query_params)
13
+ ```
14
+
15
+ #### 2. New landing_pages client
16
+
17
+ Usage example:
18
+
19
+ ```ruby
20
+ client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
21
+ client.landing_pages.all
22
+ ```
23
+
24
+ ## 2.7.0
25
+
26
+ ### Additions
27
+
28
+ #### 1. New Analytics client
29
+
30
+ Usage example:
31
+
32
+ ```ruby
33
+ client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
34
+ query_params = { start_date:'2022-11-02', end_date:'2022-11-08' }
35
+ client.analytics.email_marketing(query_params)
36
+ ```
37
+
1
38
  ## 2.6.0
2
39
 
3
40
  ### Additions
data/README.md CHANGED
@@ -18,7 +18,9 @@ Upgrading? Check the [migration guide](#Migration-guide) before bumping to a new
18
18
  6. [Webhooks](#Webhooks)
19
19
  7. [Emails](#Emails)
20
20
  8. [Segmentations](#Segmentations)
21
- 9. [Errors](#Errors)
21
+ 9. [Analytics](#Analytics)
22
+ 10.[LandingPages](#LandingPages)
23
+ 11.[Errors](#Errors)
22
24
  3. [Changelog](#Changelog)
23
25
  4. [Migration guide](#Migration-guide)
24
26
  1. [Upgrading from 1.2.x to 2.0.0](#Upgrading-from-1.2.x-to-2.0.0)
@@ -343,6 +345,37 @@ client.segmentations.all
343
345
  client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
344
346
  client.segmentations.contacts(segmentation_id)
345
347
  ```
348
+ ### Analytics
349
+ Endpoints to [Analytics](https://developers.rdstation.com/reference/estatisticas) information in your RD Station account.
350
+
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.
353
+ - NOTE: The query params `start_date`(yyyy-mm-dd) and `end_date`(yyyy-mm-dd) are required
354
+
355
+ ```ruby
356
+ client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
357
+ query_params = { start_date:'2022-11-02', end_date:'2022-11-08' }
358
+ client.analytics.email_marketing(query_params)
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
+ ```
346
379
 
347
380
  ### Errors
348
381
 
@@ -0,0 +1,32 @@
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('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)
22
+ ApiResponse.build(response)
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def base_url(path='')
29
+ "#{RDStation.host}/platform/analytics/#{path}"
30
+ end
31
+ end
32
+ end
@@ -32,6 +32,14 @@ module RDStation
32
32
  @emails ||= RDStation::Emails.new(authorization: @authorization)
33
33
  end
34
34
 
35
+ def analytics
36
+ @analytics ||= RDStation::Analytics.new(authorization: @authorization)
37
+ end
38
+
39
+ def landing_pages
40
+ @landing_pages ||= RDStation::LandingPages.new(authorization: @authorization)
41
+ end
42
+
35
43
  private
36
44
 
37
45
  def warn_deprecation
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RDStation
4
- VERSION = '2.6.0'
4
+ VERSION = '2.8.0'
5
5
  end
@@ -15,6 +15,8 @@ require 'rdstation/fields'
15
15
  require 'rdstation/webhooks'
16
16
  require 'rdstation/segmentations'
17
17
  require 'rdstation/emails'
18
+ require 'rdstation/analytics'
19
+ require 'rdstation/landing_pages'
18
20
 
19
21
  # Error handling
20
22
  require 'rdstation/error'
@@ -0,0 +1,184 @@
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(:headers) do
9
+ {
10
+ Authorization: 'Bearer access_token',
11
+ 'Content-Type': 'application/json'
12
+ }
13
+ end
14
+
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 '#email_marketing' do
24
+ let(:analytics_endpoint) { 'https://api.rd.services/platform/analytics/emails' }
25
+ let(:analytics_list) do
26
+ {
27
+ account_id: 1,
28
+ query_date: {
29
+ start_date: "2022-11-08",
30
+ end_date: "2022-11-08"
31
+ },
32
+ emails: [
33
+ {
34
+ campaign_id: 6061281,
35
+ campaign_name: "Desconto",
36
+ send_at: "2021-08-06T17:26:39-03:00",
37
+ contacts_count: 1000,
38
+ email_dropped_count: 3,
39
+ email_delivered_count: 997,
40
+ email_bounced_count: 5,
41
+ email_opened_count: 500,
42
+ email_clicked_count: 500,
43
+ email_unsubscribed_count: 4,
44
+ email_spam_reported_count: 1,
45
+ email_delivered_rate: 98.7,
46
+ email_opened_rate: 46.9,
47
+ email_clicked_rate: 36.5,
48
+ email_spam_reported_rate: 0
49
+ }
50
+ ]
51
+ }.to_json
52
+ end
53
+
54
+ it 'calls retryable_request' do
55
+ expect(analytics_client).to receive(:retryable_request)
56
+ analytics_client.email_marketing
57
+ end
58
+
59
+ context 'when the request is successful' do
60
+ before do
61
+ stub_request(:get, analytics_endpoint)
62
+ .with(headers: headers)
63
+ .to_return(status: 200, body: analytics_list.to_json)
64
+ end
65
+
66
+ it 'returns all email marketing analytics data' do
67
+ response = analytics_client.email_marketing
68
+ expect(response).to eq(analytics_list)
69
+ end
70
+ end
71
+
72
+ context 'when the request contains query params' do
73
+ let(:query_params) do
74
+ {
75
+ start_date:'2022-11-2',
76
+ end_date:'2022-11-8',
77
+ campaign_id: '6061281'
78
+ }
79
+ end
80
+
81
+ before do
82
+ stub_request(:get, analytics_endpoint)
83
+ .with(headers: headers, query: query_params)
84
+ .to_return(status: 200, body: analytics_list.to_json)
85
+ end
86
+
87
+ it 'returns email marketing analytics data filtered by the query params' do
88
+ response = analytics_client.email_marketing(query_params)
89
+ expect(response).to eq(analytics_list)
90
+ end
91
+ end
92
+
93
+ context 'when the response contains errors' do
94
+ before do
95
+ stub_request(:get, analytics_endpoint)
96
+ .with(headers: headers)
97
+ .to_return(status: 400, body: { 'errors' => ['all errors'] }.to_json)
98
+ end
99
+
100
+ it 'calls raise_error on error handler' do
101
+ analytics_client.email_marketing
102
+ expect(error_handler).to have_received(:raise_error)
103
+ end
104
+ end
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
184
+ 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,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
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.6.0
4
+ version: 2.8.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-13 00:00:00.000000000 Z
11
+ date: 2022-11-18 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/analytics.rb
144
145
  - lib/rdstation/api_response.rb
145
146
  - lib/rdstation/authentication.rb
146
147
  - lib/rdstation/authorization.rb
@@ -162,12 +163,14 @@ files:
162
163
  - lib/rdstation/error_handler/unauthorized.rb
163
164
  - lib/rdstation/events.rb
164
165
  - lib/rdstation/fields.rb
166
+ - lib/rdstation/landing_pages.rb
165
167
  - lib/rdstation/retryable_request.rb
166
168
  - lib/rdstation/segmentations.rb
167
169
  - lib/rdstation/version.rb
168
170
  - lib/rdstation/webhooks.rb
169
171
  - rdstation-ruby-client.gemspec
170
172
  - spec/lib/rdstation-ruby-client_spec.rb
173
+ - spec/lib/rdstation/analytics_spec.rb
171
174
  - spec/lib/rdstation/api_response_spec.rb
172
175
  - spec/lib/rdstation/authentication_spec.rb
173
176
  - spec/lib/rdstation/authorization_spec.rb
@@ -188,6 +191,7 @@ files:
188
191
  - spec/lib/rdstation/error_spec.rb
189
192
  - spec/lib/rdstation/events_spec.rb
190
193
  - spec/lib/rdstation/fields_spec.rb
194
+ - spec/lib/rdstation/landing_pages_spec.rb
191
195
  - spec/lib/rdstation/retryable_request_spec.rb
192
196
  - spec/lib/rdstation/segmentations_spec.rb
193
197
  - spec/lib/rdstation/webhooks_spec.rb
@@ -218,6 +222,7 @@ specification_version: 4
218
222
  summary: Ruby API wrapper for RD Station
219
223
  test_files:
220
224
  - spec/lib/rdstation-ruby-client_spec.rb
225
+ - spec/lib/rdstation/analytics_spec.rb
221
226
  - spec/lib/rdstation/api_response_spec.rb
222
227
  - spec/lib/rdstation/authentication_spec.rb
223
228
  - spec/lib/rdstation/authorization_spec.rb
@@ -238,6 +243,7 @@ test_files:
238
243
  - spec/lib/rdstation/error_spec.rb
239
244
  - spec/lib/rdstation/events_spec.rb
240
245
  - spec/lib/rdstation/fields_spec.rb
246
+ - spec/lib/rdstation/landing_pages_spec.rb
241
247
  - spec/lib/rdstation/retryable_request_spec.rb
242
248
  - spec/lib/rdstation/segmentations_spec.rb
243
249
  - spec/lib/rdstation/webhooks_spec.rb