Sha256: 3989ab39abaf1b40c4283ec820560af7f3ab502c0de31e7dd9f3b0cc68810779

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

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 FolioClient::UnexpectedResponse::ResourceNotFound, "No records found for #{instance_hrid}" if record_count.zero?
      raise FolioClient::UnexpectedResponse::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

3 entries across 3 versions & 1 rubygems

Version Path
folio_client-0.4.0 lib/folio_client/source_storage.rb
folio_client-0.3.1 lib/folio_client/source_storage.rb
folio_client-0.3.0 lib/folio_client/source_storage.rb