Class: AtlasRb::Community
- Defined in:
- lib/atlas_rb/community.rb
Overview
A top-level grouping in the Atlas hierarchy.
Communities are organizational containers — they hold Collections and, optionally, sub-Communities. Most institutional structure (departments, programs, projects) is modeled as a tree of Communities with Collections at the leaves.
See also: Collection, Work.
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.
"/communities/"
Class Method Summary collapse
-
.children(id) ⇒ Array<String>
List the immediate children (sub-Communities and Collections) of a Community.
-
.create(id = nil, xml_path = nil) ⇒ Hash
Create a new Community, optionally seeded with MODS metadata.
-
.destroy(id) ⇒ Faraday::Response
Delete a Community.
-
.find(id) ⇒ Hash
Fetch a single Community by ID.
-
.metadata(id, values) ⇒ Hash
Patch individual metadata fields without uploading a full MODS document.
-
.mods(id, kind = nil) ⇒ String
Fetch the Community's MODS representation in the requested format.
-
.restore(id, nuid:) ⇒ Faraday::Response
Restore a previously tombstoned Community.
-
.tombstone(id, nuid:) ⇒ Faraday::Response
Tombstone (withdraw) a Community.
-
.update(id, xml_path) ⇒ Hash
Replace a Community'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 immediate children (sub-Communities and Collections) of a Community.
The endpoint returns just the noids; resolve each through Resource.find (which dispatches by type) when richer payloads are needed.
114 115 116 |
# File 'lib/atlas_rb/community.rb', line 114 def self.children(id) JSON.parse(connection({}).get(ROUTE + id + '/children')&.body) end |
.create(id = nil, xml_path = nil) ⇒ Hash
Create a new Community, optionally seeded with MODS metadata.
Pass id = nil to create a top-level Community; pass a Community ID to
nest the new Community beneath an existing one.
48 49 50 51 52 53 54 |
# File 'lib/atlas_rb/community.rb', line 48 def self.create(id = nil, xml_path = nil) result = AtlasRb::Mash.new(JSON.parse(connection({ parent_id: id }).post(ROUTE)&.body))["community"] return result unless xml_path.present? update(result["id"], xml_path) find(result["id"]) end |
.destroy(id) ⇒ Faraday::Response
Delete a Community.
63 64 65 |
# File 'lib/atlas_rb/community.rb', line 63 def self.destroy(id) connection({}).delete(ROUTE + id) end |
.find(id) ⇒ Hash
Fetch a single Community by ID.
26 27 28 |
# File 'lib/atlas_rb/community.rb', line 26 def self.find(id) AtlasRb::Mash.new(JSON.parse(connection({}).get(ROUTE + id)&.body))["community"] end |
.metadata(id, values) ⇒ Hash
Patch individual metadata fields without uploading a full MODS document.
142 143 144 |
# File 'lib/atlas_rb/community.rb', line 142 def self.(id, values) AtlasRb::Mash.new(JSON.parse(connection({ metadata: values }).patch(ROUTE + id)&.body)) end |
.mods(id, kind = nil) ⇒ String
Fetch the Community's MODS representation in the requested format.
157 158 159 160 161 162 |
# File 'lib/atlas_rb/community.rb', line 157 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 Community.
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.
98 99 100 |
# File 'lib/atlas_rb/community.rb', line 98 def self.restore(id, nuid:) connection({}, nuid).post(ROUTE + id + '/restore') end |
.tombstone(id, nuid:) ⇒ Faraday::Response
Tombstone (withdraw) a Community.
The Community 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 Community
still has live (non-tombstoned) members.
82 83 84 |
# File 'lib/atlas_rb/community.rb', line 82 def self.tombstone(id, nuid:) connection({}, nuid).post(ROUTE + id + '/tombstone') end |
.update(id, xml_path) ⇒ Hash
Replace a Community's metadata by uploading a MODS XML document.
126 127 128 129 130 131 |
# File 'lib/atlas_rb/community.rb', line 126 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 |