folio_client 0.4.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop/custom.yml +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +30 -2
- data/lib/folio_client/inventory.rb +2 -2
- data/lib/folio_client/source_storage.rb +2 -2
- data/lib/folio_client/token_wrapper.rb +1 -1
- data/lib/folio_client/unexpected_response.rb +0 -18
- data/lib/folio_client/version.rb +1 -1
- data/lib/folio_client.rb +19 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e45342fc554ea5de7c33e31a2bc41fd1b550cf1d60a52edd47b18f2c861846e
|
4
|
+
data.tar.gz: 13b0ddc4db0c2f73c31b2db26c48c9295ffa836e1e5e491b3308382d61021e72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5087d3b4a53111f8d442756e4ef4d7d5213c4232650fb46216c48aa877ea12c4bf5a2686ac90cbc575be3c1b7b271079357a00dd25a96f6cd7fc32a2738741f8
|
7
|
+
data.tar.gz: 1094cccbea7e0d3cfc5f0b602c78b1b1b85aa2374cd1f264dcdf569c3b7bd907153f5f9342ddc5ccc7a3a45e68e5462060f5c4452cbc1c2c5a87fd6f4bd903d8
|
data/.rubocop/custom.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
# FolioClient
|
7
7
|
|
8
|
-
FolioClient is a Ruby gem that acts as a client to the RESTful HTTP APIs provided by the Folio ILS API.
|
8
|
+
FolioClient is a Ruby gem that acts as a client to the RESTful HTTP APIs provided by the Folio ILS API. It requires ruby 3.0 or better.
|
9
9
|
|
10
10
|
## Installation
|
11
11
|
|
@@ -19,6 +19,8 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
19
19
|
|
20
20
|
## Usage
|
21
21
|
|
22
|
+
The gem should be configured first, and then you can either call API endpoints directly using GET or POST, or more commonly, use the helper methods provided, as described in the section below.
|
23
|
+
|
22
24
|
```ruby
|
23
25
|
require 'folio_client'
|
24
26
|
|
@@ -29,7 +31,9 @@ client = FolioClient.configure(
|
|
29
31
|
okapi_headers: { 'X-Okapi-Tenant': 'sul', 'User-Agent': 'FolioApiClient' }
|
30
32
|
)
|
31
33
|
|
32
|
-
response = client.get('/organizations/organizations')
|
34
|
+
response = client.get('/organizations/organizations', {query_string_param: 'abcdef'})
|
35
|
+
|
36
|
+
response = client.post('/some/post/endpoint', params_hash.to_json)
|
33
37
|
```
|
34
38
|
|
35
39
|
Note that the settings will live in the consumer of this gem and would typically be used like this:
|
@@ -44,6 +48,30 @@ client = FolioClient.configure(
|
|
44
48
|
)
|
45
49
|
```
|
46
50
|
|
51
|
+
The client is smart enough to automatically request a new token if it detects the one it is using has expired. If for some reason, you want to immediately request a new token, you can do this:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
client.config.token = FolioClient::Authenticator.token(client.config.login_params, client.connection)
|
55
|
+
```
|
56
|
+
|
57
|
+
## API Coverage
|
58
|
+
|
59
|
+
FolioClient provides a number of methods to simplify connecting to the RESTful HTTP API of the Folio API. In this section we list all of the available methods, reflecting how much of the API the client covers. Note that this assumes the client has already been configured, as described above. See dor-services-app for an example of configuration and usage.
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
# Lookup an instance hrid given a barcode
|
63
|
+
# returns a string if found, nil if nothing found
|
64
|
+
client.fetch_hrid(barcode: "12345")
|
65
|
+
=> "a7927874"
|
66
|
+
|
67
|
+
# Request a MARC record given an instance hrid
|
68
|
+
# returns a hash if found; raises FolioClient::UnexpectedResponse::ResourceNotFound if instance_hrid not found
|
69
|
+
client.fetch_marc_hash(instance_hrid: "a7927874")
|
70
|
+
=> {"fields"=>
|
71
|
+
[{"003"=>"FOLIO"}....]
|
72
|
+
}
|
73
|
+
```
|
74
|
+
|
47
75
|
## Development
|
48
76
|
|
49
77
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -26,11 +26,11 @@ class FolioClient
|
|
26
26
|
|
27
27
|
# @param hrid [String] folio instance HRID
|
28
28
|
# @param status_id [String] uuid for an instance status code
|
29
|
-
# @raise [
|
29
|
+
# @raise [ResourceNotFound] if search by hrid returns 0 results
|
30
30
|
def has_instance_status?(hrid:, status_id:)
|
31
31
|
# get the instance record and its statusId
|
32
32
|
instance = client.get("/inventory/instances", {query: "hrid==#{hrid}"})
|
33
|
-
raise
|
33
|
+
raise ResourceNotFound, "No matching instance found for #{hrid}" if instance["totalRecords"] == 0
|
34
34
|
|
35
35
|
instance_status_id = instance.dig("instances", 0, "statusId")
|
36
36
|
|
@@ -17,8 +17,8 @@ class FolioClient
|
|
17
17
|
response_hash = client.get("/source-storage/source-records", {instanceHrid: instance_hrid})
|
18
18
|
|
19
19
|
record_count = response_hash["totalRecords"]
|
20
|
-
raise
|
21
|
-
raise
|
20
|
+
raise ResourceNotFound, "No records found for #{instance_hrid}" if record_count.zero?
|
21
|
+
raise MultipleResourcesFound, "Expected 1 record for #{instance_hrid}, but found #{record_count}" if record_count > 1
|
22
22
|
|
23
23
|
response_hash["sourceRecords"].first["parsedRecord"]["content"]
|
24
24
|
end
|
@@ -3,24 +3,6 @@
|
|
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
|
-
|
9
|
-
# Error raised by the Folio Auth API returns a 422 Unauthorized
|
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
|
14
|
-
|
15
|
-
# Error raised when e.g. exactly one result was expected, but more than one was returned
|
16
|
-
class MultipleResourcesFound < FolioClientError; end
|
17
|
-
|
18
|
-
# Error raised when the Folio API returns a 403 Forbidden
|
19
|
-
class ForbiddenError < FolioClientError; end
|
20
|
-
|
21
|
-
# Error raised when the Folio API returns a 500
|
22
|
-
class ServiceUnavailable < FolioClientError; end
|
23
|
-
|
24
6
|
# @param [Faraday::Response] response
|
25
7
|
def self.call(response)
|
26
8
|
case response.status
|
data/lib/folio_client/version.rb
CHANGED
data/lib/folio_client.rb
CHANGED
@@ -13,6 +13,24 @@ Zeitwerk::Loader.for_gem.setup
|
|
13
13
|
class FolioClient
|
14
14
|
include Singleton
|
15
15
|
|
16
|
+
# Base class for all FolioClient errors
|
17
|
+
class Error < StandardError; end
|
18
|
+
|
19
|
+
# Error raised by the Folio Auth API returns a 422 Unauthorized
|
20
|
+
class UnauthorizedError < Error; end
|
21
|
+
|
22
|
+
# Error raised when the Folio API returns a 404 NotFound, or returns 0 results when one was expected
|
23
|
+
class ResourceNotFound < Error; end
|
24
|
+
|
25
|
+
# Error raised when e.g. exactly one result was expected, but more than one was returned
|
26
|
+
class MultipleResourcesFound < Error; end
|
27
|
+
|
28
|
+
# Error raised when the Folio API returns a 403 Forbidden
|
29
|
+
class ForbiddenError < Error; end
|
30
|
+
|
31
|
+
# Error raised when the Folio API returns a 500
|
32
|
+
class ServiceUnavailable < Error; end
|
33
|
+
|
16
34
|
DEFAULT_HEADERS = {
|
17
35
|
accept: "application/json, text/plain",
|
18
36
|
content_type: "application/json"
|
@@ -23,7 +41,7 @@ class FolioClient
|
|
23
41
|
# @param login_params [Hash] the folio client login params (username:, password:)
|
24
42
|
# @param okapi_headers [Hash] the okapi specific headers to add (X-Okapi-Tenant:, User-Agent:)
|
25
43
|
def configure(url:, login_params:, okapi_headers:)
|
26
|
-
instance.config = OpenStruct.new(url
|
44
|
+
instance.config = OpenStruct.new(url: url, login_params: login_params, okapi_headers: okapi_headers, token: nil)
|
27
45
|
|
28
46
|
instance.config.token = Authenticator.token(login_params, connection)
|
29
47
|
|
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.6.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-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -189,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
189
189
|
- !ruby/object:Gem::Version
|
190
190
|
version: '0'
|
191
191
|
requirements: []
|
192
|
-
rubygems_version: 3.
|
192
|
+
rubygems_version: 3.4.5
|
193
193
|
signing_key:
|
194
194
|
specification_version: 4
|
195
195
|
summary: Interface for interacting with the Folio ILS API.
|