Class: SdrClient::RedesignedClient::UpdateResource

Inherits:
Object
  • Object
show all
Defined in:
lib/sdr_client/redesigned_client/update_resource.rb

Overview

Updates a resource (metadata) in SDR

Constant Summary collapse

RESOURCE_PATH =
'/v1/resources/%<id>s'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model:, version_description: nil, user_versions: nil) ⇒ UpdateResource

Returns a new instance of UpdateResource.

Parameters:

  • model (Cocina::Models::DRO)
  • version_description (String) (defaults to: nil)
  • user_versions (String) (defaults to: nil)

    action (none, new, update) to take for user version when closing version



16
17
18
19
20
# File 'lib/sdr_client/redesigned_client/update_resource.rb', line 16

def initialize(model:, version_description: nil, user_versions: nil)
  @model = model
  @version_description = version_description
  @user_versions = user_versions
end

Class Method Details

.runObject



9
10
11
# File 'lib/sdr_client/redesigned_client/update_resource.rb', line 9

def self.run(...)
  new(...).run
end

Instance Method Details

#runString

Returns job id for the background job result.

Returns:

  • (String)

    job id for the background job result



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sdr_client/redesigned_client/update_resource.rb', line 23

def run # rubocop:disable Metrics/MethodLength
  json = model.to_json
  logger.debug("Starting update with model: #{json}")

  response_hash = client.put(
    path: path,
    body: json,
    headers: { 'X-Cocina-Models-Version' => Cocina::Models::VERSION },
    params: request_params,
    expected_status: 202
  )

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

  response_hash.fetch('jobId')
end