Sha256: d231131436d599e1679c0821e0fb591dd71fc03f26933c7e9bd1a15cb4fc1c82

Contents?: true

Size: 993 Bytes

Versions: 5

Compression:

Stored size: 993 Bytes

Contents

# frozen_string_literal: true

class FolioClient
  # Lookup records in Folio Source Storage
  class SourceStorage
    attr_accessor :client

    # @param client [FolioClient] the configured client
    def initialize(client)
      @client = client
    end

    # @param instance_hrid [String] the key to use for MARC lookup
    # @return [Hash] hash representation of the MARC. should be usable by MARC::Record.new_from_hash (from ruby-marc gem)
    # @raises NotFound, MultipleRecordsForIdentifier
    def fetch_marc_hash(instance_hrid:)
      response_hash = client.get("/source-storage/source-records", {instanceHrid: instance_hrid})

      record_count = response_hash["totalRecords"]
      raise ResourceNotFound, "No records found for #{instance_hrid}" if record_count.zero?
      raise MultipleResourcesFound, "Expected 1 record for #{instance_hrid}, but found #{record_count}" if record_count > 1

      response_hash["sourceRecords"].first["parsedRecord"]["content"]
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
folio_client-0.8.0 lib/folio_client/source_storage.rb
folio_client-0.7.0 lib/folio_client/source_storage.rb
folio_client-0.6.1 lib/folio_client/source_storage.rb
folio_client-0.6.0 lib/folio_client/source_storage.rb
folio_client-0.5.0 lib/folio_client/source_storage.rb