folio_api_client 0.2.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: b1529c6d23ad243ce9503b24965a0afc4db6abd28a6cea7aae1000b42b5a19b0
4
- data.tar.gz: 8da619e1c7614fe9bf46951af5ee6c086467ec90869d0f32ba9803584b65487a
3
+ metadata.gz: cd0f25ee382d9468806b7ae7c39a0d7801f43d5e45c7f7bd248565673fe9da23
4
+ data.tar.gz: e05cb433eb2134c574d2de93a3e9de4cdad6a4c9bd9c6ae3f67483179f64e855
5
5
  SHA512:
6
- metadata.gz: c6196344ec464f39dfdd0b44dbd269f3b949a630c7a41d449961a73091f494ad1d49edff1eb39d2f79b4d36ee0b9f6456257cb2ca645a4d8d1a4c8f0b3c50cd0
7
- data.tar.gz: 064356b0fe0d418128ae36d101005229d3eb766f89a62456a6b024bedb5a9d748e42335177918985c34a2bef7ed4a0168c54f38b6bea58a5fd2ed3b0508e86f4
6
+ metadata.gz: f68f5dab0e5080f62b307c8f72bf2fb75e5d4033f7fb70fdfdd99f749edf821ae2c9d1c697e31f70f8af4e1be60aa55c930c9c9bd494348fbff9fe1e7337e563
7
+ data.tar.gz: 6cdc0f1d8a571a11599ae906f985f0e2901dedcbc07b8f26f71f316337507693dd22ea0f8a841bbd6083ce6436c5b7dbebe252f4f54d685bb1366c66ec29ebdf
data/README.md CHANGED
@@ -42,6 +42,14 @@ client.get(path, params)
42
42
  client.post(path, body, content_type: 'application/json'))
43
43
  client.put(path, body, content_type: 'application/json'))
44
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
45
53
  ```
46
54
 
47
55
  See [https://dev.folio.org/reference/api/](https://dev.folio.org/reference/api/) for the full list of available FOLIO API endpoints.
@@ -4,5 +4,6 @@ class FolioApiClient
4
4
  module Exceptions
5
5
  class Error < StandardError; end
6
6
  class UnexpectedMultipleRecordsFoundError < Error; end
7
+ class MissingQueryFieldError < Error; end
7
8
  end
8
9
  end
@@ -27,12 +27,24 @@ class FolioApiClient
27
27
  self.get("/instance-storage/instances/#{instance_record_id}")
28
28
  end
29
29
 
30
- def find_marc_record(instance_record_id:)
31
- source_record_search_results = self.get('/source-storage/source-records', { instanceId: instance_record_id })
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
+ )
32
36
  return nil if source_record_search_results['totalRecords'].zero?
33
37
 
34
38
  bib_record_marc_hash = source_record_search_results['sourceRecords'].first['parsedRecord']['content']
35
39
  MARC::Record.new_from_hash(bib_record_marc_hash)
36
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
37
49
  end
38
50
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class FolioApiClient
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: folio_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric O'Hanlon