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) ⇒ Hash
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.
-
.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) ⇒ Hash
List the Works in a Collection.
70 71 72 |
# File 'lib/atlas_rb/collection.rb', line 70 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 = 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) JSON.parse(connection({}).get(ROUTE + id)&.body)["collection"] end |
.metadata(id, values) ⇒ Hash
Patch individual metadata fields without uploading a full MODS document.
97 98 99 |
# File 'lib/atlas_rb/collection.rb', line 97 def self.(id, values) 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.
110 111 112 113 114 115 |
# File 'lib/atlas_rb/collection.rb', line 110 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 Collection's metadata by uploading a MODS XML document.
82 83 84 85 86 87 |
# File 'lib/atlas_rb/collection.rb', line 82 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 |