Class: SdrClient::Deposit::CreateResource

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

Overview

Creates a resource (metadata) in SDR

Constant Summary collapse

DRO_PATH =
'/v1/resources'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(accession:, metadata:, logger:, connection:) ⇒ CreateResource

Returns a new instance of CreateResource.

Parameters:

  • accession (Boolean)

    should the accessionWF be started

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

    result of the metadata call



16
17
18
19
20
21
# File 'lib/sdr_client/deposit/create_resource.rb', line 16

def initialize(accession:, metadata:, logger:, connection:)
  @accession = accession
  @metadata = 
  @logger = logger
  @connection = connection
end

Class Method Details

.run(accession:, metadata:, logger:, connection:) ⇒ Object



9
10
11
# File 'lib/sdr_client/deposit/create_resource.rb', line 9

def self.run(accession:, metadata:, logger:, connection:)
  new(accession: accession, metadata: , logger: logger, connection: connection).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



25
26
27
28
29
30
31
32
# File 'lib/sdr_client/deposit/create_resource.rb', line 25

def run
  response = 
  UnexpectedResponse.call(response) unless response.status == 201

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

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