Class: AtlasRb::Collection
- Defined in:
- lib/atlas_rb/collection.rb
Overview
Constant Summary collapse
- ROUTE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Atlas REST endpoint prefix for this resource.
"/collections/"
Class Method Summary collapse
-
.children(id, nuid: nil, on_behalf_of: nil) ⇒ Array<String>
List the Works in a Collection.
-
.create(id, xml_path = nil, nuid: nil, on_behalf_of: nil) ⇒ Hash
Create a new Collection under an existing Community.
-
.find(id, nuid: nil, on_behalf_of: nil) ⇒ Hash
Fetch a single Collection by ID.
-
.metadata(id, values, nuid: nil, on_behalf_of: nil) ⇒ Hash
Patch individual descriptive-metadata fields without uploading a full MODS document.
-
.mods(id, kind = nil, nuid: nil, on_behalf_of: nil) ⇒ String
Fetch the Collection's MODS representation in the requested format.
-
.reparent(id, new_parent_id, nuid: nil, on_behalf_of: nil) ⇒ Hash
Move a Collection to a different parent Community.
-
.set_thumbnails(id, thumbnail: nil, thumbnail_2x: nil, preview: nil, nuid: nil, on_behalf_of: nil) ⇒ AtlasRb::Mash
Attach the three thumbnail/preview Delegate URIs to a Collection.
-
.tombstone(id, nuid: nil, on_behalf_of: nil) ⇒ Faraday::Response
Tombstone (withdraw) a Collection.
-
.update(id, xml_path, nuid: nil, on_behalf_of: nil) ⇒ Hash
Replace a Collection's metadata by uploading a MODS XML document.
Methods inherited from Resource
Methods included from FaradayHelper
#connection, #multipart, #system_connection
Class Method Details
.children(id, nuid: nil, on_behalf_of: nil) ⇒ Array<String>
List the Works in a Collection.
The endpoint returns just the noids; resolve each through Resource.find (or Work.find) when a full payload is needed.
140 141 142 143 144 |
# File 'lib/atlas_rb/collection.rb', line 140 def self.children(id, nuid: nil, on_behalf_of: nil) JSON.parse( connection({}, nuid, on_behalf_of: on_behalf_of).get(ROUTE + id + '/children')&.body ) end |
.create(id, xml_path = nil, nuid: nil, on_behalf_of: nil) ⇒ Hash
Create a new Collection under an existing Community.
Note: unlike AtlasRb::Community.create, the id parameter here is the
parent Community ID (not a parent Collection ID — Collections do
not nest).
58 59 60 61 62 63 64 65 66 |
# File 'lib/atlas_rb/collection.rb', line 58 def self.create(id, xml_path = nil, nuid: nil, on_behalf_of: nil) result = AtlasRb::Mash.new(JSON.parse( connection({ parent_id: id }, nuid, on_behalf_of: on_behalf_of).post(ROUTE)&.body ))["collection"] return result unless xml_path.present? update(result["id"], xml_path, nuid: nuid, on_behalf_of: on_behalf_of) find(result["id"], nuid: nuid, on_behalf_of: on_behalf_of) end |
.find(id, nuid: nil, on_behalf_of: nil) ⇒ Hash
Fetch a single Collection by ID.
31 32 33 34 35 |
# File 'lib/atlas_rb/collection.rb', line 31 def self.find(id, nuid: nil, on_behalf_of: nil) AtlasRb::Mash.new(JSON.parse( connection({}, nuid, on_behalf_of: on_behalf_of).get(ROUTE + id)&.body ))["collection"] end |
.metadata(id, values, nuid: nil, on_behalf_of: nil) ⇒ Hash
Patch individual descriptive-metadata fields without uploading a full MODS document.
Scoped to user-authored descriptive metadata only. Programmatic writes of machine-set Delegate URIs (thumbnails) have their own purpose-specific endpoint — see set_thumbnails.
188 189 190 191 192 |
# File 'lib/atlas_rb/collection.rb', line 188 def self.(id, values, nuid: nil, on_behalf_of: nil) AtlasRb::Mash.new(JSON.parse( connection({ metadata: values }, nuid, on_behalf_of: on_behalf_of).patch(ROUTE + id)&.body )) end |
.mods(id, kind = nil, nuid: nil, on_behalf_of: nil) ⇒ String
Fetch the Collection's MODS representation in the requested format.
243 244 245 246 247 248 |
# File 'lib/atlas_rb/collection.rb', line 243 def self.mods(id, kind = nil, nuid: nil, on_behalf_of: nil) # json default, html, xml connection({}, nuid, on_behalf_of: on_behalf_of).get( ROUTE + id + '/mods' + (kind.present? ? ".#{kind}" : '') )&.body end |
.reparent(id, new_parent_id, nuid: nil, on_behalf_of: nil) ⇒ Hash
Move a Collection to a different parent Community.
Wraps PATCH /collections/<id>/parent with a parent_id of the new
Community. Atlas re-parents the Collection and synchronously cascades
the ancestry index over its Works; the structural rules (type, cycle,
tombstone guards) are enforced server-side and surface as a 422.
Mirrors create's "single parent id" shape — same kwarg threading, the only difference is the verb and that the Collection already exists.
94 95 96 97 98 99 |
# File 'lib/atlas_rb/collection.rb', line 94 def self.reparent(id, new_parent_id, nuid: nil, on_behalf_of: nil) AtlasRb::Mash.new(JSON.parse( connection({ parent_id: new_parent_id }, nuid, on_behalf_of: on_behalf_of) .patch(ROUTE + id + '/parent')&.body ))["collection"] end |
.set_thumbnails(id, thumbnail: nil, thumbnail_2x: nil, preview: nil, nuid: nil, on_behalf_of: nil) ⇒ AtlasRb::Mash
Attach the three thumbnail/preview Delegate URIs to a Collection.
Collection-level mirror of Work.set_thumbnails. Atlas dispatches
each non-blank URI to its matching Delegate role
(thumbnail_image / thumbnail_image_2x / preview_image) via
DelegateUpdater. Missing keys are left untouched.
220 221 222 223 224 225 226 |
# File 'lib/atlas_rb/collection.rb', line 220 def self.set_thumbnails(id, thumbnail: nil, thumbnail_2x: nil, preview: nil, nuid: nil, on_behalf_of: nil) body = { thumbnail: thumbnail, thumbnail_2x: thumbnail_2x, preview: preview }.compact AtlasRb::Mash.new(JSON.parse( connection({}, nuid, on_behalf_of: on_behalf_of) .patch(ROUTE + id + '/thumbnails', JSON.dump(body))&.body )) end |
.tombstone(id, nuid: nil, on_behalf_of: nil) ⇒ Faraday::Response
Tombstone (withdraw) a Collection.
The Collection remains in Atlas storage but is marked as withdrawn:
search and show pages return a withdrawn stub for every user. Atlas
rejects the request with 422 has_live_children if the Collection
still has live (non-tombstoned) Works.
119 120 121 |
# File 'lib/atlas_rb/collection.rb', line 119 def self.tombstone(id, nuid: nil, on_behalf_of: nil) connection({}, nuid, on_behalf_of: on_behalf_of).post(ROUTE + id + '/tombstone') end |
.update(id, xml_path, nuid: nil, on_behalf_of: nil) ⇒ Hash
Replace a Collection's metadata by uploading a MODS XML document.
160 161 162 163 164 165 166 167 |
# File 'lib/atlas_rb/collection.rb', line 160 def self.update(id, xml_path, nuid: nil, on_behalf_of: nil) payload = { binary: Faraday::Multipart::FilePart.new(File.open(xml_path), "application/xml", File.basename(xml_path)) } AtlasRb::Mash.new(JSON.parse( multipart(nuid, on_behalf_of: on_behalf_of).patch(ROUTE + id, payload)&.body )) end |