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) ⇒ Hash
Create a new Collection under an existing Community.
-
.destroy(id) ⇒ Faraday::Response
Delete a Collection.
-
.find(id) ⇒ Hash
Fetch a single Collection by ID.
-
.metadata(id, values) ⇒ Hash
Patch individual metadata fields without uploading a full MODS document.
-
.mods(id, kind = nil) ⇒ String
Fetch the Collection's MODS representation in the requested format.
-
.restore(id, nuid:) ⇒ Faraday::Response
Restore a previously tombstoned Collection.
-
.tombstone(id, nuid:) ⇒ Faraday::Response
Tombstone (withdraw) a Collection.
-
.update(id, xml_path) ⇒ 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.
109 110 111 |
# File 'lib/atlas_rb/collection.rb', line 109 def self.children(id) JSON.parse(connection({}).get(ROUTE + id + '/children')&.body) end |
.create(id, xml_path = 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).
44 45 46 47 48 49 50 |
# File 'lib/atlas_rb/collection.rb', line 44 def self.create(id, xml_path = nil) result = AtlasRb::Mash.new(JSON.parse(connection({ parent_id: id }).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.
59 60 61 |
# File 'lib/atlas_rb/collection.rb', line 59 def self.destroy(id) connection({}).delete(ROUTE + id) end |
.find(id) ⇒ Hash
Fetch a single Collection by ID.
25 26 27 |
# File 'lib/atlas_rb/collection.rb', line 25 def self.find(id) AtlasRb::Mash.new(JSON.parse(connection({}).get(ROUTE + id)&.body))["collection"] end |
.metadata(id, values) ⇒ Hash
Patch individual metadata fields without uploading a full MODS document.
136 137 138 |
# File 'lib/atlas_rb/collection.rb', line 136 def self.(id, values) AtlasRb::Mash.new(JSON.parse(connection({ metadata: values }).patch(ROUTE + id)&.body)) end |
.mods(id, kind = nil) ⇒ String
Fetch the Collection's MODS representation in the requested format.
149 150 151 152 153 154 |
# File 'lib/atlas_rb/collection.rb', line 149 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 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.
94 95 96 |
# File 'lib/atlas_rb/collection.rb', line 94 def self.restore(id, nuid:) connection({}, nuid).post(ROUTE + id + '/restore') 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.
78 79 80 |
# File 'lib/atlas_rb/collection.rb', line 78 def self.tombstone(id, nuid:) connection({}, nuid).post(ROUTE + id + '/tombstone') end |
.update(id, xml_path) ⇒ Hash
Replace a Collection's metadata by uploading a MODS XML document.
121 122 123 124 125 126 |
# File 'lib/atlas_rb/collection.rb', line 121 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 |