atlas_rb 1.29.10 → 1.29.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.version +1 -1
- data/CHANGELOG.md +20 -0
- data/Gemfile.lock +1 -1
- data/README.md +19 -0
- data/lib/atlas_rb/resource.rb +37 -9
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f9830ee62fc5d43c43c2a47ddb42354199f944a9a4d2fe559406d5e5df607257
|
|
4
|
+
data.tar.gz: c3a1b2034baeafdc89ea33a83050e47acbd1bcb79d0fbb74ddf49846de95021f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4388c5b2e0d815080ccc87bac6f1549dd11eddfd83a5c470184c06822b1160d008f73827c948049dbd149ae0a6961d1c1f29b39c7140f91f959426b26eb4b9ff
|
|
7
|
+
data.tar.gz: 9c374d0c7841d4e28be2c30fc6c6bc9e23d82b240ed986239e33162281317e8eec8f5aefd0f7ad72208883782bef3db743259c859f2050b5fee5b14ed7ee595d
|
data/.version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.29.
|
|
1
|
+
1.29.11
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.29.11
|
|
4
|
+
|
|
5
|
+
### Added — previews in any metadata format, and the format list
|
|
6
|
+
|
|
7
|
+
- `Resource.preview` takes `metadata_format:`, such as `"dwc"`. It defaults
|
|
8
|
+
to `"mods"`, so existing calls render as before.
|
|
9
|
+
- `Resource.metadata_formats` lists the formats `preview` renders, from
|
|
10
|
+
`GET /metadata_formats`, as `id`, `label` and `media_type`. The `id` is
|
|
11
|
+
the token `preview` takes.
|
|
12
|
+
|
|
13
|
+
Needs Atlas 0.7.12 or later. An older Atlas ignores `metadata_format` and
|
|
14
|
+
treats every draft as MODS, and answers `404` for the format list.
|
|
15
|
+
|
|
16
|
+
### Changed — `Resource.preview` raises on an error status
|
|
17
|
+
|
|
18
|
+
`preview` raises `AtlasRb::ResourceError` on a non-2xx. It used to return
|
|
19
|
+
the error body as if it were the HTML, so a caller that marked the result
|
|
20
|
+
HTML-safe would write Atlas's error JSON into its page. A refused draft
|
|
21
|
+
answers `422`, and the error's `body` is the JSON envelope.
|
|
22
|
+
|
|
3
23
|
## 1.29.10
|
|
4
24
|
|
|
5
25
|
### Fixed — documentation that the code contradicts
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -578,6 +578,25 @@ checks shape only, so validate against `tdwg_dwc_simple.xsd` before you call.
|
|
|
578
578
|
The two version calls behave as `mods_versions` and `mods_version` do, under
|
|
579
579
|
the same admin gate.
|
|
580
580
|
|
|
581
|
+
### Previewing a draft
|
|
582
|
+
|
|
583
|
+
`Resource.preview` renders a draft as HTML and saves nothing. The HTML is what
|
|
584
|
+
the format's display endpoint gives for a stored record. `Resource.metadata_formats`
|
|
585
|
+
lists the formats it takes, MODS first, so a format picker needs no
|
|
586
|
+
hard-coded list:
|
|
587
|
+
|
|
588
|
+
```ruby
|
|
589
|
+
AtlasRb::Resource.metadata_formats.map { |f| [f["label"], f["id"]] }
|
|
590
|
+
# => [["MODS", "mods"], ["Darwin Core", "dwc"]]
|
|
591
|
+
|
|
592
|
+
AtlasRb::Resource.preview("/tmp/draft-mods.xml") # MODS
|
|
593
|
+
AtlasRb::Resource.preview("/tmp/draft-dwc.xml", metadata_format: "dwc") # Darwin Core
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
`preview` raises `ResourceError` on a refused draft. Its body's `error` names
|
|
597
|
+
the rule: a Darwin Core shape rule, as `put_dwc` reports, or
|
|
598
|
+
`unknown_metadata_format` for a token Atlas does not preview.
|
|
599
|
+
|
|
581
600
|
The two mutations raise the same way `reparent` does — `LinkedMemberError`
|
|
582
601
|
on a structural `422` (carrying the envelope's `error` code as `#code`) and
|
|
583
602
|
`ForbiddenError` on a `403` — instead of swallowing the envelope.
|
data/lib/atlas_rb/resource.rb
CHANGED
|
@@ -303,27 +303,55 @@ module AtlasRb
|
|
|
303
303
|
.get("/resources/search")) { |body| AtlasRb::Mash.new(body) }
|
|
304
304
|
end
|
|
305
305
|
|
|
306
|
-
#
|
|
306
|
+
# Render an unsaved metadata draft as HTML, without persisting anything.
|
|
307
307
|
#
|
|
308
|
-
#
|
|
308
|
+
# The HTML is what the format's display endpoint gives for a stored record:
|
|
309
|
+
# a MODS draft renders as `/works/{id}/mods.html` does, a Darwin Core draft
|
|
310
|
+
# as `/works/{id}/dwc.html` does. {metadata_formats} lists the formats.
|
|
309
311
|
#
|
|
310
|
-
# @param xml_path [String] path to
|
|
312
|
+
# @param xml_path [String] path to the draft XML file on disk.
|
|
313
|
+
# @param metadata_format [String] the draft's format token, such as
|
|
314
|
+
# `"mods"` or `"dwc"`. Defaults to `"mods"`.
|
|
311
315
|
# @param nuid [String, nil] optional acting user's NUID. On the relay-signing
|
|
312
316
|
# path it is signed into the assertion `sub`; on the BYO-JWT (`ATLAS_JWT`)
|
|
313
317
|
# path it is ignored (identity lives in the token).
|
|
314
318
|
# @param on_behalf_of [String, nil] optional NUID for the `On-Behalf-Of`
|
|
315
319
|
# header. Falls through to {AtlasRb.config}.default_on_behalf_of when
|
|
316
320
|
# omitted.
|
|
317
|
-
# @return [String] the
|
|
318
|
-
#
|
|
321
|
+
# @return [String] the rendered HTML.
|
|
322
|
+
# @raise [AtlasRb::ResourceError] on a non-2xx. A draft Atlas refuses
|
|
323
|
+
# answers `422`; the error's `body` is the JSON envelope, whose `"error"`
|
|
324
|
+
# names the rule, such as `"record_count"` or `"unknown_metadata_format"`.
|
|
319
325
|
#
|
|
320
326
|
# @example
|
|
321
|
-
# AtlasRb::Resource.preview("/tmp/draft-
|
|
322
|
-
def self.preview(xml_path, nuid: nil, on_behalf_of: nil)
|
|
327
|
+
# AtlasRb::Resource.preview("/tmp/draft-dwc.xml", metadata_format: "dwc")
|
|
328
|
+
def self.preview(xml_path, metadata_format: "mods", nuid: nil, on_behalf_of: nil)
|
|
323
329
|
payload = { binary: Faraday::Multipart::FilePart.new(File.open(xml_path),
|
|
324
330
|
"application/xml",
|
|
325
|
-
File.basename(xml_path))
|
|
326
|
-
|
|
331
|
+
File.basename(xml_path)),
|
|
332
|
+
metadata_format: metadata_format }
|
|
333
|
+
read_raw(multipart(nuid, on_behalf_of: on_behalf_of).post('/resources/preview', payload))
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
# List the metadata formats {preview} renders, MODS first.
|
|
337
|
+
#
|
|
338
|
+
# Build a format picker from this rather than a hard-coded list. A Work's
|
|
339
|
+
# own `"metadata_formats"` lists the additional records it holds, by the
|
|
340
|
+
# same tokens; it leaves out MODS, which every Work holds.
|
|
341
|
+
#
|
|
342
|
+
# @param nuid [String, nil] optional acting user's NUID.
|
|
343
|
+
# @param on_behalf_of [String, nil] optional NUID for the `On-Behalf-Of`
|
|
344
|
+
# header.
|
|
345
|
+
# @return [Array<AtlasRb::Mash>] one entry per format, with `"id"` (the token),
|
|
346
|
+
# `"label"` and `"media_type"`.
|
|
347
|
+
# @raise [AtlasRb::ResourceError] on a non-2xx other than `404` / `410`.
|
|
348
|
+
#
|
|
349
|
+
# @example
|
|
350
|
+
# AtlasRb::Resource.metadata_formats.map { |f| [f["label"], f["id"]] }
|
|
351
|
+
# # => [["MODS", "mods"], ["Darwin Core", "dwc"]]
|
|
352
|
+
def self.metadata_formats(nuid: nil, on_behalf_of: nil)
|
|
353
|
+
read_body(connection({}, nuid, on_behalf_of: on_behalf_of)
|
|
354
|
+
.get("/metadata_formats")) { |body| body.map { |entry| AtlasRb::Mash.new(entry) } }
|
|
327
355
|
end
|
|
328
356
|
|
|
329
357
|
# Fetch the access-control entries for a resource.
|