folio_api_client 0.1.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 954b7e6b1e48039f364a809e5106625b64d86befca6cfb581b044395b793cc4b
4
- data.tar.gz: afa3897ee6b420e72e38cced7c3206d9bdefed076214a3bea7216b6abf5bb2e1
3
+ metadata.gz: cd0f25ee382d9468806b7ae7c39a0d7801f43d5e45c7f7bd248565673fe9da23
4
+ data.tar.gz: e05cb433eb2134c574d2de93a3e9de4cdad6a4c9bd9c6ae3f67483179f64e855
5
5
  SHA512:
6
- metadata.gz: a3ed8ef0912573e43adc2263ab65e5096f06bdd6118946fa5e2b9276bdd17e2ea9e88fe98027c1d0d2040a30036afff7ff009d70ee8bf87c11e2be87912e7ce4
7
- data.tar.gz: 8ff84094f0a2be25a608e313bd29369d3f72a295be31903aa97b261c041fcd4361c4690c2fb609766670b9ed3dd74473aa19dc3c27142eccaa188c2f9bcddcbb
6
+ metadata.gz: f68f5dab0e5080f62b307c8f72bf2fb75e5d4033f7fb70fdfdd99f749edf821ae2c9d1c697e31f70f8af4e1be60aa55c930c9c9bd494348fbff9fe1e7337e563
7
+ data.tar.gz: 6cdc0f1d8a571a11599ae906f985f0e2901dedcbc07b8f26f71f316337507693dd22ea0f8a841bbd6083ce6436c5b7dbebe252f4f54d685bb1366c66ec29ebdf
data/README.md CHANGED
@@ -4,9 +4,15 @@ A Ruby interface for making requests to the FOLIO ILS API (https://folio.org), i
4
4
 
5
5
  ## Installation
6
6
 
7
- At this time, this gem is only available on GitHub and has not been published to RubyGems yet. You can include it in your Gemfile using this syntax:
7
+ ```bash
8
+ bundle add folio_api_client
9
+ ```
10
+
11
+ If bundler is not being used to manage dependencies, you can install the gem by running:
8
12
 
9
- `gem 'folio_api_client', github: 'cul/folio_api_client', branch: 'main'`
13
+ ```bash
14
+ gem install folio_api_client
15
+ ```
10
16
 
11
17
  ## Usage
12
18
 
@@ -36,6 +42,14 @@ client.get(path, params)
36
42
  client.post(path, body, content_type: 'application/json'))
37
43
  client.put(path, body, content_type: 'application/json'))
38
44
  client.delete(path, body, content_type: 'application/json'))
45
+
46
+ # Other convenience methods:
47
+
48
+ client.find_item_record(barcode: 'some-barcode')
49
+ client.find_location_record(location_id: 'some-location-id')
50
+ client.find_holdings_record(holdings_record_id: 'some-holdings-record-id')
51
+ client.find_instance_record(instance_record_id: 'some-instance-record-id')
52
+ client.find_marc_record(instance_record_id: 'some-instance-record-id') # returns a MARC::Record
39
53
  ```
40
54
 
41
55
  See [https://dev.folio.org/reference/api/](https://dev.folio.org/reference/api/) for the full list of available FOLIO API endpoints.
@@ -3,5 +3,7 @@
3
3
  class FolioApiClient
4
4
  module Exceptions
5
5
  class Error < StandardError; end
6
+ class UnexpectedMultipleRecordsFoundError < Error; end
7
+ class MissingQueryFieldError < Error; end
6
8
  end
7
9
  end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FolioApiClient
4
+ module Finders
5
+ def find_item_record(barcode:)
6
+ item_search_results = self.get('/item-storage/items', { query: "barcode==#{barcode}", limit: 2 })['items']
7
+ return nil if item_search_results.empty?
8
+
9
+ if item_search_results.length > 1
10
+ raise FolioApiClient::Exceptions::UnexpectedMultipleRecordsFoundError,
11
+ 'Only expected one item with this barcode, but found more than one.'
12
+ end
13
+
14
+ item_record_id = item_search_results.first['id']
15
+ self.get("/item-storage/items/#{item_record_id}")
16
+ end
17
+
18
+ def find_location_record(location_id:)
19
+ self.get("/locations/#{location_id}")
20
+ end
21
+
22
+ def find_holdings_record(holdings_record_id:)
23
+ self.get("/holdings-storage/holdings/#{holdings_record_id}")
24
+ end
25
+
26
+ def find_instance_record(instance_record_id:)
27
+ self.get("/instance-storage/instances/#{instance_record_id}")
28
+ end
29
+
30
+ # Find a MARC::Record by its instance record id or instance record hrid
31
+ def find_marc_record(instance_record_id: nil, instance_record_hrid: nil)
32
+ source_record_search_results = self.get(
33
+ '/source-storage/source-records',
34
+ marc_record_query(instance_record_id: instance_record_id, instance_record_hrid: instance_record_hrid)
35
+ )
36
+ return nil if source_record_search_results['totalRecords'].zero?
37
+
38
+ bib_record_marc_hash = source_record_search_results['sourceRecords'].first['parsedRecord']['content']
39
+ MARC::Record.new_from_hash(bib_record_marc_hash)
40
+ end
41
+
42
+ def marc_record_query(instance_record_id: nil, instance_record_hrid: nil)
43
+ return { instanceId: instance_record_id } if instance_record_id
44
+ return { instanceHrid: instance_record_hrid } if instance_record_hrid
45
+
46
+ raise FolioApiClient::Exceptions::MissingQueryFieldError,
47
+ 'Missing query field. Must supply either an instance_record_id or instance_record_hrid.'
48
+ end
49
+ end
50
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class FolioApiClient
4
- VERSION = '0.1.0'
4
+ VERSION = '0.3.0'
5
5
  end
@@ -5,9 +5,12 @@ loader = Zeitwerk::Loader.for_gem
5
5
  loader.setup # ready!
6
6
 
7
7
  require 'faraday'
8
+ require 'marc'
8
9
 
9
10
  # A client used for making http requests (get/post/etc.) to the FOLIO ILS REST API.
10
11
  class FolioApiClient
12
+ include Finders
13
+
11
14
  attr_reader :config
12
15
 
13
16
  def initialize(config)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: folio_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric O'Hanlon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-04-29 00:00:00.000000000 Z
11
+ date: 2025-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -68,6 +68,7 @@ files:
68
68
  - lib/folio_api_client.rb
69
69
  - lib/folio_api_client/configuration.rb
70
70
  - lib/folio_api_client/exceptions.rb
71
+ - lib/folio_api_client/finders.rb
71
72
  - lib/folio_api_client/version.rb
72
73
  homepage: https://www.github.com/cul/folio_api_client
73
74
  licenses: []