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.
23 24 25 26 |
# File 'lib/dor/services/client/user_version.rb', line 23 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
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/dor/services/client/user_version.rb', line 67 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.
41 42 43 44 45 46 47 48 |
# File 'lib/dor/services/client/user_version.rb', line 41 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.
30 31 32 33 34 35 36 37 |
# File 'lib/dor/services/client/user_version.rb', line 30 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.
52 53 54 55 56 57 58 59 |
# File 'lib/dor/services/client/user_version.rb', line 52 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
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/dor/services/client/user_version.rb', line 85 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 |