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, idempotency_key: nil) ⇒ Hash

Create a new FileSet under a Work.

Examples:

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

Retry-safe bulk-deposit create

key = SecureRandom.uuid
AtlasRb::FileSet.create("w-789", "primary", idempotency_key: key)

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.

  • idempotency_key (String, nil) (defaults to: nil)

    optional UUID. A repeat call with the same key returns the originally-created FileSet instead of creating a new one. See Work.create for full semantics.

Returns:

  • (Hash)

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



47
48
49
50
51
52
# File 'lib/atlas_rb/file_set.rb', line 47

def self.create(id, classification, idempotency_key: nil)
  AtlasRb::Mash.new(JSON.parse(
    connection({ work_id: id, classification: classification }, nil,
               idempotency_key: idempotency_key).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.



61
62
63
# File 'lib/atlas_rb/file_set.rb', line 61

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)
  AtlasRb::Mash.new(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.



78
79
80
81
82
83
84
# File 'lib/atlas_rb/file_set.rb', line 78

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)) }
  AtlasRb::Mash.new(JSON.parse(multipart({}).patch(ROUTE + id, payload)&.body))
end