folio_client 0.2.1 → 0.3.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 +3 -1
- data/lib/folio_client/inventory.rb +1 -0
- data/lib/folio_client/source_storage.rb +26 -0
- data/lib/folio_client/unexpected_response.rb +11 -5
- data/lib/folio_client/version.rb +1 -1
- data/lib/folio_client.rb +8 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e53de53a53383306d8d102202f46a3d7812fea93d63ba876e4be9f3d31c122a
|
4
|
+
data.tar.gz: 6a923cb74ab603ecba4fc9e909da87fdcd0a2540cbc58dafc381147012ae1a4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bf690f79b82a5ec7c7a53b88867671a389bcae846832971ecb8a07f55f227b3c77761270e1d584207a6c4b1775e00f49d5ddadaea1d10bb6c9ce4a64bbb69b4
|
7
|
+
data.tar.gz: 98520694ded40e076ee49a456f46ad1b2c460c34d247fff9d519f9e5f5f4ae825e1ea2f3a56f7d8118301b14b8ffb02aa12c44cbe7e6106e9b1451f6fe8344fd
|
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.3.1)
|
5
5
|
activesupport (>= 4.2, < 8)
|
6
6
|
faraday
|
7
7
|
zeitwerk
|
@@ -97,6 +97,8 @@ GEM
|
|
97
97
|
|
98
98
|
PLATFORMS
|
99
99
|
x86_64-darwin-19
|
100
|
+
x86_64-darwin-20
|
101
|
+
x86_64-darwin-21
|
100
102
|
x86_64-linux
|
101
103
|
|
102
104
|
DEPENDENCIES
|
@@ -11,6 +11,7 @@ class FolioClient
|
|
11
11
|
end
|
12
12
|
|
13
13
|
# @param barcode [String] barcode to search by to fetch the HRID
|
14
|
+
# @return [String,nil] HRID if present, otherwise nil.
|
14
15
|
def fetch_hrid(barcode:)
|
15
16
|
# find the instance UUID for this barcode
|
16
17
|
instance = client.get("/search/instances", {query: "items.barcode==#{barcode}"})
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class FolioClient
|
4
|
+
# Lookup records in Folio Source Storage
|
5
|
+
class SourceStorage
|
6
|
+
attr_accessor :client
|
7
|
+
|
8
|
+
# @param client [FolioClient] the configured client
|
9
|
+
def initialize(client)
|
10
|
+
@client = client
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param instance_hrid [String] the key to use for MARC lookup
|
14
|
+
# @return [Hash] hash representation of the MARC. should be usable by MARC::Record.new_from_hash (from ruby-marc gem)
|
15
|
+
# @raises NotFound, MultipleRecordsForIdentifier
|
16
|
+
def fetch_marc_hash(instance_hrid:)
|
17
|
+
response_hash = client.get("/source-storage/source-records", {instanceHrid: instance_hrid})
|
18
|
+
|
19
|
+
record_count = response_hash["totalRecords"]
|
20
|
+
raise FolioClient::UnexpectedResponse::ResourceNotFound, "No records found for #{instance_hrid}" if record_count.zero?
|
21
|
+
raise FolioClient::UnexpectedResponse::MultipleResourcesFound, "Expected 1 record for #{instance_hrid}, but found #{record_count}" if record_count > 1
|
22
|
+
|
23
|
+
response_hash["sourceRecords"].first["parsedRecord"]["content"]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -3,17 +3,23 @@
|
|
3
3
|
class FolioClient
|
4
4
|
# Handles unexpected responses when communicating with Folio
|
5
5
|
class UnexpectedResponse
|
6
|
+
# Base class for all FolioClient errors
|
7
|
+
class FolioClientError < StandardError; end
|
8
|
+
|
6
9
|
# Error raised by the Folio Auth API returns a 422 Unauthorized
|
7
|
-
class UnauthorizedError <
|
10
|
+
class UnauthorizedError < FolioClientError; end
|
11
|
+
|
12
|
+
# Error raised when the Folio API returns a 404 NotFound, or returns 0 results when one was expected
|
13
|
+
class ResourceNotFound < FolioClientError; end
|
8
14
|
|
9
|
-
# Error raised when
|
10
|
-
class
|
15
|
+
# Error raised when e.g. exactly one result was expected, but more than one was returned
|
16
|
+
class MultipleResourcesFound < FolioClientError; end
|
11
17
|
|
12
18
|
# Error raised when the Folio API returns a 403 Forbidden
|
13
|
-
class ForbiddenError <
|
19
|
+
class ForbiddenError < FolioClientError; end
|
14
20
|
|
15
21
|
# Error raised when the Folio API returns a 500
|
16
|
-
class ServiceUnavailable <
|
22
|
+
class ServiceUnavailable < FolioClientError; end
|
17
23
|
|
18
24
|
# @param [Faraday::Response] response
|
19
25
|
def self.call(response)
|
data/lib/folio_client/version.rb
CHANGED
data/lib/folio_client.rb
CHANGED
@@ -31,7 +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
|
+
delegate :fetch_hrid, :fetch_marc_hash, to: :instance
|
35
35
|
end
|
36
36
|
|
37
37
|
attr_accessor :config
|
@@ -74,4 +74,11 @@ class FolioClient
|
|
74
74
|
inventory.fetch_hrid(...)
|
75
75
|
end
|
76
76
|
end
|
77
|
+
|
78
|
+
def fetch_marc_hash(...)
|
79
|
+
TokenWrapper.refresh(config, connection) do
|
80
|
+
source_storage = SourceStorage.new(self)
|
81
|
+
source_storage.fetch_marc_hash(...)
|
82
|
+
end
|
83
|
+
end
|
77
84
|
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.
|
4
|
+
version: 0.3.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-27 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/source_storage.rb
|
166
167
|
- lib/folio_client/token_wrapper.rb
|
167
168
|
- lib/folio_client/unexpected_response.rb
|
168
169
|
- lib/folio_client/version.rb
|
@@ -188,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
189
|
- !ruby/object:Gem::Version
|
189
190
|
version: '0'
|
190
191
|
requirements: []
|
191
|
-
rubygems_version: 3.
|
192
|
+
rubygems_version: 3.3.7
|
192
193
|
signing_key:
|
193
194
|
specification_version: 4
|
194
195
|
summary: Interface for interacting with the Folio ILS API.
|