Class: Dor::Services::Client::ObjectVersion
- Inherits:
-
VersionedService
- Object
- VersionedService
- Dor::Services::Client::ObjectVersion
- Defined in:
- lib/dor/services/client/object_version.rb
Overview
API calls that are about versions
Defined Under Namespace
Classes: Version, VersionStatus
Constant Summary
Constants inherited from VersionedService
VersionedService::EXCEPTION_CLASS, VersionedService::JSON_API_MIME_TYPE
Instance Method Summary collapse
-
#close(**params) ⇒ String
Close current version for an object.
-
#current ⇒ String
Get the current version for a DOR object.
-
#initialize(connection:, version:, object_identifier:) ⇒ ObjectVersion
constructor
A new instance of ObjectVersion.
-
#inventory ⇒ Array
A list of the versions.
-
#open(**params) ⇒ Cocina::Models::DROWithMetadata|CollectionWithMetadata|AdminPolicyWithMetadata
Open new version for an object.
-
#openable? ⇒ Boolean
Determines if a new version can be opened for a DOR object.
-
#status ⇒ VersionStatus
Status of the version.
Methods inherited from VersionedService
#async_result, #with_querystring
Constructor Details
#initialize(connection:, version:, object_identifier:) ⇒ ObjectVersion
Returns a new instance of ObjectVersion.
38 39 40 41 |
# File 'lib/dor/services/client/object_version.rb', line 38 def initialize(connection:, version:, object_identifier:) super(connection: connection, version: version) @object_identifier = object_identifier end |
Instance Method Details
#close(**params) ⇒ String
Close current version for an object
104 105 106 107 108 109 110 111 112 |
# File 'lib/dor/services/client/object_version.rb', line 104 def close(**params) resp = connection.post do |req| req.url with_querystring(url: close_version_path, params: params) req.headers['Content-Type'] = 'application/json' end return resp.body if resp.success? raise_exception_based_on_response!(resp) end |
#current ⇒ String
Get the current version for a DOR object. This comes from ObjectVersion table in the DSA
47 48 49 50 51 52 53 54 |
# File 'lib/dor/services/client/object_version.rb', line 47 def current resp = connection.get do |req| req.url "#{base_path}/current" end return resp.body if resp.success? raise_exception_based_on_response!(resp) end |
#inventory ⇒ Array
Returns a list of the versions.
116 117 118 119 120 121 122 123 |
# File 'lib/dor/services/client/object_version.rb', line 116 def inventory resp = connection.get do |req| req.url base_path end raise_exception_based_on_response!(resp, object_identifier) unless resp.success? JSON.parse(resp.body).fetch('versions').map { |params| Version.new(**params.symbolize_keys!) } end |
#open(**params) ⇒ Cocina::Models::DROWithMetadata|CollectionWithMetadata|AdminPolicyWithMetadata
Open new version for an object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/dor/services/client/object_version.rb', line 86 def open(**params) resp = connection.post do |req| req.url with_querystring(url: open_new_version_path, params: params) req.headers['Content-Type'] = 'application/json' end raise_exception_based_on_response!(resp) unless resp.success? build_cocina_from_response(resp) end |
#openable? ⇒ Boolean
Determines if a new version can be opened for a DOR object. rubocop:disable Metrics/MethodLength
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/dor/services/client/object_version.rb', line 61 def openable? resp = connection.get do |req| req.url "#{base_path}/openable" end raise_exception_based_on_response!(resp) unless resp.success? case resp.body when 'true' true when 'false' false else raise MalformedResponse, "Expected true or false, not #{resp.body}" end end |
#status ⇒ VersionStatus
Returns status of the version.
127 128 129 130 131 132 133 134 |
# File 'lib/dor/services/client/object_version.rb', line 127 def status resp = connection.get do |req| req.url "#{base_path}/status" end raise_exception_based_on_response!(resp, object_identifier) unless resp.success? VersionStatus.new(JSON.parse(resp.body).symbolize_keys!) end |