Sha256: 4c36eb695713dd7aa20a7da389c1cc5f9631f5497f536572604f1e37bd0e9354

Contents?: true

Size: 1.31 KB

Versions: 23

Compression:

Stored size: 1.31 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')
      end

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

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
sdr-client-0.55.1 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.55.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.54.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.53.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.52.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.51.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.51.0.beta.1 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.50.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.49.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.48.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.47.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.46.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.45.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.44.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.43.1 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.43.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.42.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.41.0 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.40.1 lib/sdr_client/deposit/update_resource.rb
sdr-client-0.40.0 lib/sdr_client/deposit/update_resource.rb