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, nuid: nil, on_behalf_of: nil) ⇒ Array<String>
List the immediate children (sub-Communities and Collections) of a Community.
-
.create(id = nil, xml_path = nil, nuid: nil, on_behalf_of: nil) ⇒ Hash
Create a new Community, optionally seeded with MODS metadata.
-
.find(id, nuid: nil, on_behalf_of: nil) ⇒ Hash
Fetch a single Community by ID.
-
.metadata(id, values, nuid: nil, on_behalf_of: nil) ⇒ Hash
Patch individual descriptive-metadata fields without uploading a full MODS document.
-
.mods(id, kind = nil, nuid: nil, on_behalf_of: nil) ⇒ String
Fetch the Community's MODS representation in the requested format.
-
.set_thumbnails(id, thumbnail: nil, thumbnail_2x: nil, preview: nil, nuid: nil, on_behalf_of: nil) ⇒ AtlasRb::Mash
Attach the three thumbnail/preview Delegate URIs to a Community.
-
.tombstone(id, nuid: nil, on_behalf_of: nil) ⇒ Faraday::Response
Tombstone (withdraw) a Community.
-
.update(id, xml_path, nuid: nil, on_behalf_of: nil) ⇒ Hash
Replace a Community's metadata by uploading a MODS XML document.
Methods inherited from Resource
Methods included from FaradayHelper
#connection, #multipart, #system_connection
Class Method Details
.children(id, nuid: nil, on_behalf_of: nil) ⇒ 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.
112 113 114 115 116 |
# File 'lib/atlas_rb/community.rb', line 112 def self.children(id, nuid: nil, on_behalf_of: nil) JSON.parse( connection({}, nuid, on_behalf_of: on_behalf_of).get(ROUTE + id + '/children')&.body ) end |
.create(id = nil, xml_path = nil, nuid: nil, on_behalf_of: 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.
62 63 64 65 66 67 68 69 70 |
# File 'lib/atlas_rb/community.rb', line 62 def self.create(id = nil, xml_path = nil, nuid: nil, on_behalf_of: nil) result = AtlasRb::Mash.new(JSON.parse( connection({ parent_id: id }, nuid, on_behalf_of: on_behalf_of).post(ROUTE)&.body ))["community"] return result unless xml_path.present? update(result["id"], xml_path, nuid: nuid, on_behalf_of: on_behalf_of) find(result["id"], nuid: nuid, on_behalf_of: on_behalf_of) end |
.find(id, nuid: nil, on_behalf_of: nil) ⇒ Hash
Fetch a single Community by ID.
32 33 34 35 36 |
# File 'lib/atlas_rb/community.rb', line 32 def self.find(id, nuid: nil, on_behalf_of: nil) AtlasRb::Mash.new(JSON.parse( connection({}, nuid, on_behalf_of: on_behalf_of).get(ROUTE + id)&.body ))["community"] end |
.metadata(id, values, nuid: nil, on_behalf_of: nil) ⇒ Hash
Patch individual descriptive-metadata fields without uploading a full MODS document.
Scoped to user-authored descriptive metadata only. Programmatic writes of machine-set Delegate URIs (thumbnails) have their own purpose-specific endpoint — see set_thumbnails.
161 162 163 164 165 |
# File 'lib/atlas_rb/community.rb', line 161 def self.(id, values, nuid: nil, on_behalf_of: nil) AtlasRb::Mash.new(JSON.parse( connection({ metadata: values }, nuid, on_behalf_of: on_behalf_of).patch(ROUTE + id)&.body )) end |
.mods(id, kind = nil, nuid: nil, on_behalf_of: nil) ⇒ String
Fetch the Community's MODS representation in the requested format.
215 216 217 218 219 220 |
# File 'lib/atlas_rb/community.rb', line 215 def self.mods(id, kind = nil, nuid: nil, on_behalf_of: nil) # json default, html, xml connection({}, nuid, on_behalf_of: on_behalf_of).get( ROUTE + id + '/mods' + (kind.present? ? ".#{kind}" : '') )&.body end |
.set_thumbnails(id, thumbnail: nil, thumbnail_2x: nil, preview: nil, nuid: nil, on_behalf_of: nil) ⇒ AtlasRb::Mash
Attach the three thumbnail/preview Delegate URIs to a Community.
Community-level mirror of Work.set_thumbnails. Atlas dispatches
each non-blank URI to its matching Delegate role
(thumbnail_image / thumbnail_image_2x / preview_image) via
DelegateUpdater. Missing keys are left untouched.
190 191 192 193 194 195 196 |
# File 'lib/atlas_rb/community.rb', line 190 def self.set_thumbnails(id, thumbnail: nil, thumbnail_2x: nil, preview: nil, nuid: nil, on_behalf_of: nil) body = { thumbnail: thumbnail, thumbnail_2x: thumbnail_2x, preview: preview }.compact AtlasRb::Mash.new(JSON.parse( connection({}, nuid, on_behalf_of: on_behalf_of) .patch(ROUTE + id + '/thumbnails', JSON.dump(body))&.body )) end |
.tombstone(id, nuid: nil, on_behalf_of: nil) ⇒ 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.
90 91 92 |
# File 'lib/atlas_rb/community.rb', line 90 def self.tombstone(id, nuid: nil, on_behalf_of: nil) connection({}, nuid, on_behalf_of: on_behalf_of).post(ROUTE + id + '/tombstone') end |
.update(id, xml_path, nuid: nil, on_behalf_of: nil) ⇒ Hash
Replace a Community's metadata by uploading a MODS XML document.
132 133 134 135 136 137 138 139 |
# File 'lib/atlas_rb/community.rb', line 132 def self.update(id, xml_path, nuid: nil, on_behalf_of: nil) payload = { binary: Faraday::Multipart::FilePart.new(File.open(xml_path), "application/xml", File.basename(xml_path)) } AtlasRb::Mash.new(JSON.parse( multipart(nuid, on_behalf_of: on_behalf_of).patch(ROUTE + id, payload)&.body )) end |