folio_client 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +7 -7
- data/lib/folio_client/inventory.rb +26 -0
- 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 +10 -0
- metadata +4 -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
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
folio_client (0.
|
4
|
+
folio_client (0.2.0)
|
5
5
|
activesupport (>= 4.2, < 8)
|
6
6
|
faraday
|
7
7
|
zeitwerk
|
@@ -34,7 +34,7 @@ GEM
|
|
34
34
|
language_server-protocol (3.17.0.3)
|
35
35
|
minitest (5.17.0)
|
36
36
|
parallel (1.22.1)
|
37
|
-
parser (3.2.
|
37
|
+
parser (3.2.1.0)
|
38
38
|
ast (~> 2.4.1)
|
39
39
|
public_suffix (5.0.1)
|
40
40
|
rainbow (3.1.1)
|
@@ -64,9 +64,9 @@ GEM
|
|
64
64
|
rubocop-ast (>= 1.24.1, < 2.0)
|
65
65
|
ruby-progressbar (~> 1.7)
|
66
66
|
unicode-display_width (>= 2.4.0, < 3.0)
|
67
|
-
rubocop-ast (1.
|
68
|
-
parser (>= 3.
|
69
|
-
rubocop-capybara (2.17.
|
67
|
+
rubocop-ast (1.26.0)
|
68
|
+
parser (>= 3.2.1.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)
|
@@ -82,7 +82,7 @@ GEM
|
|
82
82
|
simplecov_json_formatter (~> 0.1)
|
83
83
|
simplecov-html (0.12.3)
|
84
84
|
simplecov_json_formatter (0.1.4)
|
85
|
-
standard (1.
|
85
|
+
standard (1.24.3)
|
86
86
|
language_server-protocol (~> 3.17.0.2)
|
87
87
|
rubocop (= 1.44.1)
|
88
88
|
rubocop-performance (= 1.15.2)
|
@@ -93,7 +93,7 @@ GEM
|
|
93
93
|
addressable (>= 2.8.0)
|
94
94
|
crack (>= 0.3.2)
|
95
95
|
hashdiff (>= 0.4.0, < 2.0.0)
|
96
|
-
zeitwerk (2.6.
|
96
|
+
zeitwerk (2.6.7)
|
97
97
|
|
98
98
|
PLATFORMS
|
99
99
|
x86_64-darwin-19
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class FolioClient
|
4
|
+
# Lookup items in the Folio inventory
|
5
|
+
class Inventory
|
6
|
+
attr_accessor :client
|
7
|
+
|
8
|
+
# @param client [FolioClient] the configured client
|
9
|
+
def initialize(client)
|
10
|
+
@client = client
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param barcode [String] barcode to search by to fetch the HRID
|
14
|
+
def fetch_hrid(barcode:)
|
15
|
+
# find the instance UUID for this barcode
|
16
|
+
instance = client.get("/search/instances", {query: "items.barcode==#{barcode}"})
|
17
|
+
instance_uuid = instance.dig("instances", 0, "id")
|
18
|
+
|
19
|
+
return nil unless instance_uuid
|
20
|
+
|
21
|
+
# next lookup the instance given the instance_uuid so we can fetch the hrid
|
22
|
+
result = client.get("/inventory/instances/#{instance_uuid}")
|
23
|
+
result.dig("hrid")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -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
@@ -31,6 +31,7 @@ class FolioClient
|
|
31
31
|
end
|
32
32
|
|
33
33
|
delegate :config, :connection, :get, :post, to: :instance
|
34
|
+
delegate :fetch_hrid, to: :instance
|
34
35
|
end
|
35
36
|
|
36
37
|
attr_accessor :config
|
@@ -64,4 +65,13 @@ class FolioClient
|
|
64
65
|
headers: DEFAULT_HEADERS.merge(config.okapi_headers || {})
|
65
66
|
)
|
66
67
|
end
|
68
|
+
|
69
|
+
# Public methods available on the FolioClient below
|
70
|
+
# Wrap methods in `TokenWrapper` to ensure a new token is fetched automatically if expired
|
71
|
+
def fetch_hrid(...)
|
72
|
+
TokenWrapper.refresh(config, connection) do
|
73
|
+
inventory = Inventory.new(self)
|
74
|
+
inventory.fetch_hrid(...)
|
75
|
+
end
|
76
|
+
end
|
67
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.1
|
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
|
@@ -162,6 +162,8 @@ files:
|
|
162
162
|
- folio_client.gemspec
|
163
163
|
- lib/folio_client.rb
|
164
164
|
- lib/folio_client/authenticator.rb
|
165
|
+
- lib/folio_client/inventory.rb
|
166
|
+
- lib/folio_client/token_wrapper.rb
|
165
167
|
- lib/folio_client/unexpected_response.rb
|
166
168
|
- lib/folio_client/version.rb
|
167
169
|
homepage: https://github.com/sul-dlss/folio_client
|