Module: BerkeleyLibrary::Alma::SRU
- Extended by:
- SRU
- Includes:
- Constants, Logging
- Included in:
- SRU
- Defined in:
- lib/berkeley_library/alma/sru/sru.rb,
lib/berkeley_library/alma/sru/xml_reader.rb
Defined Under Namespace
Classes: XMLReader
Constant Summary collapse
- DEFAULT_MAX_RECORDS =
10
Constants included from Constants
Constants::ALMA_RECORD_RE, Constants::DEFAULT_USER_AGENT, Constants::MILLENNIUM_RECORD_RE
Instance Method Summary collapse
-
#get_marc_records(*record_ids, max_records: DEFAULT_MAX_RECORDS, freeze: false) ⇒ Enumerator::Lazy<MARC::Record>
Given a list of record IDs, returns the MARC records for each ID (if found).
-
#make_sru_query(query_value, max_records: DEFAULT_MAX_RECORDS) ⇒ String?
Makes an SRU query for the specified query value and returns the query response as a string.
-
#marc_records_for(query_value, max_records: DEFAULT_MAX_RECORDS, freeze: false) ⇒ Enumerator::Lazy<MARC::Record>
Makes an SRU query for the specified query value and returns the query response as MARC records.
-
#sru_query_uri(sru_query_value, max_records: DEFAULT_MAX_RECORDS) ⇒ URI
Returns a URI for retrieving records for the specified query via SRU.
Instance Method Details
#get_marc_records(*record_ids, max_records: DEFAULT_MAX_RECORDS, freeze: false) ⇒ Enumerator::Lazy<MARC::Record>
Given a list of record IDs, returns the MARC records for each ID (if found). Note that the order of the records is not guaranteed.
27 28 29 30 31 32 33 34 |
# File 'lib/berkeley_library/alma/sru/sru.rb', line 27 def get_marc_records(*record_ids, max_records: DEFAULT_MAX_RECORDS, freeze: false) # noinspection RubyMismatchedReturnType parsed_ids = record_ids.filter_map { |id| RecordId.parse(id) } raise ArgumentError, "Argument #{record_ids.inspect} contain no valid record IDs" if parsed_ids.empty? sru_query_value = parsed_ids.map(&:sru_query_value).join(' or ') SRU.marc_records_for(sru_query_value, max_records: max_records, freeze: freeze) end |
#make_sru_query(query_value, max_records: DEFAULT_MAX_RECORDS) ⇒ String?
Makes an SRU query for the specified query value and returns the query response as a string.
57 58 59 60 |
# File 'lib/berkeley_library/alma/sru/sru.rb', line 57 def make_sru_query(query_value, max_records: DEFAULT_MAX_RECORDS) uri = sru_query_uri(query_value, max_records: max_records) do_get(uri) end |
#marc_records_for(query_value, max_records: DEFAULT_MAX_RECORDS, freeze: false) ⇒ Enumerator::Lazy<MARC::Record>
Makes an SRU query for the specified query value and returns the query response as MARC records.
69 70 71 72 73 74 |
# File 'lib/berkeley_library/alma/sru/sru.rb', line 69 def marc_records_for(query_value, max_records: DEFAULT_MAX_RECORDS, freeze: false) Enumerator.new do |y| uri = sru_query_uri(query_value, max_records: max_records) perform_query(uri, freeze: freeze) { |rec| y << rec } end.lazy end |
#sru_query_uri(sru_query_value, max_records: DEFAULT_MAX_RECORDS) ⇒ URI
Returns a URI for retrieving records for the specified query via SRU. Requires Config.alma_sru_base_uri to be set.
41 42 43 44 45 46 47 48 49 |
# File 'lib/berkeley_library/alma/sru/sru.rb', line 41 def sru_query_uri(sru_query_value, max_records: DEFAULT_MAX_RECORDS) query_string = URI.encode_www_form( 'version' => '1.2', 'operation' => 'searchRetrieve', 'query' => sru_query_value ) Util::URIs.append(Config.alma_sru_base_uri, '?', query_string, '&', "maximumRecords=#{max_records}") end |