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) ⇒ Hash
-
.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.
-
.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 = 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) ⇒ Hash
103 104 105 |
# File 'lib/atlas_rb/work.rb', line 103 def self.files(id) JSON.parse(connection({}).get(ROUTE + id + '/files')&.body) 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) JSON.parse(connection({}).get(ROUTE + id)&.body)["work"] end |
.metadata(id, values) ⇒ Hash
Patch individual metadata fields without uploading a full MODS document.
89 90 91 |
# File 'lib/atlas_rb/work.rb', line 89 def self.(id, values) 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.
116 117 118 119 120 121 |
# File 'lib/atlas_rb/work.rb', line 116 def self.mods(id, kind = nil) # json default, html, xml connection({}).get( ROUTE + id + '/mods' + (kind.present? ? ".#{kind}" : '') )&.body end |
.update(id, xml_path) ⇒ Hash
Replace a Work's metadata by uploading a MODS XML document.
74 75 76 77 78 79 |
# File 'lib/atlas_rb/work.rb', line 74 def self.update(id, xml_path) payload = { binary: Faraday::Multipart::FilePart.new(File.open(xml_path), "application/xml", File.basename(xml_path)) } JSON.parse(multipart({}).patch(ROUTE + id, payload)&.body) end |