Class: Dor::Services::Client::UserVersion
- Inherits:
-
VersionedService
- Object
- VersionedService
- Dor::Services::Client::UserVersion
- Defined in:
- lib/dor/services/client/user_version.rb
Overview
API calls that are about user versions
Defined Under Namespace
Classes: Version
Constant Summary
Constants inherited from VersionedService
VersionedService::EXCEPTION_CLASS, VersionedService::JSON_API_MIME_TYPE
Instance Method Summary collapse
-
#create(object_version:) ⇒ Version
Create a user version for an object.
-
#find(version) ⇒ Cocina::Models::DROWithMetadata
The object metadata.
-
#initialize(connection:, version:, object_identifier:) ⇒ UserVersion
constructor
A new instance of UserVersion.
-
#inventory ⇒ Array
A list of the user versions.
-
#solr(version) ⇒ Hash
The solr document for the user version.
-
#update(user_version:) ⇒ Version
Updates a user version.
Methods inherited from VersionedService
#async_result, #with_querystring
Constructor Details
#initialize(connection:, version:, object_identifier:) ⇒ UserVersion
Returns a new instance of UserVersion.
11 12 13 14 |
# File 'lib/dor/services/client/user_version.rb', line 11 def initialize(connection:, version:, object_identifier:) super(connection: connection, version: version) @object_identifier = object_identifier end |
Instance Method Details
#create(object_version:) ⇒ Version
Create a user version for an object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/dor/services/client/user_version.rb', line 55 def create(object_version:) resp = connection.post do |req| req.url "#{api_version}/objects/#{object_identifier}/user_versions" req.headers['Content-Type'] = 'application/json' req.body = { version: object_version }.to_json end raise_exception_based_on_response!(resp, object_identifier) unless resp.success? Version.new(**JSON.parse(resp.body).symbolize_keys!) end |
#find(version) ⇒ Cocina::Models::DROWithMetadata
Returns the object metadata.
29 30 31 32 33 34 35 36 |
# File 'lib/dor/services/client/user_version.rb', line 29 def find(version) resp = connection.get do |req| req.url "#{base_path}/#{version}" end raise_exception_based_on_response!(resp) unless resp.success? build_cocina_from_response(resp, validate: false) end |
#inventory ⇒ Array
Returns a list of the user versions.
18 19 20 21 22 23 24 25 |
# File 'lib/dor/services/client/user_version.rb', line 18 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('user_versions').map { |params| Version.new(**params.symbolize_keys!) } end |
#solr(version) ⇒ Hash
Returns the solr document for the user version.
40 41 42 43 44 45 46 47 |
# File 'lib/dor/services/client/user_version.rb', line 40 def solr(version) resp = connection.get do |req| req.url "#{base_path}/#{version}/solr" end raise_exception_based_on_response!(resp) unless resp.success? JSON.parse(resp.body) end |
#update(user_version:) ⇒ Version
Updates a user version
rubocop:disable Metrics/AbcSize
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/dor/services/client/user_version.rb', line 73 def update(user_version:) resp = connection.patch do |req| req.url "#{api_version}/objects/#{object_identifier}/user_versions/#{user_version.userVersion}" req.headers['Content-Type'] = 'application/json' req.body = user_version.to_h.except(:userVersion).compact.to_json end raise_exception_based_on_response!(resp, object_identifier) unless resp.success? Version.new(**JSON.parse(resp.body).symbolize_keys!) end |