Sha256: f9ba8b2c10d9b1c23f82f0e77dba8377c843d0e46bd935d12cbdc97b146a7d13

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true

module PurlFetcher
  class Client
    # Withdraw / restore a version of an item from the purl-fetcher cache
    class Withdraw
      # @param [String] druid the identifier of the item
      # @param [String] version the version of the item
      def self.withdraw(druid:, version:)
        new(druid:, version:).withdraw
      end

      # @param [String] druid the identifier of the item
      # @param [String] version the version of the item
      def self.restore(druid:, version:)
        new(druid:, version:).restore
      end

      # @param [String] druid the identifier of the item
      # @param [String] version the version of the item
      def initialize(druid:, version:)
        @druid = druid
        @version = version
      end

      def withdraw
        logger.debug("Starting a withdraw request for: #{druid} (#{version})")
        response = client.put(path: path(:withdraw))
        logger.debug("Withdraw request complete")
        response
      end

      def restore
        logger.debug("Starting a restore request for: #{druid} (#{version})")
        response = client.put(path: path(:restore))
        logger.debug("Withdraw request complete")
        response
      end

      private

      attr_reader :druid, :version

      def logger
        Client.config.logger
      end

      def client
        Client.instance
      end

      def path(action)
        "/v1/purls/#{druid}/versions/#{version}/#{action}"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
purl_fetcher-client-2.1.2 lib/purl_fetcher/client/withdraw.rb
purl_fetcher-client-2.1.1 lib/purl_fetcher/client/withdraw.rb
purl_fetcher-client-2.1.0 lib/purl_fetcher/client/withdraw.rb