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) ⇒ Array<String>
List the Works in a Collection.
-
.create(id, xml_path = nil, nuid: nil) ⇒ Hash
Create a new Collection under an existing Community.
-
.destroy(id) ⇒ Faraday::Response
Delete a Collection.
-
.find(id, nuid: nil) ⇒ Hash
Fetch a single Collection by ID.
-
.metadata(id, values, nuid: nil) ⇒ Hash
Patch individual descriptive-metadata fields without uploading a full MODS document.
-
.mods(id, kind = nil, nuid: nil) ⇒ String
Fetch the Collection's MODS representation in the requested format.
-
.restore(id, nuid:) ⇒ Faraday::Response
Restore a previously tombstoned Collection.
-
.set_thumbnails(id, thumbnail: nil, thumbnail_2x: nil, preview: nil, nuid: nil) ⇒ AtlasRb::Mash
Attach the three thumbnail/preview Delegate URIs to a Collection.
-
.tombstone(id, nuid:) ⇒ Faraday::Response
Tombstone (withdraw) a Collection.
-
.update(id, xml_path, nuid: nil) ⇒ Hash
Replace a Collection's metadata by uploading a MODS XML document.
Methods inherited from Resource
Methods included from FaradayHelper
Class Method Details
.children(id) ⇒ 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.
115 116 117 |
# File 'lib/atlas_rb/collection.rb', line 115 def self.children(id) JSON.parse(connection({}).get(ROUTE + id + '/children')&.body) end |
.create(id, xml_path = nil, nuid: 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).
50 51 52 53 54 55 56 |
# File 'lib/atlas_rb/collection.rb', line 50 def self.create(id, xml_path = nil, nuid: nil) result = AtlasRb::Mash.new(JSON.parse(connection({ parent_id: id }, nuid).post(ROUTE)&.body))["collection"] return result unless xml_path.present? update(result["id"], xml_path) find(result["id"]) end |
.destroy(id) ⇒ Faraday::Response
Delete a Collection.
65 66 67 |
# File 'lib/atlas_rb/collection.rb', line 65 def self.destroy(id) connection({}).delete(ROUTE + id) end |
.find(id, nuid: nil) ⇒ Hash
Fetch a single Collection by ID.
28 29 30 |
# File 'lib/atlas_rb/collection.rb', line 28 def self.find(id, nuid: nil) AtlasRb::Mash.new(JSON.parse(connection({}, nuid).get(ROUTE + id)&.body))["collection"] end |
.metadata(id, values, nuid: 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.
153 154 155 |
# File 'lib/atlas_rb/collection.rb', line 153 def self.(id, values, nuid: nil) AtlasRb::Mash.new(JSON.parse(connection({ metadata: values }, nuid).patch(ROUTE + id)&.body)) end |
.mods(id, kind = nil, nuid: nil) ⇒ String
Fetch the Collection's MODS representation in the requested format.
199 200 201 202 203 204 |
# File 'lib/atlas_rb/collection.rb', line 199 def self.mods(id, kind = nil, nuid: nil) # json default, html, xml connection({}, nuid).get( ROUTE + id + '/mods' + (kind.present? ? ".#{kind}" : '') )&.body end |
.restore(id, nuid:) ⇒ Faraday::Response
Restore a previously tombstoned Collection.
Operator-only. Restoration is intentionally not exposed in any end-user UI; call this from a Rails console session (or a future admin panel) when the library has decided an object should come back.
100 101 102 |
# File 'lib/atlas_rb/collection.rb', line 100 def self.restore(id, nuid:) connection({}, nuid).post(ROUTE + id + '/restore') end |
.set_thumbnails(id, thumbnail: nil, thumbnail_2x: nil, preview: nil, nuid: 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.
180 181 182 183 184 185 |
# File 'lib/atlas_rb/collection.rb', line 180 def self.set_thumbnails(id, thumbnail: nil, thumbnail_2x: nil, preview: nil, nuid: nil) body = { thumbnail: thumbnail, thumbnail_2x: thumbnail_2x, preview: preview }.compact AtlasRb::Mash.new(JSON.parse( connection({}, nuid).patch(ROUTE + id + '/thumbnails', JSON.dump(body))&.body )) end |
.tombstone(id, nuid:) ⇒ 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.
84 85 86 |
# File 'lib/atlas_rb/collection.rb', line 84 def self.tombstone(id, nuid:) connection({}, nuid).post(ROUTE + id + '/tombstone') end |
.update(id, xml_path, nuid: nil) ⇒ Hash
Replace a Collection's metadata by uploading a MODS XML document.
130 131 132 133 134 135 |
# File 'lib/atlas_rb/collection.rb', line 130 def self.update(id, xml_path, nuid: nil) payload = { binary: Faraday::Multipart::FilePart.new(File.open(xml_path), "application/xml", File.basename(xml_path)) } AtlasRb::Mash.new(JSON.parse(multipart(nuid).patch(ROUTE + id, payload)&.body)) end |