rdstation-ruby-client 2.7.0 → 2.8.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: f95c666afffacdbac2a2903c5b8909999bb24bba716f89d4646ee19c165bc262
4
- data.tar.gz: 1beded8e2c402f5bb89523e3e20d5ee8ed485f6687819317f558f958bdd90353
3
+ metadata.gz: f9c55a165bdad7cd10471e913f2f531d429e4200c7180b291d55695e5370c585
4
+ data.tar.gz: f88b126bc80b46bb3b7ffd5f5d424190251f8d93f3c787aeefb291c6ccdec544
5
5
  SHA512:
6
- metadata.gz: 4803cf2a2f16e6982c84d84d9109c03130f8df4ff4d92ecfc9b5500e96383afdf6527b7dd834d7d1256d9947ab67f4aeed6d70591a2a86c3edf9b10ad7cced70
7
- data.tar.gz: 344733aa7473f0d0db3391e26fc4a00648b9123ded0a5713549ab67462fdc528ef1a3256774d728aa2df6490cbdc989e65c2538e9a81c3f9829ab6f0622c303f
6
+ metadata.gz: bc9a5c11adcc7d45451b2b069b3634c08bb3a47a9af4b473f7d2a39222969764cf80cd746d4d74cf723a6ff46b03f3983a1257f72f5a6a6f88085d2bc7929785
7
+ data.tar.gz: 17df3fc0b5abaa008377680764ef12a9fadb99a1d44a1fdbc3d76ea656776f07a51da3a348c00fc2982691b517f89d596d0d6e1fd1ca553bb5fd8e007c80ccac
data/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
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
+
1
24
  ## 2.7.0
2
25
 
3
26
  ### Additions
@@ -8,7 +31,7 @@ Usage example:
8
31
 
9
32
  ```ruby
10
33
  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' }
34
+ query_params = { start_date:'2022-11-02', end_date:'2022-11-08' }
12
35
  client.analytics.email_marketing(query_params)
13
36
  ```
14
37
 
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. [Errors](#Errors)
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/get_platform-analytics-emails) information in your RD Station account.
349
+ Endpoints to [Analytics](https://developers.rdstation.com/reference/estatisticas) information in your RD Station account.
349
350
 
350
- #### List all email marketing analytics data
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
- query_parms = { start_date:'2022-11-02', end_date:'2022-11-08' }
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:
@@ -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/emails"
28
+ def base_url(path='')
29
+ "#{RDStation.host}/platform/analytics/#{path}"
23
30
  end
24
31
  end
25
- end
32
+ end
@@ -36,6 +36,10 @@ module RDStation
36
36
  @analytics ||= RDStation::Analytics.new(authorization: @authorization)
37
37
  end
38
38
 
39
+ def landing_pages
40
+ @landing_pages ||= RDStation::LandingPages.new(authorization: @authorization)
41
+ end
42
+
39
43
  private
40
44
 
41
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.7.0'
4
+ VERSION = '2.8.0'
5
5
  end
@@ -16,6 +16,7 @@ require 'rdstation/webhooks'
16
16
  require 'rdstation/segmentations'
17
17
  require 'rdstation/emails'
18
18
  require 'rdstation/analytics'
19
+ require 'rdstation/landing_pages'
19
20
 
20
21
  # Error handling
21
22
  require 'rdstation/error'
@@ -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
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.7.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-11-09 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
@@ -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