Sha256: 3f0b9803693ec145cee4bec540720a3def54294e31ab59a9185515473f56604c

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 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

    # get marc bib data from folio given an instance HRID
    # @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)
    # @raise [ResourceNotFound]
    # @raise [MultipleResourcesFound]
    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

3 entries across 3 versions & 1 rubygems

Version Path
folio_client-0.12.0 lib/folio_client/source_storage.rb
folio_client-0.11.0 lib/folio_client/source_storage.rb
folio_client-0.10.1 lib/folio_client/source_storage.rb