Class: Dor::Services::Client::Objects

Inherits:
VersionedService show all
Defined in:
lib/dor/services/client/objects.rb

Overview

API calls that are about a repository objects

Constant Summary

Constants inherited from VersionedService

VersionedService::EXCEPTION_CLASS, VersionedService::JSON_API_MIME_TYPE

Instance Method Summary collapse

Methods inherited from VersionedService

#async_result, #initialize, #with_querystring

Constructor Details

This class inherits a constructor from Dor::Services::Client::VersionedService

Instance Method Details

#find(source_id:, validate: false) ⇒ Cocina::Models::DROWithMetadata, Cocina::Models::CollectionWithMetadata

Find an object by source ID

Parameters:

  • validate (boolean) (defaults to: false)

    validate the response object

Returns:

  • (Cocina::Models::DROWithMetadata, Cocina::Models::CollectionWithMetadata)

    the returned object

Raises:



34
35
36
37
38
39
40
41
42
# File 'lib/dor/services/client/objects.rb', line 34

def find(source_id:, validate: false)
  resp = connection.get do |req|
    req.url "#{objects_path}/find"
    req.params['sourceId'] = source_id
  end
  raise_exception_based_on_response!(resp) unless resp.success?

  build_cocina_from_response(resp, validate: validate)
end

#register(params:, assign_doi: false, validate: false) ⇒ Cocina::Models::DROWithMetadata, ...

Creates a new object in DOR

Parameters:

  • params (Cocina::Models::RequestDRO, Cocina::Models::RequestCollection, Cocina::Models::RequestAdminPolicy)
  • assign_doi (Boolean) (defaults to: false)
  • validate (boolean) (defaults to: false)

    validate the response object

Returns:

  • (Cocina::Models::DROWithMetadata, Cocina::Models::CollectionWithMetadata, Cocina::Models::AdminPolicyWithMetadata)

    the returned model



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dor/services/client/objects.rb', line 15

def register(params:, assign_doi: false, validate: false)
  resp = connection.post do |req|
    req.url with_querystring(url: objects_path, params: { assign_doi: assign_doi })
    req.headers['Content-Type'] = 'application/json'
    # asking the service to return JSON (else it'll be plain text)
    req.headers['Accept'] = 'application/json'
    req.body = params.to_json
  end

  raise_exception_based_on_response!(resp) unless resp.success?

  build_cocina_from_response(resp, validate: validate)
end