Sha256: 21186316563ee3ec5a93cc757ff984102b4aaebb55d3554028dfae6a0f38e2b5

Contents?: true

Size: 1.05 KB

Versions: 7

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module PurlFetcher
  class Client
    # Publish (metadata-only) to the purl cache
    class Publish
      def self.publish(...)
        new(...).publish
      end

      # @param [Cocina::Models::DRO,Cocina::Models::Collection] cocina the Cocina data object
      # @param [Hash<String,String>] file_uploads map of filenames to signed_ids
      def initialize(cocina:, file_uploads:)
        @cocina = cocina
        @file_uploads = file_uploads
      end

      def publish
        logger.debug("Starting a publish request for: #{druid}")
        client.post(path:, body:)
        logger.debug("Publish request complete")
      end

      private

      attr_reader :cocina, :file_uploads

      def druid
        cocina.externalIdentifier
      end

      def body
        {
          object: cocina.to_h,
          file_uploads: file_uploads
      }.to_json
      end

      def logger
        Client.config.logger
      end

      def client
        Client.instance
      end

      def path
        "/v1/resources"
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
purl_fetcher-client-1.5.4 lib/purl_fetcher/client/publish.rb
purl_fetcher-client-1.5.3 lib/purl_fetcher/client/publish.rb
purl_fetcher-client-1.5.2 lib/purl_fetcher/client/publish.rb
purl_fetcher-client-1.5.1 lib/purl_fetcher/client/publish.rb
purl_fetcher-client-1.5.0 lib/purl_fetcher/client/publish.rb
purl_fetcher-client-1.4.1 lib/purl_fetcher/client/publish.rb
purl_fetcher-client-1.4.0 lib/purl_fetcher/client/publish.rb