folio_client 0.12.0 → 0.13.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: 7918be772bc1758840166cbb6f0fb66bfbf4765f636118d971efef2192a947df
4
- data.tar.gz: 86d3c7e5656e849cf3358ddf7e22463bd65527cedf017a9a31dfdd2606bad88a
3
+ metadata.gz: c3b597d27e912d256a895af940e312d24e85acf5c234f48788c6716a4e8947de
4
+ data.tar.gz: 9700fb07ff086e5b6c833897abd921adaa8efd19e173c8948484ad5d554614a2
5
5
  SHA512:
6
- metadata.gz: 9471247fec95c9df775cd359896c788d124173477b74f1124d41641f76e6d61438fe7b5e7c10fb3ee7d6efb9f5dba11c9b0b7b45fb9040520f6668cba626fc1d
7
- data.tar.gz: 4f0adf00bb277b709a68552e7f2b5119e7b8597723ffc3c4f500d850e2c8470df0249a19e35a98bcfcf2ef6daa3befb8155e57d5f69c8d825fe3b1806cd240a5
6
+ metadata.gz: a8256c90e8c80390e5536d4c988140d30074481d6d8b958a3e8321b81e6dc0f2f7634f3e5253abe7c9b60b22fbebb5246fe6f9052c93b658d621a108a1598ff9
7
+ data.tar.gz: 99e52e340c66cc0233e577e73840880c2a0f9b2eea758b42418784124a524d1c7d1fc73ede20dd8bdd77aa0d69f44843eebd0f82e08067306b687b0082dc326b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- folio_client (0.12.0)
4
+ folio_client (0.13.0)
5
5
  activesupport (>= 4.2, < 8)
6
6
  dry-monads
7
7
  faraday
@@ -72,7 +72,7 @@ GEM
72
72
  diff-lcs (>= 1.2.0, < 2.0)
73
73
  rspec-support (~> 3.12.0)
74
74
  rspec-support (3.12.1)
75
- rubocop (1.56.3)
75
+ rubocop (1.56.4)
76
76
  base64 (~> 0.1.1)
77
77
  json (~> 2.3)
78
78
  language_server-protocol (>= 3.17.0)
@@ -86,14 +86,14 @@ GEM
86
86
  unicode-display_width (>= 2.4.0, < 3.0)
87
87
  rubocop-ast (1.29.0)
88
88
  parser (>= 3.2.1.0)
89
- rubocop-capybara (2.18.0)
89
+ rubocop-capybara (2.19.0)
90
90
  rubocop (~> 1.41)
91
91
  rubocop-factory_bot (2.24.0)
92
92
  rubocop (~> 1.33)
93
93
  rubocop-performance (1.19.1)
94
94
  rubocop (>= 1.7.0, < 2.0)
95
95
  rubocop-ast (>= 0.4.0)
96
- rubocop-rspec (2.24.0)
96
+ rubocop-rspec (2.24.1)
97
97
  rubocop (~> 1.33)
98
98
  rubocop-capybara (~> 2.17)
99
99
  rubocop-factory_bot (~> 2.22)
@@ -123,12 +123,12 @@ GEM
123
123
  unf (0.1.4)
124
124
  unf_ext
125
125
  unf_ext (0.0.8.2)
126
- unicode-display_width (2.4.2)
126
+ unicode-display_width (2.5.0)
127
127
  webmock (3.19.1)
128
128
  addressable (>= 2.8.0)
129
129
  crack (>= 0.3.2)
130
130
  hashdiff (>= 0.4.0, < 2.0.0)
131
- zeitwerk (2.6.11)
131
+ zeitwerk (2.6.12)
132
132
 
133
133
  PLATFORMS
134
134
  x86_64-darwin-19
data/README.md CHANGED
@@ -131,6 +131,22 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
131
131
 
132
132
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
133
133
 
134
+ ## Integration Testing
135
+
136
+ To test that the gem works against the Folio APIs, run `api_test.rb` via:
137
+
138
+ ```shell
139
+ # NOTE: This is bash syntax, YMMV
140
+ $ export OKAPI_PASSWORD=$(vault kv get --field=content puppet/application/folio/stage/app_sdr_password)
141
+ $ export OKAPI_TENANT=sul
142
+ $ export OKAPI_USER=app_sdr
143
+ $ export OKAPI_URL=https://okapi-stage.stanford.edu
144
+ # NOTE: The args below are a list of MARC files
145
+ $ bundle exec ruby ./api_test.rb /path/to/marc/files/test.mrc /another/marc/file/at/foobar.marc
146
+ ```
147
+
148
+ Inspect the output and make sure there are no errors.
149
+
134
150
  ## Contributing
135
151
 
136
152
  Bug reports and pull requests are welcome on GitHub at https://github.com/sul-dlss/folio_client.
data/api_test.rb ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "folio_client"
5
+
6
+ marc_files = *ARGV
7
+
8
+ client =
9
+ FolioClient.configure(
10
+ url: ENV["OKAPI_URL"],
11
+ login_params: {
12
+ username: ENV["OKAPI_USER"],
13
+ password: ENV["OKAPI_PASSWORD"]
14
+ },
15
+ okapi_headers: {
16
+ "X-Okapi-Tenant": ENV["OKAPI_TENANT"],
17
+ "User-Agent": "folio_client gem (testing)"
18
+ }
19
+ )
20
+
21
+ pp(client.fetch_marc_hash(instance_hrid: "a666"))
22
+
23
+ puts client.fetch_marc_xml(instance_hrid: "a666")
24
+ puts client.fetch_marc_xml(barcode: "20503330279")
25
+
26
+ records = marc_files.flat_map do |marc_file_path|
27
+ MARC::Reader.new(marc_file_path).to_a
28
+ end
29
+
30
+ data_importer =
31
+ client.data_import(
32
+ records: records,
33
+ job_profile_id: "e34d7b92-9b83-11eb-a8b3-0242ac130003",
34
+ job_profile_name: "Default - Create instance and SRS MARC Bib"
35
+ )
36
+
37
+ puts data_importer.wait_until_complete
38
+ puts data_importer.instance_hrids
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "date"
4
- require "marc"
5
4
  require "stringio"
6
5
 
7
6
  class FolioClient
@@ -3,6 +3,8 @@
3
3
  class FolioClient
4
4
  # Lookup records in Folio Source Storage
5
5
  class SourceStorage
6
+ FIELDS_TO_REMOVE = %w[001 003].freeze
7
+
6
8
  attr_accessor :client
7
9
 
8
10
  # @param client [FolioClient] the configured client
@@ -24,5 +26,36 @@ class FolioClient
24
26
 
25
27
  response_hash["sourceRecords"].first["parsedRecord"]["content"]
26
28
  end
29
+
30
+ # get marc bib data as MARCXML from folio given an instance HRID
31
+ # @param instance_hrid [String] the instance HRID to use for MARC lookup
32
+ # @param barcode [String] the barcode to use for MARC lookup
33
+ # @return [String] MARCXML string
34
+ # @raise [ResourceNotFound]
35
+ # @raise [MultipleResourcesFound]
36
+ def fetch_marc_xml(instance_hrid: nil, barcode: nil)
37
+ raise ArgumentError, "Either a barcode or a Folio instance HRID must be provided" if barcode.nil? && instance_hrid.nil?
38
+
39
+ instance_hrid ||= client.fetch_hrid(barcode: barcode)
40
+
41
+ raise ResourceNotFound, "Catalog record not found. HRID: #{instance_hrid} | Barcode: #{barcode}" if instance_hrid.blank?
42
+
43
+ marc_record = MARC::Record.new_from_hash(
44
+ fetch_marc_hash(instance_hrid: instance_hrid)
45
+ )
46
+ updated_marc = MARC::Record.new
47
+ updated_marc.leader = marc_record.leader
48
+ marc_record.fields.each do |field|
49
+ # explicitly remove all listed tags from the record
50
+ next if FIELDS_TO_REMOVE.include?(field.tag)
51
+
52
+ updated_marc.fields << field
53
+ end
54
+ # explicitly inject the instance_hrid into the 001 field
55
+ updated_marc.fields << MARC::ControlField.new("001", instance_hrid)
56
+ # explicitly inject FOLIO into the 003 field
57
+ updated_marc.fields << MARC::ControlField.new("003", "FOLIO")
58
+ updated_marc.to_xml.to_s
59
+ end
27
60
  end
28
61
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class FolioClient
4
- VERSION = "0.12.0"
4
+ VERSION = "0.13.0"
5
5
  end
data/lib/folio_client.rb CHANGED
@@ -3,8 +3,9 @@
3
3
  require "active_support/core_ext/module/delegation"
4
4
  require "active_support/core_ext/object/blank"
5
5
  require "faraday"
6
- require "singleton"
6
+ require "marc"
7
7
  require "ostruct"
8
+ require "singleton"
8
9
  require "zeitwerk"
9
10
 
10
11
  # Load the gem's internal dependencies: use Zeitwerk instead of needing to manually require classes
@@ -72,10 +73,10 @@ class FolioClient
72
73
 
73
74
  delegate :config, :connection, :data_import, :default_timeout,
74
75
  :edit_marc_json, :fetch_external_id, :fetch_hrid, :fetch_instance_info,
75
- :fetch_marc_hash, :get, :has_instance_status?, :http_get_headers,
76
- :http_post_and_put_headers, :interface_details, :job_profiles,
77
- :organization_interfaces, :organizations, :post, :put, to: :instance
78
- end
76
+ :fetch_marc_hash, :fetch_marc_xml, :get, :has_instance_status?,
77
+ :http_get_headers, :http_post_and_put_headers, :interface_details,
78
+ :job_profiles, :organization_interfaces, :organizations, :post, :put, to:
79
+ :instance end
79
80
 
80
81
  attr_accessor :config
81
82
 
@@ -175,6 +176,13 @@ class FolioClient
175
176
  .fetch_marc_hash(...)
176
177
  end
177
178
 
179
+ # @see SourceStorage#fetch_marc_xml
180
+ def fetch_marc_xml(...)
181
+ SourceStorage
182
+ .new(self)
183
+ .fetch_marc_xml(...)
184
+ end
185
+
178
186
  # @see Inventory#has_instance_status?
179
187
  def has_instance_status?(...)
180
188
  Inventory
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.12.0
4
+ version: 0.13.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-09-22 00:00:00.000000000 Z
11
+ date: 2023-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -187,6 +187,7 @@ files:
187
187
  - LICENSE
188
188
  - README.md
189
189
  - Rakefile
190
+ - api_test.rb
190
191
  - folio_client.gemspec
191
192
  - lib/folio_client.rb
192
193
  - lib/folio_client/authenticator.rb
@@ -220,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
221
  - !ruby/object:Gem::Version
221
222
  version: '0'
222
223
  requirements: []
223
- rubygems_version: 3.3.7
224
+ rubygems_version: 3.4.19
224
225
  signing_key:
225
226
  specification_version: 4
226
227
  summary: Interface for interacting with the Folio ILS API.