berkeley_library-alma 0.0.6 → 0.0.7

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: ab227f94abea9d1275bceb4ed361cf2d75021ae7d9cf49283e6139404e9e327f
4
- data.tar.gz: 2370efa8b2bc2b72e6e506cf38271a74ee8a785cbebf7f42b19e49bf84b4a6da
3
+ metadata.gz: 1c1b867f1a283eccf4a721f805d351af4292624f787ae44477330f39d0579905
4
+ data.tar.gz: 15abfaec0a2bf5cfab9b096b2636cfebe320a458661b251b095dfdae71c94b4f
5
5
  SHA512:
6
- metadata.gz: 438181aea5e19163ca57dd7c5c9086fd6d324ac5bb6e05fd33917cc70327ca5682e1f07a9ffc5280104207562f6fdda4443070bdc8ba3163b519ba70f96f2558
7
- data.tar.gz: dc9cafbf0b36ee0ac1875d8cc89b0b4a10bdccd37456f67004e0c3abb0097fde7b8d5da31c946ab1eb4f300dd1f14ad5dcaf550ca697aef0de4f8b6d81521bdb
6
+ metadata.gz: db9c0732aa97dd07877d0b12277d6841c18d501fd4239899fc50b97d6ae15d3467c88a502dae0ac0aaa42504fdc06ab67e5841ceff265819f5b3262acd136ab8
7
+ data.tar.gz: aa6053bdfd55d475256a8acd05ae0fd23990d8b0269d6ddf7a385ab96ef1d53c011773a96c28a71ee73b25794bebe10abd589e5f95bb5353923139e489df3361
data/.idea/alma.iml CHANGED
@@ -45,7 +45,6 @@
45
45
  <orderEntry type="library" scope="PROVIDED" name="method_source (v1.0.0, RVM: ruby-2.7.5) [gem]" level="application" />
46
46
  <orderEntry type="library" scope="PROVIDED" name="mime-types (v3.4.1, RVM: ruby-2.7.5) [gem]" level="application" />
47
47
  <orderEntry type="library" scope="PROVIDED" name="mime-types-data (v3.2022.0105, RVM: ruby-2.7.5) [gem]" level="application" />
48
- <orderEntry type="library" scope="PROVIDED" name="mini_portile2 (v2.8.0, RVM: ruby-2.7.5) [gem]" level="application" />
49
48
  <orderEntry type="library" scope="PROVIDED" name="minitest (v5.15.0, RVM: ruby-2.7.5) [gem]" level="application" />
50
49
  <orderEntry type="library" scope="PROVIDED" name="netrc (v0.11.0, RVM: ruby-2.7.5) [gem]" level="application" />
51
50
  <orderEntry type="library" scope="PROVIDED" name="nokogiri (v1.13.5, RVM: ruby-2.7.5) [gem]" level="application" />
data/CHANGES.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 0.0.7 (6 May 2022)
2
+
3
+ - `SRU#get_marc_records` now accepts a `max_records` parameter corresponding to the SRU
4
+ `maximumRecords` query parameter for page size.
5
+ - `BerkeleyLibrary::Alma::Config.default!` now returns the `Config` singleton rather than
6
+ an arbitrary config value.
7
+
1
8
  # 0.0.6 (5 May 2022)
2
9
 
3
10
  - `SRU#get_marc_records` now supports paginated results.
@@ -118,10 +118,12 @@ module BerkeleyLibrary
118
118
 
119
119
  def default!
120
120
  BerkeleyLibrary::Alma.configure do
121
- config.alma_sru_host = ENV.fetch('LIT_ALMA_SRU_HOST', 'berkeley.alma.exlibrisgroup.com')
122
- config.alma_institution_code = ENV.fetch('LIT_ALMA_INSTITUTION_CODE', '01UCS_BER')
123
- config.alma_primo_host = ENV.fetch('LIT_ALMA_PRIMO_HOST', 'search.library.berkeley.edu')
124
- config.alma_permalink_key = ENV.fetch('LIT_ALMA_PERMALINK_KEY', 'iqob43')
121
+ config.tap do |c|
122
+ c.alma_sru_host = ENV.fetch('LIT_ALMA_SRU_HOST', 'berkeley.alma.exlibrisgroup.com')
123
+ c.alma_institution_code = ENV.fetch('LIT_ALMA_INSTITUTION_CODE', '01UCS_BER')
124
+ c.alma_primo_host = ENV.fetch('LIT_ALMA_PRIMO_HOST', 'search.library.berkeley.edu')
125
+ c.alma_permalink_key = ENV.fetch('LIT_ALMA_PERMALINK_KEY', 'iqob43')
126
+ end
125
127
  end
126
128
  end
127
129
 
@@ -7,7 +7,7 @@ module BerkeleyLibrary
7
7
  SUMMARY = 'Alma/Primo utilities for the UC Berkeley Library'.freeze
8
8
  DESCRIPTION = 'A gem providing Alma/Primo-related utility code for the UC Berkeley Library'.freeze
9
9
  LICENSE = 'MIT'.freeze
10
- VERSION = '0.0.6'.freeze
10
+ VERSION = '0.0.7'.freeze
11
11
  HOMEPAGE = 'https://github.com/BerkeleyLibrary/alma'.freeze
12
12
  end
13
13
  end
@@ -48,7 +48,7 @@ module BerkeleyLibrary
48
48
  #
49
49
  # @return [URI] the MARC URI
50
50
  def marc_uri
51
- SRU.sru_query_uri(sru_query_value)
51
+ SRU.sru_query_uri(sru_query_value, max_records: 1)
52
52
  end
53
53
 
54
54
  # Makes an SRU query for this record and returns a MARC record, or nil if the
@@ -60,7 +60,7 @@ module BerkeleyLibrary
60
60
  # @return [MARC::Record, nil] the MARC record
61
61
  # rubocop:disable Naming/AccessorMethodName
62
62
  def get_marc_record
63
- records = SRU.marc_records_for(sru_query_value)
63
+ records = SRU.marc_records_for(sru_query_value, max_records: 1)
64
64
  logger.warn("GET #{marc_uri} did not return a MARC record") unless (marc_record = records.first)
65
65
  marc_record
66
66
  end
@@ -72,7 +72,7 @@ module BerkeleyLibrary
72
72
  # @return [String, nil] the SRU query response body, or nil in the event of an error.
73
73
  # rubocop:disable Naming/AccessorMethodName
74
74
  def get_marc_xml
75
- SRU.make_sru_query(sru_query_value)
75
+ SRU.make_sru_query(sru_query_value, max_records: 1)
76
76
  end
77
77
  # rubocop:enable Naming/AccessorMethodName
78
78
 
@@ -11,6 +11,8 @@ module BerkeleyLibrary
11
11
  include BerkeleyLibrary::Logging
12
12
  include Constants
13
13
 
14
+ DEFAULT_MAX_RECORDS = 10
15
+
14
16
  class << self
15
17
  include SRU
16
18
  end
@@ -20,37 +22,40 @@ module BerkeleyLibrary
20
22
  #
21
23
  # @param record_ids [Array<String, RecordId>] the record IDs to look up
22
24
  # @param freeze [Boolean] whether to freeze the records
25
+ # @param max_records the number of records per SRU page.
23
26
  # @return [Enumerator::Lazy<MARC::Record>] the records
24
- def get_marc_records(*record_ids, freeze: false)
27
+ def get_marc_records(*record_ids, max_records: DEFAULT_MAX_RECORDS, freeze: false)
25
28
  # noinspection RubyMismatchedReturnType
26
29
  parsed_ids = record_ids.filter_map { |id| RecordId.parse(id) }
27
30
  raise ArgumentError, "Argument #{record_ids.inspect} contain no valid record IDs" if parsed_ids.empty?
28
31
 
29
32
  sru_query_value = parsed_ids.map(&:sru_query_value).join(' or ')
30
- SRU.marc_records_for(sru_query_value, freeze: freeze)
33
+ SRU.marc_records_for(sru_query_value, max_records: max_records, freeze: freeze)
31
34
  end
32
35
 
33
36
  # Returns a URI for retrieving records for the specified query
34
37
  # via SRU. Requires {Config#alma_sru_base_uri} to be set.
35
38
  #
36
39
  # @return [URI] the MARC URI
37
- def sru_query_uri(sru_query_value)
40
+ # @param max_records the number of records per SRU page
41
+ def sru_query_uri(sru_query_value, max_records: DEFAULT_MAX_RECORDS)
38
42
  query_string = URI.encode_www_form(
39
43
  'version' => '1.2',
40
44
  'operation' => 'searchRetrieve',
41
45
  'query' => sru_query_value
42
46
  )
43
47
 
44
- Util::URIs.append(Config.alma_sru_base_uri, '?', query_string)
48
+ Util::URIs.append(Config.alma_sru_base_uri, '?', query_string, '&', "maximumRecords=#{max_records}")
45
49
  end
46
50
 
47
51
  # Makes an SRU query for the specified query value and returns the query response
48
52
  # as a string.
49
53
  #
50
54
  # @param query_value [String] the value of the SRU query parameter
55
+ # @param max_records the number of records per SRU page
51
56
  # @return [String, nil] the SRU query response body, or nil in the event of an error.
52
- def make_sru_query(query_value)
53
- uri = sru_query_uri(query_value)
57
+ def make_sru_query(query_value, max_records: DEFAULT_MAX_RECORDS)
58
+ uri = sru_query_uri(query_value, max_records: max_records)
54
59
  do_get(uri)
55
60
  end
56
61
 
@@ -59,10 +64,11 @@ module BerkeleyLibrary
59
64
  #
60
65
  # @param query_value [String] the value of the SRU query parameter
61
66
  # @param freeze [Boolean] whether to freeze the records
67
+ # @param max_records the number of records per SRU page
62
68
  # @return [Enumerator::Lazy<MARC::Record>] the records
63
- def marc_records_for(query_value, freeze: false)
69
+ def marc_records_for(query_value, max_records: DEFAULT_MAX_RECORDS, freeze: false)
64
70
  Enumerator.new do |y|
65
- uri = sru_query_uri(query_value)
71
+ uri = sru_query_uri(query_value, max_records: max_records)
66
72
  perform_query(uri, freeze: freeze) { |rec| y << rec }
67
73
  end.lazy
68
74
  end
data/spec/spec_helper.rb CHANGED
@@ -31,17 +31,17 @@ require 'berkeley_library/alma'
31
31
  # ------------------------------------------------------------
32
32
  # Utility methods
33
33
 
34
- def sru_url_for(index, value)
35
- "https://berkeley.alma.exlibrisgroup.com/view/sru/01UCS_BER?version=1.2&operation=searchRetrieve&query=#{index}%3D#{value}"
34
+ def sru_url_for(index, value, max_records: 1)
35
+ "https://berkeley.alma.exlibrisgroup.com/view/sru/01UCS_BER?version=1.2&operation=searchRetrieve&query=#{index}%3D#{value}&maximumRecords=#{max_records}"
36
36
  end
37
37
 
38
38
  def sru_data_path_for(record_id)
39
39
  "spec/data/#{record_id}-sru.xml"
40
40
  end
41
41
 
42
- def stub_sru_request(index, value)
43
- sru_url_ = sru_url_for(index, value)
42
+ def stub_sru_request(index, value, max_records: 1)
43
+ sru_url = sru_url_for(index, value, max_records: max_records)
44
44
  marc_xml_path = sru_data_path_for(value)
45
45
 
46
- stub_request(:get, sru_url_).to_return(status: 200, body: File.read(marc_xml_path))
46
+ stub_request(:get, sru_url).to_return(status: 200, body: File.read(marc_xml_path))
47
47
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berkeley_library-alma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Moles
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-05 00:00:00.000000000 Z
11
+ date: 2022-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: berkeley_library-logging