Class: SdrClient::RedesignedClient::CreateResource

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

Overview

Creates a resource (metadata) in SDR

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(accession:, metadata:, assign_doi: false, priority: nil, user_versions: nil) ⇒ CreateResource

Returns a new instance of CreateResource.

Parameters:

  • accession (Boolean)

    should the accessionWF be started

  • assign_doi (Boolean) (defaults to: false)

    should a DOI be assigned to this item

  • metadata (Cocina::Models::RequestDRO, Cocina::Models::RequestCollection)
  • the (Hash<Symbol,String>)

    result of the metadata call

  • priority (String) (defaults to: nil)

    what processing priority should be used either ‘low’ or ‘default’

  • user_versions (String) (defaults to: nil)

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



18
19
20
21
22
23
24
# File 'lib/sdr_client/redesigned_client/create_resource.rb', line 18

def initialize(accession:, metadata:, assign_doi: false, priority: nil, user_versions: nil)
  @accession = accession
  @priority = priority
  @assign_doi = assign_doi
  @metadata = 
  @user_versions = user_versions
end

Class Method Details

.runObject



7
8
9
# File 'lib/sdr_client/redesigned_client/create_resource.rb', line 7

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

Instance Method Details

#runString

Returns job id for the background job result.

Parameters:

  • the (Hash<Symbol,String>)

    result of the metadata call

Returns:

  • (String)

    job id for the background job result



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/sdr_client/redesigned_client/create_resource.rb', line 28

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

  response_hash = client.post(
    path: path,
    body: json,
    headers: { 'X-Cocina-Models-Version' => Cocina::Models::VERSION },
    expected_status: 201
  )

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

  response_hash.fetch(:jobId)
end