folio_client 0.2.0 → 0.2.1
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/folio_client/token_wrapper.rb +13 -0
- data/lib/folio_client/unexpected_response.rb +2 -0
- data/lib/folio_client/version.rb +1 -1
- data/lib/folio_client.rb +6 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 821d1cc96a7b33ce8c0c8e86c29864175ebfb775ad7c09f0d876d5e52a4a7515
|
4
|
+
data.tar.gz: ed7139af94e9a0be7aa9393cc6dc5477b05630f81efe1ed693f2778e81286211
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31b71ca76d853865aef2752b688d795e2e8d3370febb99371e52d14e44f04f0e00f39d29ae2c8de006cd6cb49a73c8860a7d46bbe084a0c4b80dc119240e9261
|
7
|
+
data.tar.gz: 658f33fa1639211c7139009800e972b59ae19ebb8558a71cbb1d304b5c0a2537c3a089898dcf41d8a74533ee42ab8758e0f59310f76f617b8e46c64875f86a0a
|
data/Gemfile.lock
CHANGED
@@ -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
|
data/lib/folio_client/version.rb
CHANGED
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
|
-
|
71
|
-
|
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.
|
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-
|
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
|