folio_client 0.2.0 → 0.2.1

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: eb2abde077e892ded8a30319b08e773915d646d5c0193b8080789a49c73014e6
4
- data.tar.gz: 9a8de9e86652903db4068919af862d08abfa9a0cd86fea4d78500d206620fa25
3
+ metadata.gz: 821d1cc96a7b33ce8c0c8e86c29864175ebfb775ad7c09f0d876d5e52a4a7515
4
+ data.tar.gz: ed7139af94e9a0be7aa9393cc6dc5477b05630f81efe1ed693f2778e81286211
5
5
  SHA512:
6
- metadata.gz: b187b89f764fce8d797f3caa2b654f08895868cfa2732b049b3e40c30439ddc4f38aae1ae77f7f8ab0e433844c600ab615daa72d12a7768f261d2f44e232d897
7
- data.tar.gz: f7244e622f86eb96c8562baa62781c30cebc9909060945eac932b9ed8bcb3e3e08e6ba8578b1bd7712ac7964c3c7df630b2dffed8ed59708ee59cad1859b247a
6
+ metadata.gz: 31b71ca76d853865aef2752b688d795e2e8d3370febb99371e52d14e44f04f0e00f39d29ae2c8de006cd6cb49a73c8860a7d46bbe084a0c4b80dc119240e9261
7
+ data.tar.gz: 658f33fa1639211c7139009800e972b59ae19ebb8558a71cbb1d304b5c0a2537c3a089898dcf41d8a74533ee42ab8758e0f59310f76f617b8e46c64875f86a0a
data/Gemfile.lock CHANGED
@@ -66,7 +66,7 @@ GEM
66
66
  unicode-display_width (>= 2.4.0, < 3.0)
67
67
  rubocop-ast (1.26.0)
68
68
  parser (>= 3.2.1.0)
69
- rubocop-capybara (2.17.0)
69
+ rubocop-capybara (2.17.1)
70
70
  rubocop (~> 1.41)
71
71
  rubocop-performance (1.15.2)
72
72
  rubocop (>= 1.7.0, < 2.0)
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FolioClient
4
+ # Wraps API operations to request new access token if expired
5
+ class TokenWrapper
6
+ def self.refresh(config, connection)
7
+ yield
8
+ rescue UnexpectedResponse::UnauthorizedError
9
+ config.token = Authenticator.token(config.login_params, connection)
10
+ yield
11
+ end
12
+ end
13
+ end
@@ -18,6 +18,8 @@ class FolioClient
18
18
  # @param [Faraday::Response] response
19
19
  def self.call(response)
20
20
  case response.status
21
+ when 401
22
+ raise UnauthorizedError, "There was a problem with the access token: #{response.body}"
21
23
  when 403
22
24
  raise ForbiddenError, "The operation requires privileges which the client does not have: #{response.body}"
23
25
  when 404
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class FolioClient
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/folio_client.rb CHANGED
@@ -66,8 +66,12 @@ class FolioClient
66
66
  )
67
67
  end
68
68
 
69
+ # Public methods available on the FolioClient below
70
+ # Wrap methods in `TokenWrapper` to ensure a new token is fetched automatically if expired
69
71
  def fetch_hrid(...)
70
- inventory = Inventory.new(self)
71
- inventory.fetch_hrid(...)
72
+ TokenWrapper.refresh(config, connection) do
73
+ inventory = Inventory.new(self)
74
+ inventory.fetch_hrid(...)
75
+ end
72
76
  end
73
77
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: folio_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Mangiafico
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-15 00:00:00.000000000 Z
11
+ date: 2023-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -163,6 +163,7 @@ files:
163
163
  - lib/folio_client.rb
164
164
  - lib/folio_client/authenticator.rb
165
165
  - lib/folio_client/inventory.rb
166
+ - lib/folio_client/token_wrapper.rb
166
167
  - lib/folio_client/unexpected_response.rb
167
168
  - lib/folio_client/version.rb
168
169
  homepage: https://github.com/sul-dlss/folio_client