Class: AtlasRb::Resource
- Inherits:
-
Object
- Object
- AtlasRb::Resource
- Extended by:
- FaradayHelper
- Defined in:
- lib/atlas_rb/resource.rb
Overview
Abstract base for every Atlas resource type.
Subclasses define a ROUTE constant (e.g. "/communities/") and override
whichever of find / create / destroy / update / metadata / mods apply.
The Resource class itself ships three endpoints that are not
type-specific: a generic resolver, an XML preview helper, and a
permissions lookup.
The Atlas resource hierarchy is:
{Community} → {Collection} → {Work} → {FileSet} → {Blob}
Subclasses extend FaradayHelper so that connection(...) and
multipart(...) are available as class methods.
Direct Known Subclasses
Class Method Summary collapse
-
.find(id) ⇒ Hash{String => String, Hash}
Resolve any Atlas resource by ID without knowing its type up front.
-
.permissions(id) ⇒ Hash
Fetch the access-control entries for a resource.
-
.preview(xml_path) ⇒ String
Validate a MODS XML document against Atlas's schema without persisting it.
Methods included from FaradayHelper
Class Method Details
.find(id) ⇒ Hash{String => String, Hash}
Resolve any Atlas resource by ID without knowing its type up front.
The Atlas server returns a single-key JSON object whose key names the
resource type ("community", "collection", "work", etc.); this
method splits that into a normalized { "klass" => ..., "resource" => ... }
pair so callers can dispatch on type.
36 37 38 39 40 |
# File 'lib/atlas_rb/resource.rb', line 36 def self.find(id) result = JSON.parse(connection({}).get('/resources/' + id)&.body) { "klass" => result.first[0].capitalize, "resource" => result.first[1] } end |
.permissions(id) ⇒ Hash
Fetch the access-control entries for a resource.
68 69 70 |
# File 'lib/atlas_rb/resource.rb', line 68 def self.(id) result = JSON.parse(connection({}).get('/resources/' + id + '/permissions')&.body)["resource"] end |
.preview(xml_path) ⇒ String
Validate a MODS XML document against Atlas's schema without persisting it.
Useful for surfacing validation errors in UIs before the user commits.
52 53 54 55 56 57 |
# File 'lib/atlas_rb/resource.rb', line 52 def self.preview(xml_path) payload = { binary: Faraday::Multipart::FilePart.new(File.open(xml_path), "application/xml", File.basename(xml_path)) } multipart({}).post('/resources/preview', payload)&.body end |