Class: Dor::Services::Client::Mutate
- Inherits:
-
VersionedService
- Object
- VersionedService
- Dor::Services::Client::Mutate
- Defined in:
- lib/dor/services/client/mutate.rb
Overview
API calls that update the data.
Constant Summary
Constants inherited from VersionedService
VersionedService::EXCEPTION_CLASS, VersionedService::JSON_API_MIME_TYPE
Instance Method Summary collapse
-
#apply_admin_policy_defaults ⇒ boolean
Copies the values from the admin policy to the item.
-
#destroy(user_name: nil) ⇒ Boolean
Destroys an object.
-
#initialize(connection:, version:, object_identifier:) ⇒ Mutate
constructor
A new instance of Mutate.
-
#refresh_descriptive_metadata_from_ils ⇒ boolean
Pull in metadata from Symphony and updates descriptive metadata.
-
#update(params:, skip_lock: false, validate: false) ⇒ Cocina::Models::DROWithMetadata, ...
Updates the object rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength.
Methods inherited from VersionedService
#async_result, #with_querystring
Constructor Details
#initialize(connection:, version:, object_identifier:) ⇒ Mutate
Returns a new instance of Mutate.
9 10 11 12 |
# File 'lib/dor/services/client/mutate.rb', line 9 def initialize(connection:, version:, object_identifier:) super(connection: connection, version: version) @object_identifier = object_identifier end |
Instance Method Details
#apply_admin_policy_defaults ⇒ boolean
Copies the values from the admin policy to the item
18 19 20 21 22 23 24 25 26 |
# File 'lib/dor/services/client/mutate.rb', line 18 def apply_admin_policy_defaults resp = connection.post do |req| req.url "#{object_path}/apply_admin_policy_defaults" end raise_exception_based_on_response!(resp) unless resp.success? true end |
#destroy(user_name: nil) ⇒ Boolean
Destroys an object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/dor/services/client/mutate.rb', line 79 def destroy(user_name: nil) path = object_path path += "?user_name=#{user_name}" if user_name resp = connection.delete do |req| req.url path end raise_exception_based_on_response!(resp, object_identifier) unless resp.success? true end |
#refresh_descriptive_metadata_from_ils ⇒ boolean
Pull in metadata from Symphony and updates descriptive metadata
64 65 66 67 68 69 70 71 72 |
# File 'lib/dor/services/client/mutate.rb', line 64 def resp = connection.post do |req| req.url "#{object_path}/refresh_metadata" end raise_exception_based_on_response!(resp) unless resp.success? true end |
#update(params:, skip_lock: false, validate: false) ⇒ Cocina::Models::DROWithMetadata, ...
Updates the object rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/dor/services/client/mutate.rb', line 38 def update(params:, skip_lock: false, validate: false) raise ArgumentError, 'Cocina object not provided.' unless params.respond_to?(:externalIdentifier) # Raised if Cocina::Models::*WithMetadata not provided. raise ArgumentError, 'ETag not provided.' unless skip_lock || params.respond_to?(:lock) resp = connection.patch do |req| req.url object_path req.headers['Content-Type'] = 'application/json' # asking the service to return JSON (else it'll be plain text) req.headers['Accept'] = 'application/json' req.headers['If-Match'] = params.lock unless skip_lock req.body = build_json_from_cocina(params) end raise_exception_based_on_response!(resp) unless resp.success? build_cocina_from_response(resp, validate: validate) end |