folio_client 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -1
- data/lib/folio_client/source_storage.rb +26 -0
- data/lib/folio_client/unexpected_response.rb +4 -1
- 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: 960e3e0d138665bbf21b4f609fb7c789c52110101bf303c42ba2c98b93583b98
|
4
|
+
data.tar.gz: b2690e1193c7391a6e4bd6bae4c4f417f395ed91faa50d6215c43e1fc39aaadd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42cbfadefe92754026e08435bd06378e6dee17ae97e539bd9d71d7833e873c02194ad1762690b55087f002f5fca553f63579a981dfe915674ee95fb8e839bbf2
|
7
|
+
data.tar.gz: 4e2067aa01d4cd2534079cc9a5d11834d73432cd05c209fc57553713ec7d07a27dcf458ec52cace086fab3971d0fe3b9048e3e30e0669d3736d2ea37dcd0589b
|
data/Gemfile.lock
CHANGED
@@ -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
|
@@ -6,9 +6,12 @@ class FolioClient
|
|
6
6
|
# Error raised by the Folio Auth API returns a 422 Unauthorized
|
7
7
|
class UnauthorizedError < StandardError; end
|
8
8
|
|
9
|
-
# Error raised when the Folio API returns a 404 NotFound
|
9
|
+
# Error raised when the Folio API returns a 404 NotFound, or returns 0 results when one was expected
|
10
10
|
class ResourceNotFound < StandardError; end
|
11
11
|
|
12
|
+
# Error raised when e.g. exactly one result was expected, but more than one was returned
|
13
|
+
class MultipleResourcesFound < StandardError; end
|
14
|
+
|
12
15
|
# Error raised when the Folio API returns a 403 Forbidden
|
13
16
|
class ForbiddenError < StandardError; end
|
14
17
|
|
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.0
|
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-23 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.
|