rdstation-ruby-client 2.4.0 → 2.5.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: d51df272057d17abe280b0fe23f7a97f9ef2ceb543f823db1ce8b047788d1887
4
- data.tar.gz: d59bd8063663bb95df477c672066e4c6655172a193d9b2244bba6b8608a92869
3
+ metadata.gz: 5df3763feda5bcb841946b403695b54933c0fcc9b0b9da1c907146454e5311ff
4
+ data.tar.gz: 63cd80564336415bc361c3dfce276611d1b1a6b61c68554e4f1a212c73fd9c7e
5
5
  SHA512:
6
- metadata.gz: 1451abf2db818f4551575ea88befdb63b6f8f8b1afa3270b96ee50b059f0f69676d6c6104a6e217d58e9c84384527d77e81d257d5a222a1ab2df74e1ed525446
7
- data.tar.gz: 06c2620cdf413e945207f7b0bad15bcdb762038b360ef3c9ed5371e2ff06edc4949f97602fc0c3ffc352ff14bf66774234c398b291a5606d34931ab0eded84e9
6
+ metadata.gz: 60eded16372c0d970d67b5f456a28d8adb9e7f013f8551e56b72598752ea9a0c24f99fdf4f3c943f040872d71a837279d769b43ac7b2e36d2c0c5eaa8ae9f405
7
+ data.tar.gz: 1107d1405d1984cd36de905403f3a53a6275505e55ff4c4d5661f7914d268f11031d81c5602464ca2f573b61831d5516a437abe9501a1fd8a34549ec3a36753f
@@ -1,3 +1,17 @@
1
+ ## 2.5.0
2
+
3
+ - InvalidRefreshToken error added. This error will be raised when the refresh token is invalid or it was revoked. When you get this error, you can safely disconnect the user from RD Station.
4
+
5
+ Usage example:
6
+
7
+ ```ruby
8
+ begin
9
+ rdstation.update_access_token(refresh_token)
10
+ rescue RDStation::Error::InvalidRefreshToken
11
+ # Disconnect user
12
+ end
13
+ ```
14
+
1
15
  ## 2.4.0
2
16
 
3
17
  - Add the TooManyRequests errors in case of rate limit exceeded. See [API request limit](https://developers.rdstation.com/en/request-limit) for more details
data/Rakefile CHANGED
@@ -5,3 +5,7 @@ RSpec::Core::RakeTask.new
5
5
 
6
6
  task :default => :spec
7
7
  task :test => :spec
8
+
9
+ task :console do
10
+ exec 'pry -r rdstation-ruby-client -I ./lib'
11
+ end
@@ -35,5 +35,6 @@ module RDStation
35
35
  class ExpiredAccessToken < Unauthorized; end
36
36
  class ExpiredCodeGrant < Unauthorized; end
37
37
  class InvalidCredentials < Unauthorized; end
38
+ class InvalidRefreshToken < Unauthorized; end
38
39
  end
39
40
  end
@@ -0,0 +1,24 @@
1
+ module RDStation
2
+ class ErrorHandler
3
+ class InvalidRefreshToken
4
+ attr_reader :errors
5
+
6
+ ERROR_CODE = 'INVALID_REFRESH_TOKEN'.freeze
7
+
8
+ def initialize(errors)
9
+ @errors = errors
10
+ end
11
+
12
+ def raise_error
13
+ return if invalid_refresh_token_error.empty?
14
+ raise RDStation::Error::InvalidRefreshToken, invalid_refresh_token_error
15
+ end
16
+
17
+ private
18
+
19
+ def invalid_refresh_token_error
20
+ errors.find { |error| error['error_type'] == ERROR_CODE }
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,6 +1,7 @@
1
1
  require_relative 'expired_access_token'
2
2
  require_relative 'expired_code_grant'
3
3
  require_relative 'invalid_credentials'
4
+ require_relative 'invalid_refresh_token'
4
5
 
5
6
  module RDStation
6
7
  class ErrorHandler
@@ -9,6 +10,7 @@ module RDStation
9
10
  ErrorHandler::ExpiredAccessToken,
10
11
  ErrorHandler::ExpiredCodeGrant,
11
12
  ErrorHandler::InvalidCredentials,
13
+ ErrorHandler::InvalidRefreshToken,
12
14
  ].freeze
13
15
 
14
16
  def initialize(array_of_errors)
@@ -1,3 +1,3 @@
1
1
  module RDStation
2
- VERSION = '2.4.0'.freeze
2
+ VERSION = '2.5.0'.freeze
3
3
  end
@@ -217,19 +217,32 @@ RSpec.describe RDStation::Authentication do
217
217
  end
218
218
 
219
219
  context 'when the refresh token is invalid' do
220
+ let(:invalid_refresh_token_response) do
221
+ {
222
+ status: 401,
223
+ headers: { 'Content-Type' => 'application/json' },
224
+ body: {
225
+ errors: {
226
+ error_type: 'INVALID_REFRESH_TOKEN',
227
+ error_message: 'The provided refresh token is invalid or was revoked.'
228
+ }
229
+ }.to_json
230
+ }
231
+ end
232
+
220
233
  before do
221
234
  stub_request(:post, token_endpoint)
222
235
  .with(
223
236
  headers: request_headers,
224
237
  body: token_request_with_invalid_refresh_token.to_json
225
238
  )
226
- .to_return(invalid_code_response)
239
+ .to_return(invalid_refresh_token_response)
227
240
  end
228
241
 
229
242
  it 'returns an auth error' do
230
243
  expect do
231
244
  authentication.update_access_token('invalid_refresh_token')
232
- end.to raise_error(RDStation::Error::InvalidCredentials)
245
+ end.to raise_error(RDStation::Error::InvalidRefreshToken)
233
246
  end
234
247
  end
235
248
 
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RDStation::ErrorHandler::InvalidRefreshToken do
4
+ describe '#raise_error' do
5
+ subject(:invalid_refresh_token) { described_class.new(errors) }
6
+
7
+ context 'when the refresh token is invalid or was revoked' do
8
+ let(:errors) do
9
+ [
10
+ {
11
+ 'error_type' => 'INVALID_REFRESH_TOKEN',
12
+ 'error_message' => 'Error Message',
13
+ }
14
+ ]
15
+ end
16
+
17
+ it 'raises an InvalidRefreshToken error' do
18
+ expect do
19
+ invalid_refresh_token.raise_error
20
+ end.to raise_error(RDStation::Error::InvalidRefreshToken, 'Error Message')
21
+ end
22
+ end
23
+
24
+ context 'when none of the errors are invalid refresh token errors' do
25
+ let(:errors) do
26
+ [
27
+ {
28
+ 'error_message' => 'Error Message',
29
+ 'error_type' => 'RANDOM_ERROR_TYPE'
30
+ },
31
+ {
32
+ 'error_message' => 'Another Error Message',
33
+ 'error_type' => 'ANOTHER_RANDOM_ERROR_TYPE'
34
+ }
35
+ ]
36
+ end
37
+
38
+ it 'does not raise an InvalidRefreshToken error' do
39
+ result = invalid_refresh_token.raise_error
40
+ expect(result).to be_nil
41
+ end
42
+ end
43
+
44
+ context 'when there are no errors' do
45
+ let(:errors) { [] }
46
+
47
+ it 'does not raise an InvalidRefreshToken error' do
48
+ result = invalid_refresh_token.raise_error
49
+ expect(result).to be_nil
50
+ end
51
+ end
52
+ end
53
+ 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.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo L F Casaretto
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-16 00:00:00.000000000 Z
11
+ date: 2020-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -156,6 +156,7 @@ files:
156
156
  - lib/rdstation/error_handler/expired_code_grant.rb
157
157
  - lib/rdstation/error_handler/invalid_credentials.rb
158
158
  - lib/rdstation/error_handler/invalid_event_type.rb
159
+ - lib/rdstation/error_handler/invalid_refresh_token.rb
159
160
  - lib/rdstation/error_handler/unauthorized.rb
160
161
  - lib/rdstation/events.rb
161
162
  - lib/rdstation/fields.rb
@@ -177,6 +178,7 @@ files:
177
178
  - spec/lib/rdstation/error_handler/expired_code_grant_spec.rb
178
179
  - spec/lib/rdstation/error_handler/invalid_credentials_spec.rb
179
180
  - spec/lib/rdstation/error_handler/invalid_event_type_spec.rb
181
+ - spec/lib/rdstation/error_handler/invalid_refresh_token_spec.rb
180
182
  - spec/lib/rdstation/error_handler/unauthorized_spec.rb
181
183
  - spec/lib/rdstation/error_handler_spec.rb
182
184
  - spec/lib/rdstation/error_spec.rb
@@ -190,7 +192,7 @@ homepage: http://resultadosdigitais.com.br
190
192
  licenses:
191
193
  - MIT
192
194
  metadata: {}
193
- post_install_message:
195
+ post_install_message:
194
196
  rdoc_options: []
195
197
  require_paths:
196
198
  - lib
@@ -205,8 +207,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
207
  - !ruby/object:Gem::Version
206
208
  version: '0'
207
209
  requirements: []
208
- rubygems_version: 3.0.8
209
- signing_key:
210
+ rubyforge_project:
211
+ rubygems_version: 2.7.6.2
212
+ signing_key:
210
213
  specification_version: 4
211
214
  summary: Ruby API wrapper for RD Station
212
215
  test_files:
@@ -224,6 +227,7 @@ test_files:
224
227
  - spec/lib/rdstation/error_handler/expired_code_grant_spec.rb
225
228
  - spec/lib/rdstation/error_handler/invalid_credentials_spec.rb
226
229
  - spec/lib/rdstation/error_handler/invalid_event_type_spec.rb
230
+ - spec/lib/rdstation/error_handler/invalid_refresh_token_spec.rb
227
231
  - spec/lib/rdstation/error_handler/unauthorized_spec.rb
228
232
  - spec/lib/rdstation/error_handler_spec.rb
229
233
  - spec/lib/rdstation/error_spec.rb