rdstation-ruby-client 2.0.0 → 2.1.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
- SHA256:
3
- metadata.gz: 5ca94a755162557e5fcca58d15583986492ee1ef64c569c54d7c8a6feab6edec
4
- data.tar.gz: 7b258da27dd4f13148e2f9de60a4a95eb32131fb0e5e0d8f5cc133eb3e4720fd
2
+ SHA1:
3
+ metadata.gz: adcf1abef180f5dd333152cc6956191fd637f09e
4
+ data.tar.gz: 22ad74012fcef08e888ef1d72fb73989f84ee651
5
5
  SHA512:
6
- metadata.gz: 28bf2fc07e73df574917d1b441867146d3120d44a7e72599399648b118922c04c7e4fc75364180bdc175c14ee77c2452cf7ff02885d83d7daf6924c642876759
7
- data.tar.gz: c70a26f5d2b8a42d6b4deb8ee3de27ad817262e58b033a88200bcda04f9c36e468f2ce919b25d29181d810eb286a018a8eaed52eb04e4f545682e7a36b7a3876
6
+ metadata.gz: ad4409d04b424d90f74bab2a3d5264b7a0fe1b74b233840befff8e21a8597c40cb1cd99767292322b65a3ee309d809ad9a00ec8a851855476471fc89bb1a240c
7
+ data.tar.gz: 54f42eac6c63524bdacfb2c00548f3e9fdc5b0b63554c9c3ceca15f0afc24c800339506582127ebcc21b59e2b39f15ba5b3e20fe3eca9a658d0a258c9b380b5c
@@ -1,8 +1,14 @@
1
+ ## 2.1.0
2
+
3
+ ### Additions
4
+
5
+ `RDStation::Authentication.revoke` added. This method revokes an access_token at RD Station.
6
+
1
7
  ## 2.0.0
2
8
 
3
9
  ### Removals
4
10
 
5
- All API methods that were called directly on `RDStation::Client` (ex: `RDStation::Client.new('rdstation_token', 'auth_token').create_lead(lead_info)`) have been removed. See the [upgrading guide](#Upgrading-to-version-2.0.0) for a comprehensive guide on how to upgrade from version 1.2.x.
11
+ All API methods that were called directly on `RDStation::Client` (ex: `RDStation::Client.new('rdstation_token', 'auth_token').create_lead(lead_info)`) have been removed. See the [migration guide](README.md#Upgrading-from-1.2.x-to-2.0.0) for a comprehensive guide on how to upgrade from version 1.2.x.
6
12
 
7
13
  ### Notable changes
8
14
 
@@ -52,8 +58,8 @@ In cause of Unahtorized (401), the following specific errors may be raised (thos
52
58
 
53
59
  `rdstation-ruby-client` now requires `ruby >= 2.0.0`.
54
60
 
55
- ## 1.2.1
61
+ ## 1.2.1
56
62
 
57
63
  ### Deprecations
58
64
 
59
- All API methods that were called directly on `RDStation::Client` (ex: `RDStation::Client.new('rdstation_token', 'auth_token').create_lead(lead_info)`) are now deprecated. Those methods call RDSM's 1.3 API and will be removed in the next release.
65
+ All API methods that were called directly on `RDStation::Client` (ex: `RDStation::Client.new('rdstation_token', 'auth_token').create_lead(lead_info)`) are now deprecated. Those methods call RDSM's 1.3 API and will be removed in the next release.
data/README.md CHANGED
@@ -68,6 +68,14 @@ rdstation_authentication = RDStation::Authentication.new('client_id', 'client_se
68
68
  rdstation_authentication.update_access_token('refresh_token')
69
69
  ```
70
70
 
71
+ #### Revoking an access_token
72
+
73
+ ```ruby
74
+ RDStation::Authentication.revoke(access_token: "your token")
75
+ ```
76
+
77
+ Note: this will completely remove your credentials from RD Station (`update_access_token` won't work anymore).
78
+
71
79
  ### Contacts
72
80
 
73
81
  #### Getting a Contact by UUID
@@ -5,6 +5,7 @@ module RDStation
5
5
 
6
6
  AUTH_TOKEN_URL = 'https://api.rd.services/auth/token'.freeze
7
7
  DEFAULT_HEADERS = { 'Content-Type' => 'application/json' }.freeze
8
+ REVOKE_URL = 'https://api.rd.services/auth/revoke'.freeze
8
9
 
9
10
  def initialize(client_id, client_secret)
10
11
  @client_id = client_id
@@ -47,8 +48,31 @@ module RDStation
47
48
  ApiResponse.build(response)
48
49
  end
49
50
 
51
+ def self.revoke(access_token:)
52
+ response = self.post(
53
+ REVOKE_URL,
54
+ body: revoke_body(access_token),
55
+ headers: revoke_headers(access_token)
56
+ )
57
+ ApiResponse.build(response)
58
+ end
59
+
50
60
  private
51
61
 
62
+ def self.revoke_body(access_token)
63
+ URI.encode_www_form({
64
+ token: access_token,
65
+ token_type_hint: 'access_token'
66
+ })
67
+ end
68
+
69
+ def self.revoke_headers(access_token)
70
+ {
71
+ "Authorization" => "Bearer #{access_token}",
72
+ "Content-Type" => "application/x-www-form-urlencoded"
73
+ }
74
+ end
75
+
52
76
  def post_to_auth_endpoint(params)
53
77
  default_body = { client_id: @client_id, client_secret: @client_secret }
54
78
  body = default_body.merge(params)
@@ -1,3 +1,3 @@
1
1
  module RDStation
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '2.1.0'.freeze
3
3
  end
@@ -174,4 +174,78 @@ RSpec.describe RDStation::Authentication do
174
174
  end
175
175
  end
176
176
  end
177
+
178
+ describe ".revoke" do
179
+ let(:revoke_endpoint) { 'https://api.rd.services/auth/revoke' }
180
+ let(:request_headers) do
181
+ {
182
+ "Authorization" => "Bearer #{access_token}",
183
+ "Content-Type" => "application/x-www-form-urlencoded"
184
+ }
185
+ end
186
+
187
+ context "valid access_token" do
188
+ let(:access_token) { "valid_access_token" }
189
+
190
+ let(:ok_response) do
191
+ {
192
+ status: 200,
193
+ headers: { 'Content-Type' => 'application/json' },
194
+ body: {}.to_json
195
+ }
196
+ end
197
+
198
+ before do
199
+ stub_request(:post, revoke_endpoint)
200
+ .with(
201
+ headers: request_headers,
202
+ body: URI.encode_www_form({
203
+ token: access_token,
204
+ token_type_hint: 'access_token'
205
+ })
206
+ )
207
+ .to_return(ok_response)
208
+ end
209
+
210
+ it "returns 200 code with an empty hash in the body" do
211
+ request_response = RDStation::Authentication.revoke(access_token: access_token)
212
+ expect(request_response).to eq({})
213
+ end
214
+ end
215
+
216
+ context "invalid access token" do
217
+ let(:access_token) { "invalid_access_token" }
218
+
219
+ let(:unauthorized_response) do
220
+ {
221
+ status: 401,
222
+ headers: { 'Content-Type' => 'application/json' },
223
+ body: {
224
+ errors: {
225
+ error_type: 'UNAUTHORIZED',
226
+ error_message: 'Invalid token.'
227
+ }
228
+ }.to_json
229
+ }
230
+ end
231
+
232
+ before do
233
+ stub_request(:post, revoke_endpoint)
234
+ .with(
235
+ headers: request_headers,
236
+ body: URI.encode_www_form({
237
+ token: access_token,
238
+ token_type_hint: 'access_token'
239
+ })
240
+ )
241
+ .to_return(unauthorized_response)
242
+ end
243
+
244
+ it "raises unauthorized" do
245
+ expect do
246
+ RDStation::Authentication.revoke(access_token: access_token)
247
+ end.to raise_error(RDStation::Error::Unauthorized)
248
+ end
249
+ end
250
+ end
177
251
  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.0.0
4
+ version: 2.1.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: 2019-04-30 00:00:00.000000000 Z
11
+ date: 2019-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -184,7 +184,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
184
  - !ruby/object:Gem::Version
185
185
  version: '0'
186
186
  requirements: []
187
- rubygems_version: 3.0.2
187
+ rubyforge_project:
188
+ rubygems_version: 2.6.8
188
189
  signing_key:
189
190
  specification_version: 4
190
191
  summary: Ruby API wrapper for RD Station