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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a41cd3a20e9d87272ff866480fbdd650d9c9a286afa63ad0fe999a978342be6a
4
- data.tar.gz: ed569b1627bdb06488a35fa4f7683fe4b82bfa4f674dcde6b603655f9e2a2082
3
+ metadata.gz: f9830ee62fc5d43c43c2a47ddb42354199f944a9a4d2fe559406d5e5df607257
4
+ data.tar.gz: c3a1b2034baeafdc89ea33a83050e47acbd1bcb79d0fbb74ddf49846de95021f
5
5
  SHA512:
6
- metadata.gz: 7473a5fb3a8a87d1176f8b8832df36bd4c952210d3ee52f027cecf96d0285673e27659e3d06e27c2d53eabe6a9949e45406965cdc5558fa22943206e3dc270fa
7
- data.tar.gz: f145be9dc509c7c9bd01f93f1fd672dfd75fd07ff43edeeffee437b51b097609aaa7571a0e724850f2ba9ec55632a253ad03f01050577f58029822d6a76f310c
6
+ metadata.gz: 4388c5b2e0d815080ccc87bac6f1549dd11eddfd83a5c470184c06822b1160d008f73827c948049dbd149ae0a6961d1c1f29b39c7140f91f959426b26eb4b9ff
7
+ data.tar.gz: 9c374d0c7841d4e28be2c30fc6c6bc9e23d82b240ed986239e33162281317e8eec8f5aefd0f7ad72208883782bef3db743259c859f2050b5fee5b14ed7ee595d
data/.version CHANGED
@@ -1 +1 @@
1
- 1.29.10
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- atlas_rb (1.29.10)
4
+ atlas_rb (1.29.11)
5
5
  faraday (~> 2.7)
6
6
  faraday-follow_redirects (~> 0.5)
7
7
  faraday-multipart (~> 1)
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.
@@ -303,27 +303,55 @@ module AtlasRb
303
303
  .get("/resources/search")) { |body| AtlasRb::Mash.new(body) }
304
304
  end
305
305
 
306
- # Validate a MODS XML document against Atlas's schema *without* persisting it.
306
+ # Render an unsaved metadata draft as HTML, without persisting anything.
307
307
  #
308
- # Useful for surfacing validation errors in UIs before the user commits.
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 a MODS XML file on disk.
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 raw response body from `POST /resources/preview`
318
- # — typically a JSON or XML error report.
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-mods.xml")
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
- multipart(nuid, on_behalf_of: on_behalf_of).post('/resources/preview', payload)&.body
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.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atlas_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.29.10
4
+ version: 1.29.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cliff