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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 821d1cc96a7b33ce8c0c8e86c29864175ebfb775ad7c09f0d876d5e52a4a7515
4
- data.tar.gz: ed7139af94e9a0be7aa9393cc6dc5477b05630f81efe1ed693f2778e81286211
3
+ metadata.gz: 960e3e0d138665bbf21b4f609fb7c789c52110101bf303c42ba2c98b93583b98
4
+ data.tar.gz: b2690e1193c7391a6e4bd6bae4c4f417f395ed91faa50d6215c43e1fc39aaadd
5
5
  SHA512:
6
- metadata.gz: 31b71ca76d853865aef2752b688d795e2e8d3370febb99371e52d14e44f04f0e00f39d29ae2c8de006cd6cb49a73c8860a7d46bbe084a0c4b80dc119240e9261
7
- data.tar.gz: 658f33fa1639211c7139009800e972b59ae19ebb8558a71cbb1d304b5c0a2537c3a089898dcf41d8a74533ee42ab8758e0f59310f76f617b8e46c64875f86a0a
6
+ metadata.gz: 42cbfadefe92754026e08435bd06378e6dee17ae97e539bd9d71d7833e873c02194ad1762690b55087f002f5fca553f63579a981dfe915674ee95fb8e839bbf2
7
+ data.tar.gz: 4e2067aa01d4cd2534079cc9a5d11834d73432cd05c209fc57553713ec7d07a27dcf458ec52cace086fab3971d0fe3b9048e3e30e0669d3736d2ea37dcd0589b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- folio_client (0.2.0)
4
+ folio_client (0.3.0)
5
5
  activesupport (>= 4.2, < 8)
6
6
  faraday
7
7
  zeitwerk
@@ -97,6 +97,7 @@ GEM
97
97
 
98
98
  PLATFORMS
99
99
  x86_64-darwin-19
100
+ x86_64-darwin-20
100
101
  x86_64-linux
101
102
 
102
103
  DEPENDENCIES
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class FolioClient
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.0"
5
5
  end
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.2.1
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-22 00:00:00.000000000 Z
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.4.5
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.