Class: AtlasRb::FileSet

Inherits:
Resource show all
Defined in:
lib/atlas_rb/file_set.rb

Overview

An ordered, classified slot under a Work that holds a Blob.

FileSets give a Work multiple distinct files (e.g. a primary PDF, a supplemental dataset, a thumbnail) and tag each with a classification so the UI knows how to display it. The actual binary content lives on the associated Blob.

See also: Work, Blob.

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.

"/file_sets/"

Class Method Summary collapse

Methods inherited from Resource

permissions, preview

Methods included from FaradayHelper

#connection, #multipart

Class Method Details

.create(id, classification) ⇒ Hash

Create a new FileSet under a Work.

Examples:

fs = AtlasRb::FileSet.create("w-789", "primary")
AtlasRb::FileSet.update(fs["id"], "/tmp/article.pdf")

Parameters:

  • id (String)

    the parent Work ID.

  • classification (String)

    role tag for the FileSet — e.g. "primary", "supplemental", "thumbnail". The exact set is defined by the Atlas server.

Returns:

  • (Hash)

    the created "file_set" payload, including its "id" which can then be passed to update to attach a binary.



40
41
42
# File 'lib/atlas_rb/file_set.rb', line 40

def self.create(id, classification)
  JSON.parse(connection({ work_id: id, classification: classification }).post(ROUTE)&.body)["file_set"]
end

.destroy(id) ⇒ Faraday::Response

Delete a FileSet.

Examples:

AtlasRb::FileSet.destroy("fs-001")

Parameters:

  • id (String)

    the FileSet ID.

Returns:

  • (Faraday::Response)

    the raw delete response.



51
52
53
# File 'lib/atlas_rb/file_set.rb', line 51

def self.destroy(id)
  connection({}).delete(ROUTE + id)
end

.find(id) ⇒ Hash

Fetch a single FileSet by ID.

Examples:

AtlasRb::FileSet.find("fs-001")

Parameters:

  • id (String)

    the FileSet ID.

Returns:

  • (Hash)

    the "file_set" object, already unwrapped.



24
25
26
# File 'lib/atlas_rb/file_set.rb', line 24

def self.find(id)
  JSON.parse(connection({}).get(ROUTE + id)&.body)["file_set"]
end

.update(id, blob_path) ⇒ Hash

Attach (or replace) the binary content backing this FileSet.

The body is uploaded as application/octet-stream regardless of the file's true type — Atlas inspects the content server-side. To upload a binary blob plus an original filename, use Blob.create directly against the underlying /files/ endpoint.

Examples:

AtlasRb::FileSet.update("fs-001", "/tmp/article.pdf")

Parameters:

  • id (String)

    the FileSet ID.

  • blob_path (String)

    path to the binary file on disk.

Returns:

  • (Hash)

    the parsed JSON response from the patch.



68
69
70
71
72
73
74
# File 'lib/atlas_rb/file_set.rb', line 68

def self.update(id, blob_path)
  # Need to figure out blob vs XML
  payload = { binary: Faraday::Multipart::FilePart.new(File.open(blob_path),
                                                      "application/octet-stream",
                                                      File.basename(blob_path)) }
  JSON.parse(multipart({}).patch(ROUTE + id, payload)&.body)
end