Sha256: 08c3124a75d7f0d95656aa28205333a254ca5a3113c0898574001f4c225b93de

Contents?: true

Size: 1.41 KB

Versions: 18

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

module SdrClient
  module Deposit
    # Updates a resource (metadata) in SDR
    class UpdateResource
      DRO_PATH = '/v1/resources/%<id>s'

      def self.run(metadata:, logger:, connection:)
        new(metadata: metadata, logger: logger, connection: connection).run
      end

      # @param [Cocina::Models::DRO] metadata
      # @param [Hash<Symbol,String>] the result of the metadata call
      def initialize(metadata:, logger:, connection:)
        @metadata = metadata
        @logger = logger
        @connection = connection
      end

      # @param [Hash<Symbol,String>] the result of the metadata call
      # @return [String] job id for the background job result
      def run
        response = metadata_request
        UnexpectedResponse.call(response) unless response.status == 202

        logger.info("Response from server: #{response.body}")

        JSON.parse(response.body)['jobId']
      end

      private

      attr_reader :metadata, :logger, :connection

      def metadata_request
        json = metadata.to_json
        logger.debug("Starting upload metadata: #{json}")

        connection.put(path(metadata), json,
                       'Content-Type' => 'application/json',
                       'X-Cocina-Models-Version' => Cocina::Models::VERSION)
      end

      def path(metadata)
        format(DRO_PATH, id: metadata.externalIdentifier)
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
sdr-client-0.69.1 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.69.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.68.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.67.1 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.67.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.66.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.65.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.64.1 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.64.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.63.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.62.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.61.1 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.61.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.60.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.59.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.58.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.57.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.56.0 lib/sdr_client/deposit/update_resource.rb