atlas_rb 0.0.97 → 0.0.99
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/Gemfile.lock +2 -2
- data/lib/atlas_rb/blob.rb +25 -10
- data/lib/atlas_rb/collection.rb +30 -12
- data/lib/atlas_rb/community.rb +30 -12
- data/lib/atlas_rb/resource.rb +15 -6
- data/lib/atlas_rb/work.rb +40 -16
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4eca6ad0d27c37d1c2b6d367c620e981acef4c3dd39fcf7a888f05827438b8eb
|
|
4
|
+
data.tar.gz: 4d20891f98883ffa158039515f6108f7e147c181da4adc146933b571063640c2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fe7aec013ecd78e381bef342e226e499a97b1c37b2120d912aec1636f64a2de4536182436407ebf920df254818054cf73f39046aa4848b93ff818af2a266d3fa
|
|
7
|
+
data.tar.gz: 32b39e4905ea9463d9c6cce7aff994e9925fb8de1d11ce8a619ab0520a07d358657d8f23c90c4b8ae7d35aa1ad799a825457b6a1a5bdeeaad4472ad1ef6ad579
|
data/.version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0.
|
|
1
|
+
0.0.99
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
atlas_rb (0.0.
|
|
4
|
+
atlas_rb (0.0.99)
|
|
5
5
|
faraday (~> 2.7)
|
|
6
6
|
faraday-follow_redirects (~> 0.3.0)
|
|
7
7
|
faraday-multipart (~> 1)
|
|
@@ -19,7 +19,7 @@ GEM
|
|
|
19
19
|
faraday (>= 1, < 3)
|
|
20
20
|
faraday-multipart (1.2.0)
|
|
21
21
|
multipart-post (~> 2.0)
|
|
22
|
-
faraday-net_http (3.4.
|
|
22
|
+
faraday-net_http (3.4.3)
|
|
23
23
|
net-http (~> 0.5)
|
|
24
24
|
hashie (5.1.0)
|
|
25
25
|
logger
|
data/lib/atlas_rb/blob.rb
CHANGED
|
@@ -17,14 +17,17 @@ module AtlasRb
|
|
|
17
17
|
# Fetch a single Blob's metadata record (not its bytes — see {.content}).
|
|
18
18
|
#
|
|
19
19
|
# @param id [String] the Blob ID.
|
|
20
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
21
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
22
|
+
# tokens still resolve without it.
|
|
20
23
|
# @return [Hash] the `"blob"` object, already unwrapped — typically
|
|
21
24
|
# includes `"id"`, `"original_filename"`, `"size"`, and a download URL.
|
|
22
25
|
#
|
|
23
26
|
# @example
|
|
24
27
|
# AtlasRb::Blob.find("b-321")
|
|
25
28
|
# # => { "id" => "b-321", "original_filename" => "scan.pdf", ... }
|
|
26
|
-
def self.find(id)
|
|
27
|
-
AtlasRb::Mash.new(JSON.parse(connection({}).get(ROUTE + id)&.body))['blob']
|
|
29
|
+
def self.find(id, nuid: nil)
|
|
30
|
+
AtlasRb::Mash.new(JSON.parse(connection({}, nuid).get(ROUTE + id)&.body))['blob']
|
|
28
31
|
end
|
|
29
32
|
|
|
30
33
|
# Stream the Blob's binary content through a caller-supplied block.
|
|
@@ -35,6 +38,9 @@ module AtlasRb
|
|
|
35
38
|
# returned so callers can inspect `Content-Type`, `Content-Length`, etc.
|
|
36
39
|
#
|
|
37
40
|
# @param id [String] the Blob ID.
|
|
41
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
42
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
43
|
+
# tokens still resolve without it.
|
|
38
44
|
# @yieldparam chunk [String] the next chunk of binary data.
|
|
39
45
|
# @return [Hash] the response headers from `GET /files/<id>/content`.
|
|
40
46
|
#
|
|
@@ -43,9 +49,9 @@ module AtlasRb
|
|
|
43
49
|
# headers = AtlasRb::Blob.content("b-321") { |chunk| f.write(chunk) }
|
|
44
50
|
# puts headers["content-type"]
|
|
45
51
|
# end
|
|
46
|
-
def self.content(id, &chunk_handler)
|
|
52
|
+
def self.content(id, nuid: nil, &chunk_handler)
|
|
47
53
|
headers = {}
|
|
48
|
-
connection({}).get("#{ROUTE}#{id}/content") do |req|
|
|
54
|
+
connection({}, nuid).get("#{ROUTE}#{id}/content") do |req|
|
|
49
55
|
req.options.on_data = proc do |chunk, _bytes_received, env|
|
|
50
56
|
headers = env.response_headers if headers.empty? && env
|
|
51
57
|
chunk_handler.call(chunk)
|
|
@@ -68,6 +74,9 @@ module AtlasRb
|
|
|
68
74
|
# @param idempotency_key [String, nil] optional UUID. A repeat call with
|
|
69
75
|
# the same key returns the originally-created Blob instead of creating
|
|
70
76
|
# a new one. See {AtlasRb::Work.create} for full semantics.
|
|
77
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
78
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
79
|
+
# tokens still resolve without it.
|
|
71
80
|
# @return [Hash] the created `"blob"` payload, including its `"id"`.
|
|
72
81
|
#
|
|
73
82
|
# @example
|
|
@@ -78,7 +87,7 @@ module AtlasRb
|
|
|
78
87
|
# key = SecureRandom.uuid
|
|
79
88
|
# AtlasRb::Blob.create("w-789", "/tmp/upload.tmp", "thesis.pdf",
|
|
80
89
|
# idempotency_key: key)
|
|
81
|
-
def self.create(id, blob_path, original_filename, idempotency_key: nil)
|
|
90
|
+
def self.create(id, blob_path, original_filename, idempotency_key: nil, nuid: nil)
|
|
82
91
|
payload = { work_id: id,
|
|
83
92
|
original_filename: original_filename,
|
|
84
93
|
binary: Faraday::Multipart::FilePart.new(File.open(blob_path),
|
|
@@ -86,19 +95,22 @@ module AtlasRb
|
|
|
86
95
|
File.basename(blob_path)) }
|
|
87
96
|
|
|
88
97
|
AtlasRb::Mash.new(JSON.parse(
|
|
89
|
-
multipart(
|
|
98
|
+
multipart(nuid, idempotency_key: idempotency_key).post(ROUTE, payload)&.body
|
|
90
99
|
))['blob']
|
|
91
100
|
end
|
|
92
101
|
|
|
93
102
|
# Delete a Blob (the bytes *and* the metadata record).
|
|
94
103
|
#
|
|
95
104
|
# @param id [String] the Blob ID.
|
|
105
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
106
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
107
|
+
# tokens still resolve without it.
|
|
96
108
|
# @return [Faraday::Response] the raw delete response.
|
|
97
109
|
#
|
|
98
110
|
# @example
|
|
99
111
|
# AtlasRb::Blob.destroy("b-321")
|
|
100
|
-
def self.destroy(id)
|
|
101
|
-
connection({}).delete(ROUTE + id)
|
|
112
|
+
def self.destroy(id, nuid: nil)
|
|
113
|
+
connection({}, nuid).delete(ROUTE + id)
|
|
102
114
|
end
|
|
103
115
|
|
|
104
116
|
# Replace the bytes of an existing Blob in-place.
|
|
@@ -109,15 +121,18 @@ module AtlasRb
|
|
|
109
121
|
#
|
|
110
122
|
# @param id [String] the Blob ID.
|
|
111
123
|
# @param blob_path [String] path to the replacement binary on disk.
|
|
124
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
125
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
126
|
+
# tokens still resolve without it.
|
|
112
127
|
# @return [Hash] the parsed JSON response from the patch.
|
|
113
128
|
#
|
|
114
129
|
# @example
|
|
115
130
|
# AtlasRb::Blob.update("b-321", "/tmp/revised.pdf")
|
|
116
|
-
def self.update(id, blob_path)
|
|
131
|
+
def self.update(id, blob_path, nuid: nil)
|
|
117
132
|
payload = { binary: Faraday::Multipart::FilePart.new(File.open(blob_path),
|
|
118
133
|
"application/octet-stream",
|
|
119
134
|
File.basename(blob_path)) }
|
|
120
|
-
AtlasRb::Mash.new(JSON.parse(multipart(
|
|
135
|
+
AtlasRb::Mash.new(JSON.parse(multipart(nuid).patch(ROUTE + id, payload)&.body))
|
|
121
136
|
end
|
|
122
137
|
end
|
|
123
138
|
end
|
data/lib/atlas_rb/collection.rb
CHANGED
|
@@ -16,14 +16,17 @@ module AtlasRb
|
|
|
16
16
|
# Fetch a single Collection by ID.
|
|
17
17
|
#
|
|
18
18
|
# @param id [String] the Collection ID.
|
|
19
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
20
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
21
|
+
# tokens still resolve without it.
|
|
19
22
|
# @return [Hash] the `"collection"` object, already unwrapped from the
|
|
20
23
|
# JSON response.
|
|
21
24
|
#
|
|
22
25
|
# @example
|
|
23
26
|
# AtlasRb::Collection.find("col-456")
|
|
24
27
|
# # => { "id" => "col-456", "title" => "Faculty Publications", ... }
|
|
25
|
-
def self.find(id)
|
|
26
|
-
AtlasRb::Mash.new(JSON.parse(connection({}).get(ROUTE + id)&.body))["collection"]
|
|
28
|
+
def self.find(id, nuid: nil)
|
|
29
|
+
AtlasRb::Mash.new(JSON.parse(connection({}, nuid).get(ROUTE + id)&.body))["collection"]
|
|
27
30
|
end
|
|
28
31
|
|
|
29
32
|
# Create a new Collection under an existing Community.
|
|
@@ -36,13 +39,16 @@ module AtlasRb
|
|
|
36
39
|
# @param xml_path [String, nil] optional path to a MODS XML file used to
|
|
37
40
|
# seed metadata. When given, the Collection is created and immediately
|
|
38
41
|
# patched with the metadata in the file.
|
|
42
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
43
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
44
|
+
# tokens still resolve without it.
|
|
39
45
|
# @return [Hash] the created Collection payload (post-update if
|
|
40
46
|
# `xml_path` was supplied).
|
|
41
47
|
#
|
|
42
48
|
# @example
|
|
43
49
|
# AtlasRb::Collection.create("c-123", "/tmp/collection-mods.xml")
|
|
44
|
-
def self.create(id, xml_path = nil)
|
|
45
|
-
result = AtlasRb::Mash.new(JSON.parse(connection({ parent_id: id }).post(ROUTE)&.body))["collection"]
|
|
50
|
+
def self.create(id, xml_path = nil, nuid: nil)
|
|
51
|
+
result = AtlasRb::Mash.new(JSON.parse(connection({ parent_id: id }, nuid).post(ROUTE)&.body))["collection"]
|
|
46
52
|
return result unless xml_path.present?
|
|
47
53
|
|
|
48
54
|
update(result["id"], xml_path)
|
|
@@ -114,15 +120,18 @@ module AtlasRb
|
|
|
114
120
|
#
|
|
115
121
|
# @param id [String] the Collection ID.
|
|
116
122
|
# @param xml_path [String] path to a MODS XML file on disk.
|
|
123
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
124
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
125
|
+
# tokens still resolve without it.
|
|
117
126
|
# @return [Hash] the parsed JSON response from the patch.
|
|
118
127
|
#
|
|
119
128
|
# @example
|
|
120
129
|
# AtlasRb::Collection.update("col-456", "/tmp/collection-mods.xml")
|
|
121
|
-
def self.update(id, xml_path)
|
|
130
|
+
def self.update(id, xml_path, nuid: nil)
|
|
122
131
|
payload = { binary: Faraday::Multipart::FilePart.new(File.open(xml_path),
|
|
123
132
|
"application/xml",
|
|
124
133
|
File.basename(xml_path)) }
|
|
125
|
-
AtlasRb::Mash.new(JSON.parse(multipart(
|
|
134
|
+
AtlasRb::Mash.new(JSON.parse(multipart(nuid).patch(ROUTE + id, payload)&.body))
|
|
126
135
|
end
|
|
127
136
|
|
|
128
137
|
# Patch individual descriptive-metadata fields without uploading a
|
|
@@ -134,12 +143,15 @@ module AtlasRb
|
|
|
134
143
|
#
|
|
135
144
|
# @param id [String] the Collection ID.
|
|
136
145
|
# @param values [Hash] field-level metadata updates.
|
|
146
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
147
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
148
|
+
# tokens still resolve without it.
|
|
137
149
|
# @return [Hash] the parsed JSON response.
|
|
138
150
|
#
|
|
139
151
|
# @example
|
|
140
152
|
# AtlasRb::Collection.metadata("col-456", title: "Renamed Collection")
|
|
141
|
-
def self.metadata(id, values)
|
|
142
|
-
AtlasRb::Mash.new(JSON.parse(connection({ metadata: values }).patch(ROUTE + id)&.body))
|
|
153
|
+
def self.metadata(id, values, nuid: nil)
|
|
154
|
+
AtlasRb::Mash.new(JSON.parse(connection({ metadata: values }, nuid).patch(ROUTE + id)&.body))
|
|
143
155
|
end
|
|
144
156
|
|
|
145
157
|
# Attach the three thumbnail/preview Delegate URIs to a Collection.
|
|
@@ -153,6 +165,9 @@ module AtlasRb
|
|
|
153
165
|
# @param thumbnail [String, nil] IIIF URI for the ~85² thumbnail.
|
|
154
166
|
# @param thumbnail_2x [String, nil] IIIF URI for the ~170² 2x thumbnail.
|
|
155
167
|
# @param preview [String, nil] IIIF URI for the ~500w preview image.
|
|
168
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
169
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
170
|
+
# tokens still resolve without it.
|
|
156
171
|
# @return [AtlasRb::Mash] the parsed JSON response.
|
|
157
172
|
#
|
|
158
173
|
# @example
|
|
@@ -162,10 +177,10 @@ module AtlasRb
|
|
|
162
177
|
# thumbnail_2x: "https://iiif.example.edu/iiif/3/c.jp2/full/!170,170/0/default.jpg",
|
|
163
178
|
# preview: "https://iiif.example.edu/iiif/3/c.jp2/full/500,/0/default.jpg"
|
|
164
179
|
# )
|
|
165
|
-
def self.set_thumbnails(id, thumbnail: nil, thumbnail_2x: nil, preview: nil)
|
|
180
|
+
def self.set_thumbnails(id, thumbnail: nil, thumbnail_2x: nil, preview: nil, nuid: nil)
|
|
166
181
|
body = { thumbnail: thumbnail, thumbnail_2x: thumbnail_2x, preview: preview }.compact
|
|
167
182
|
AtlasRb::Mash.new(JSON.parse(
|
|
168
|
-
connection({}).patch(ROUTE + id + '/thumbnails', JSON.dump(body))&.body
|
|
183
|
+
connection({}, nuid).patch(ROUTE + id + '/thumbnails', JSON.dump(body))&.body
|
|
169
184
|
))
|
|
170
185
|
end
|
|
171
186
|
|
|
@@ -174,13 +189,16 @@ module AtlasRb
|
|
|
174
189
|
# @param id [String] the Collection ID.
|
|
175
190
|
# @param kind [String, nil] one of `"json"` (default), `"html"`, or
|
|
176
191
|
# `"xml"`.
|
|
192
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
193
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
194
|
+
# tokens still resolve without it.
|
|
177
195
|
# @return [String] the raw response body in the requested format.
|
|
178
196
|
#
|
|
179
197
|
# @example
|
|
180
198
|
# AtlasRb::Collection.mods("col-456", "xml")
|
|
181
|
-
def self.mods(id, kind = nil)
|
|
199
|
+
def self.mods(id, kind = nil, nuid: nil)
|
|
182
200
|
# json default, html, xml
|
|
183
|
-
connection({}).get(
|
|
201
|
+
connection({}, nuid).get(
|
|
184
202
|
ROUTE + id + '/mods' + (kind.present? ? ".#{kind}" : '')
|
|
185
203
|
)&.body
|
|
186
204
|
end
|
data/lib/atlas_rb/community.rb
CHANGED
|
@@ -17,14 +17,17 @@ module AtlasRb
|
|
|
17
17
|
# Fetch a single Community by ID.
|
|
18
18
|
#
|
|
19
19
|
# @param id [String] the Community ID.
|
|
20
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
21
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
22
|
+
# tokens still resolve without it.
|
|
20
23
|
# @return [Hash] the `"community"` object from the JSON response,
|
|
21
24
|
# already unwrapped.
|
|
22
25
|
#
|
|
23
26
|
# @example
|
|
24
27
|
# AtlasRb::Community.find("c-123")
|
|
25
28
|
# # => { "id" => "c-123", "title" => "College of Engineering", ... }
|
|
26
|
-
def self.find(id)
|
|
27
|
-
AtlasRb::Mash.new(JSON.parse(connection({}).get(ROUTE + id)&.body))["community"]
|
|
29
|
+
def self.find(id, nuid: nil)
|
|
30
|
+
AtlasRb::Mash.new(JSON.parse(connection({}, nuid).get(ROUTE + id)&.body))["community"]
|
|
28
31
|
end
|
|
29
32
|
|
|
30
33
|
# Create a new Community, optionally seeded with MODS metadata.
|
|
@@ -37,6 +40,9 @@ module AtlasRb
|
|
|
37
40
|
# @param xml_path [String, nil] optional path to a MODS XML file. When
|
|
38
41
|
# given, the Community is created and immediately patched with the
|
|
39
42
|
# metadata in the file; the returned Hash reflects the patched state.
|
|
43
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
44
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
45
|
+
# tokens still resolve without it.
|
|
40
46
|
# @return [Hash] the created Community payload (post-update if `xml_path`
|
|
41
47
|
# was supplied).
|
|
42
48
|
#
|
|
@@ -45,8 +51,8 @@ module AtlasRb
|
|
|
45
51
|
#
|
|
46
52
|
# @example Sub-community seeded from MODS
|
|
47
53
|
# AtlasRb::Community.create("c-parent", "/tmp/dept-mods.xml")
|
|
48
|
-
def self.create(id = nil, xml_path = nil)
|
|
49
|
-
result = AtlasRb::Mash.new(JSON.parse(connection({ parent_id: id }).post(ROUTE)&.body))["community"]
|
|
54
|
+
def self.create(id = nil, xml_path = nil, nuid: nil)
|
|
55
|
+
result = AtlasRb::Mash.new(JSON.parse(connection({ parent_id: id }, nuid).post(ROUTE)&.body))["community"]
|
|
50
56
|
return result unless xml_path.present?
|
|
51
57
|
|
|
52
58
|
update(result["id"], xml_path)
|
|
@@ -119,15 +125,18 @@ module AtlasRb
|
|
|
119
125
|
#
|
|
120
126
|
# @param id [String] the Community ID.
|
|
121
127
|
# @param xml_path [String] path to a MODS XML file on disk.
|
|
128
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
129
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
130
|
+
# tokens still resolve without it.
|
|
122
131
|
# @return [Hash] the parsed JSON response from the patch.
|
|
123
132
|
#
|
|
124
133
|
# @example
|
|
125
134
|
# AtlasRb::Community.update("c-123", "/tmp/community-mods.xml")
|
|
126
|
-
def self.update(id, xml_path)
|
|
135
|
+
def self.update(id, xml_path, nuid: nil)
|
|
127
136
|
payload = { binary: Faraday::Multipart::FilePart.new(File.open(xml_path),
|
|
128
137
|
"application/xml",
|
|
129
138
|
File.basename(xml_path)) }
|
|
130
|
-
AtlasRb::Mash.new(JSON.parse(multipart(
|
|
139
|
+
AtlasRb::Mash.new(JSON.parse(multipart(nuid).patch(ROUTE + id, payload)&.body))
|
|
131
140
|
end
|
|
132
141
|
|
|
133
142
|
# Patch individual descriptive-metadata fields without uploading a
|
|
@@ -140,12 +149,15 @@ module AtlasRb
|
|
|
140
149
|
# @param id [String] the Community ID.
|
|
141
150
|
# @param values [Hash] field-level metadata updates (shape determined by
|
|
142
151
|
# the Atlas server, typically a mapping from MODS field name to value).
|
|
152
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
153
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
154
|
+
# tokens still resolve without it.
|
|
143
155
|
# @return [Hash] the parsed JSON response.
|
|
144
156
|
#
|
|
145
157
|
# @example
|
|
146
158
|
# AtlasRb::Community.metadata("c-123", title: "New Name")
|
|
147
|
-
def self.metadata(id, values)
|
|
148
|
-
AtlasRb::Mash.new(JSON.parse(connection({ metadata: values }).patch(ROUTE + id)&.body))
|
|
159
|
+
def self.metadata(id, values, nuid: nil)
|
|
160
|
+
AtlasRb::Mash.new(JSON.parse(connection({ metadata: values }, nuid).patch(ROUTE + id)&.body))
|
|
149
161
|
end
|
|
150
162
|
|
|
151
163
|
# Attach the three thumbnail/preview Delegate URIs to a Community.
|
|
@@ -159,6 +171,9 @@ module AtlasRb
|
|
|
159
171
|
# @param thumbnail [String, nil] IIIF URI for the ~85² thumbnail.
|
|
160
172
|
# @param thumbnail_2x [String, nil] IIIF URI for the ~170² 2x thumbnail.
|
|
161
173
|
# @param preview [String, nil] IIIF URI for the ~500w preview image.
|
|
174
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
175
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
176
|
+
# tokens still resolve without it.
|
|
162
177
|
# @return [AtlasRb::Mash] the parsed JSON response.
|
|
163
178
|
#
|
|
164
179
|
# @example
|
|
@@ -168,10 +183,10 @@ module AtlasRb
|
|
|
168
183
|
# thumbnail_2x: "https://iiif.example.edu/iiif/3/m.jp2/full/!170,170/0/default.jpg",
|
|
169
184
|
# preview: "https://iiif.example.edu/iiif/3/m.jp2/full/500,/0/default.jpg"
|
|
170
185
|
# )
|
|
171
|
-
def self.set_thumbnails(id, thumbnail: nil, thumbnail_2x: nil, preview: nil)
|
|
186
|
+
def self.set_thumbnails(id, thumbnail: nil, thumbnail_2x: nil, preview: nil, nuid: nil)
|
|
172
187
|
body = { thumbnail: thumbnail, thumbnail_2x: thumbnail_2x, preview: preview }.compact
|
|
173
188
|
AtlasRb::Mash.new(JSON.parse(
|
|
174
|
-
connection({}).patch(ROUTE + id + '/thumbnails', JSON.dump(body))&.body
|
|
189
|
+
connection({}, nuid).patch(ROUTE + id + '/thumbnails', JSON.dump(body))&.body
|
|
175
190
|
))
|
|
176
191
|
end
|
|
177
192
|
|
|
@@ -181,14 +196,17 @@ module AtlasRb
|
|
|
181
196
|
# @param kind [String, nil] one of `"json"` (default when omitted),
|
|
182
197
|
# `"html"`, or `"xml"`. When `nil`, Atlas returns its default
|
|
183
198
|
# representation.
|
|
199
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
200
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
201
|
+
# tokens still resolve without it.
|
|
184
202
|
# @return [String] the raw response body (JSON, HTML, or XML serialized
|
|
185
203
|
# as a string).
|
|
186
204
|
#
|
|
187
205
|
# @example HTML rendering for display
|
|
188
206
|
# AtlasRb::Community.mods("c-123", "html")
|
|
189
|
-
def self.mods(id, kind = nil)
|
|
207
|
+
def self.mods(id, kind = nil, nuid: nil)
|
|
190
208
|
# json default, html, xml
|
|
191
|
-
connection({}).get(
|
|
209
|
+
connection({}, nuid).get(
|
|
192
210
|
ROUTE + id + '/mods' + (kind.present? ? ".#{kind}" : '')
|
|
193
211
|
)&.body
|
|
194
212
|
end
|
data/lib/atlas_rb/resource.rb
CHANGED
|
@@ -26,6 +26,9 @@ module AtlasRb
|
|
|
26
26
|
# pair so callers can dispatch on type.
|
|
27
27
|
#
|
|
28
28
|
# @param id [String] an Atlas resource ID of any type.
|
|
29
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
30
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
31
|
+
# tokens still resolve without it.
|
|
29
32
|
# @return [Hash{String => String, Hash}] hash with two keys:
|
|
30
33
|
# - `"klass"` — the resource type, capitalized (e.g. `"Work"`).
|
|
31
34
|
# - `"resource"` — the resource payload as a Hash.
|
|
@@ -33,8 +36,8 @@ module AtlasRb
|
|
|
33
36
|
# @example Polymorphic lookup
|
|
34
37
|
# AtlasRb::Resource.find("abc123")
|
|
35
38
|
# # => { "klass" => "Work", "resource" => { "id" => "abc123", "title" => "..." } }
|
|
36
|
-
def self.find(id)
|
|
37
|
-
result = JSON.parse(connection({}).get('/resources/' + id)&.body)
|
|
39
|
+
def self.find(id, nuid: nil)
|
|
40
|
+
result = JSON.parse(connection({}, nuid).get('/resources/' + id)&.body)
|
|
38
41
|
AtlasRb::Mash.new("klass" => result.first[0].capitalize,
|
|
39
42
|
"resource" => result.first[1])
|
|
40
43
|
end
|
|
@@ -44,29 +47,35 @@ module AtlasRb
|
|
|
44
47
|
# Useful for surfacing validation errors in UIs before the user commits.
|
|
45
48
|
#
|
|
46
49
|
# @param xml_path [String] path to a MODS XML file on disk.
|
|
50
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
51
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
52
|
+
# tokens still resolve without it.
|
|
47
53
|
# @return [String] the raw response body from `POST /resources/preview`
|
|
48
54
|
# — typically a JSON or XML error report.
|
|
49
55
|
#
|
|
50
56
|
# @example
|
|
51
57
|
# AtlasRb::Resource.preview("/tmp/draft-mods.xml")
|
|
52
|
-
def self.preview(xml_path)
|
|
58
|
+
def self.preview(xml_path, nuid: nil)
|
|
53
59
|
payload = { binary: Faraday::Multipart::FilePart.new(File.open(xml_path),
|
|
54
60
|
"application/xml",
|
|
55
61
|
File.basename(xml_path)) }
|
|
56
|
-
multipart(
|
|
62
|
+
multipart(nuid).post('/resources/preview', payload)&.body
|
|
57
63
|
end
|
|
58
64
|
|
|
59
65
|
# Fetch the access-control entries for a resource.
|
|
60
66
|
#
|
|
61
67
|
# @param id [String] an Atlas resource ID.
|
|
68
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
69
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
70
|
+
# tokens still resolve without it.
|
|
62
71
|
# @return [Hash] the `"resource"` payload from `GET /resources/<id>/permissions`,
|
|
63
72
|
# typically containing read/write/admin grant lists.
|
|
64
73
|
#
|
|
65
74
|
# @example
|
|
66
75
|
# AtlasRb::Resource.permissions("abc123")
|
|
67
76
|
# # => { "id" => "abc123", "read" => [...], "write" => [...] }
|
|
68
|
-
def self.permissions(id)
|
|
69
|
-
AtlasRb::Mash.new(JSON.parse(connection({}).get('/resources/' + id + '/permissions')&.body))["resource"]
|
|
77
|
+
def self.permissions(id, nuid: nil)
|
|
78
|
+
AtlasRb::Mash.new(JSON.parse(connection({}, nuid).get('/resources/' + id + '/permissions')&.body))["resource"]
|
|
70
79
|
end
|
|
71
80
|
end
|
|
72
81
|
end
|
data/lib/atlas_rb/work.rb
CHANGED
|
@@ -16,14 +16,17 @@ module AtlasRb
|
|
|
16
16
|
# Fetch a single Work by ID.
|
|
17
17
|
#
|
|
18
18
|
# @param id [String] the Work ID.
|
|
19
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
20
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
21
|
+
# tokens still resolve without it.
|
|
19
22
|
# @return [Hash] the `"work"` object, already unwrapped from the JSON
|
|
20
23
|
# response.
|
|
21
24
|
#
|
|
22
25
|
# @example
|
|
23
26
|
# AtlasRb::Work.find("w-789")
|
|
24
27
|
# # => { "id" => "w-789", "title" => "An Article", ... }
|
|
25
|
-
def self.find(id)
|
|
26
|
-
AtlasRb::Mash.new(JSON.parse(connection({}).get(ROUTE + id)&.body))["work"]
|
|
28
|
+
def self.find(id, nuid: nil)
|
|
29
|
+
AtlasRb::Mash.new(JSON.parse(connection({}, nuid).get(ROUTE + id)&.body))["work"]
|
|
27
30
|
end
|
|
28
31
|
|
|
29
32
|
# List Works, paginated.
|
|
@@ -71,6 +74,9 @@ module AtlasRb
|
|
|
71
74
|
# follow-up PATCH/GET when `xml_path` is given do not carry the key.
|
|
72
75
|
# The caller (e.g. Cerberus's Solid Queue job) generates and persists
|
|
73
76
|
# the UUID; this gem does not mint keys.
|
|
77
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
78
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
79
|
+
# tokens still resolve without it.
|
|
74
80
|
# @return [Hash] the created Work payload (post-update if `xml_path` was
|
|
75
81
|
# supplied).
|
|
76
82
|
#
|
|
@@ -83,9 +89,9 @@ module AtlasRb
|
|
|
83
89
|
# @example Retry-safe bulk-deposit create
|
|
84
90
|
# key = SecureRandom.uuid
|
|
85
91
|
# AtlasRb::Work.create("col-456", idempotency_key: key)
|
|
86
|
-
def self.create(id, xml_path = nil, idempotency_key: nil)
|
|
92
|
+
def self.create(id, xml_path = nil, idempotency_key: nil, nuid: nil)
|
|
87
93
|
result = AtlasRb::Mash.new(JSON.parse(
|
|
88
|
-
connection({ collection_id: id },
|
|
94
|
+
connection({ collection_id: id }, nuid, idempotency_key: idempotency_key).post(ROUTE)&.body
|
|
89
95
|
))["work"]
|
|
90
96
|
return result unless xml_path.present?
|
|
91
97
|
|
|
@@ -166,15 +172,18 @@ module AtlasRb
|
|
|
166
172
|
#
|
|
167
173
|
# @param id [String] the Work ID.
|
|
168
174
|
# @param xml_path [String] path to a MODS XML file on disk.
|
|
175
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
176
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
177
|
+
# tokens still resolve without it.
|
|
169
178
|
# @return [Hash] the parsed JSON response from the patch.
|
|
170
179
|
#
|
|
171
180
|
# @example
|
|
172
181
|
# AtlasRb::Work.update("w-789", "/tmp/work-mods.xml")
|
|
173
|
-
def self.update(id, xml_path)
|
|
182
|
+
def self.update(id, xml_path, nuid: nil)
|
|
174
183
|
payload = { binary: Faraday::Multipart::FilePart.new(File.open(xml_path),
|
|
175
184
|
"application/xml",
|
|
176
185
|
File.basename(xml_path)) }
|
|
177
|
-
AtlasRb::Mash.new(JSON.parse(multipart(
|
|
186
|
+
AtlasRb::Mash.new(JSON.parse(multipart(nuid).patch(ROUTE + id, payload)&.body))
|
|
178
187
|
end
|
|
179
188
|
|
|
180
189
|
# Patch individual descriptive-metadata fields without uploading a
|
|
@@ -187,12 +196,15 @@ module AtlasRb
|
|
|
187
196
|
#
|
|
188
197
|
# @param id [String] the Work ID.
|
|
189
198
|
# @param values [Hash] field-level metadata updates.
|
|
199
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
200
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
201
|
+
# tokens still resolve without it.
|
|
190
202
|
# @return [Hash] the parsed JSON response.
|
|
191
203
|
#
|
|
192
204
|
# @example
|
|
193
205
|
# AtlasRb::Work.metadata("w-789", title: "Revised Title")
|
|
194
|
-
def self.metadata(id, values)
|
|
195
|
-
AtlasRb::Mash.new(JSON.parse(connection({ metadata: values }).patch(ROUTE + id)&.body))
|
|
206
|
+
def self.metadata(id, values, nuid: nil)
|
|
207
|
+
AtlasRb::Mash.new(JSON.parse(connection({ metadata: values }, nuid).patch(ROUTE + id)&.body))
|
|
196
208
|
end
|
|
197
209
|
|
|
198
210
|
# Attach the three thumbnail/preview Delegate URIs to a Work.
|
|
@@ -208,6 +220,9 @@ module AtlasRb
|
|
|
208
220
|
# @param thumbnail [String, nil] IIIF URI for the ~85² thumbnail.
|
|
209
221
|
# @param thumbnail_2x [String, nil] IIIF URI for the ~170² 2x thumbnail.
|
|
210
222
|
# @param preview [String, nil] IIIF URI for the ~500w preview image.
|
|
223
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
224
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
225
|
+
# tokens still resolve without it.
|
|
211
226
|
# @return [AtlasRb::Mash] the parsed JSON response.
|
|
212
227
|
#
|
|
213
228
|
# @example
|
|
@@ -217,10 +232,10 @@ module AtlasRb
|
|
|
217
232
|
# thumbnail_2x: "https://iiif.example.edu/iiif/3/abc.jp2/full/!170,170/0/default.jpg",
|
|
218
233
|
# preview: "https://iiif.example.edu/iiif/3/abc.jp2/full/500,/0/default.jpg"
|
|
219
234
|
# )
|
|
220
|
-
def self.set_thumbnails(id, thumbnail: nil, thumbnail_2x: nil, preview: nil)
|
|
235
|
+
def self.set_thumbnails(id, thumbnail: nil, thumbnail_2x: nil, preview: nil, nuid: nil)
|
|
221
236
|
body = { thumbnail: thumbnail, thumbnail_2x: thumbnail_2x, preview: preview }.compact
|
|
222
237
|
AtlasRb::Mash.new(JSON.parse(
|
|
223
|
-
connection({}).patch(ROUTE + id + '/thumbnails', JSON.dump(body))&.body
|
|
238
|
+
connection({}, nuid).patch(ROUTE + id + '/thumbnails', JSON.dump(body))&.body
|
|
224
239
|
))
|
|
225
240
|
end
|
|
226
241
|
|
|
@@ -237,6 +252,9 @@ module AtlasRb
|
|
|
237
252
|
# @param small [String, nil] IIIF URI for the small derivative.
|
|
238
253
|
# @param medium [String, nil] IIIF URI for the medium derivative.
|
|
239
254
|
# @param large [String, nil] IIIF URI for the large derivative.
|
|
255
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
256
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
257
|
+
# tokens still resolve without it.
|
|
240
258
|
# @return [AtlasRb::Mash] the parsed JSON response.
|
|
241
259
|
#
|
|
242
260
|
# @example
|
|
@@ -246,10 +264,10 @@ module AtlasRb
|
|
|
246
264
|
# medium: "https://iiif.example.edu/iiif/3/abc.jp2/full/1600,/0/default.jpg",
|
|
247
265
|
# large: "https://iiif.example.edu/iiif/3/abc.jp2/full/full/0/default.jpg"
|
|
248
266
|
# )
|
|
249
|
-
def self.set_image_derivatives(id, small: nil, medium: nil, large: nil)
|
|
267
|
+
def self.set_image_derivatives(id, small: nil, medium: nil, large: nil, nuid: nil)
|
|
250
268
|
body = { small: small, medium: medium, large: large }.compact
|
|
251
269
|
AtlasRb::Mash.new(JSON.parse(
|
|
252
|
-
connection({}).patch(ROUTE + id + '/image_derivatives', JSON.dump(body))&.body
|
|
270
|
+
connection({}, nuid).patch(ROUTE + id + '/image_derivatives', JSON.dump(body))&.body
|
|
253
271
|
))
|
|
254
272
|
end
|
|
255
273
|
|
|
@@ -263,13 +281,16 @@ module AtlasRb
|
|
|
263
281
|
# schema.
|
|
264
282
|
#
|
|
265
283
|
# @param id [String] the Work ID.
|
|
284
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
285
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
286
|
+
# tokens still resolve without it.
|
|
266
287
|
# @return [Array<AtlasRb::Mash>] the listing from `GET /works/<id>/assets`,
|
|
267
288
|
# one entry per attached asset.
|
|
268
289
|
#
|
|
269
290
|
# @example
|
|
270
291
|
# AtlasRb::Work.assets("w-789").each { |a| puts a.label }
|
|
271
|
-
def self.assets(id)
|
|
272
|
-
JSON.parse(connection({}).get(ROUTE + id + '/assets')&.body).map { |entry| AtlasRb::Mash.new(entry) }
|
|
292
|
+
def self.assets(id, nuid: nil)
|
|
293
|
+
JSON.parse(connection({}, nuid).get(ROUTE + id + '/assets')&.body).map { |entry| AtlasRb::Mash.new(entry) }
|
|
273
294
|
end
|
|
274
295
|
|
|
275
296
|
# Fetch the Work's MODS representation in the requested format.
|
|
@@ -277,13 +298,16 @@ module AtlasRb
|
|
|
277
298
|
# @param id [String] the Work ID.
|
|
278
299
|
# @param kind [String, nil] one of `"json"` (default), `"html"`, or
|
|
279
300
|
# `"xml"`.
|
|
301
|
+
# @param nuid [String, nil] optional acting user's NUID, forwarded as the
|
|
302
|
+
# `User:` header. Required for cerberus-token requests; legacy bearer
|
|
303
|
+
# tokens still resolve without it.
|
|
280
304
|
# @return [String] the raw response body in the requested format.
|
|
281
305
|
#
|
|
282
306
|
# @example
|
|
283
307
|
# AtlasRb::Work.mods("w-789", "html")
|
|
284
|
-
def self.mods(id, kind = nil)
|
|
308
|
+
def self.mods(id, kind = nil, nuid: nil)
|
|
285
309
|
# json default, html, xml
|
|
286
|
-
connection({}).get(
|
|
310
|
+
connection({}, nuid).get(
|
|
287
311
|
ROUTE + id + '/mods' + (kind.present? ? ".#{kind}" : '')
|
|
288
312
|
)&.body
|
|
289
313
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: atlas_rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.99
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David Cliff
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-05-
|
|
11
|
+
date: 2026-05-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|