Class: AtlasRb::Work
Overview
The bibliographic unit in Atlas — an article, thesis, dataset, image, etc.
A Work belongs to exactly one Collection and aggregates one or more FileSets, each of which holds binary content via a Blob. MODS metadata is attached at the Work level.
See also: Collection, FileSet, Blob.
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.
"/works/"
Class Method Summary collapse
-
.create(id, xml_path = nil) ⇒ Hash
Create a new Work in an existing Collection.
-
.destroy(id) ⇒ Faraday::Response
Delete a Work.
- .files(id) ⇒ Array<AtlasRb::Mash>
-
.find(id) ⇒ Hash
Fetch a single Work by ID.
-
.metadata(id, values) ⇒ Hash
Patch individual metadata fields without uploading a full MODS document.
-
.mods(id, kind = nil) ⇒ String
Fetch the Work's MODS representation in the requested format.
-
.restore(id, nuid:) ⇒ Faraday::Response
Restore a previously tombstoned Work.
-
.tombstone(id, nuid:) ⇒ Faraday::Response
Tombstone (withdraw) a Work.
-
.update(id, xml_path) ⇒ Hash
Replace a Work's metadata by uploading a MODS XML document.
Methods inherited from Resource
Methods included from FaradayHelper
Class Method Details
.create(id, xml_path = nil) ⇒ Hash
Create a new Work in an existing Collection.
Note: unlike Community.create and Collection.create, the id
parameter here is the parent Collection ID. The underlying request
uses the collection_id query param rather than parent_id.
47 48 49 50 51 52 53 |
# File 'lib/atlas_rb/work.rb', line 47 def self.create(id, xml_path = nil) result = AtlasRb::Mash.new(JSON.parse(connection({ collection_id: id }).post(ROUTE)&.body))["work"] return result unless xml_path.present? update(result["id"], xml_path) find(result["id"]) end |
.destroy(id) ⇒ Faraday::Response
Delete a Work.
62 63 64 |
# File 'lib/atlas_rb/work.rb', line 62 def self.destroy(id) connection({}).delete(ROUTE + id) end |
.files(id) ⇒ Array<AtlasRb::Mash>
139 140 141 |
# File 'lib/atlas_rb/work.rb', line 139 def self.files(id) JSON.parse(connection({}).get(ROUTE + id + '/files')&.body).map { |entry| AtlasRb::Mash.new(entry) } end |
.find(id) ⇒ Hash
Fetch a single Work by ID.
25 26 27 |
# File 'lib/atlas_rb/work.rb', line 25 def self.find(id) AtlasRb::Mash.new(JSON.parse(connection({}).get(ROUTE + id)&.body))["work"] end |
.metadata(id, values) ⇒ Hash
Patch individual metadata fields without uploading a full MODS document.
124 125 126 |
# File 'lib/atlas_rb/work.rb', line 124 def self.(id, values) AtlasRb::Mash.new(JSON.parse(connection({ metadata: values }).patch(ROUTE + id)&.body)) end |
.mods(id, kind = nil) ⇒ String
Fetch the Work's MODS representation in the requested format.
152 153 154 155 156 157 |
# File 'lib/atlas_rb/work.rb', line 152 def self.mods(id, kind = nil) # json default, html, xml connection({}).get( ROUTE + id + '/mods' + (kind.present? ? ".#{kind}" : '') )&.body end |
.restore(id, nuid:) ⇒ Faraday::Response
Restore a previously tombstoned Work.
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.
97 98 99 |
# File 'lib/atlas_rb/work.rb', line 97 def self.restore(id, nuid:) connection({}, nuid).post(ROUTE + id + '/restore') end |
.tombstone(id, nuid:) ⇒ Faraday::Response
Tombstone (withdraw) a Work.
The Work remains in Atlas storage along with its FileSets and Blobs, but is marked as withdrawn: search and show pages return a withdrawn stub for every user. Unlike Communities and Collections, Works are always tombstoneable regardless of how many files they hold — the FileSets and Blobs ride along.
81 82 83 |
# File 'lib/atlas_rb/work.rb', line 81 def self.tombstone(id, nuid:) connection({}, nuid).post(ROUTE + id + '/tombstone') end |
.update(id, xml_path) ⇒ Hash
Replace a Work's metadata by uploading a MODS XML document.
109 110 111 112 113 114 |
# File 'lib/atlas_rb/work.rb', line 109 def self.update(id, xml_path) payload = { binary: Faraday::Multipart::FilePart.new(File.open(xml_path), "application/xml", File.basename(xml_path)) } AtlasRb::Mash.new(JSON.parse(multipart({}).patch(ROUTE + id, payload)&.body)) end |