Repository navigation
Allow use of the jobs_with_files endpoint in ADT - #36
Merged
Merged
Conversation
These changes are minor updates required to use the jobs_with_files endpoint in an upcoming change to aspace-data-tools. Essentially, this PR adds a way to use that endpoint via a new post_multipart() function. A simple test for the function is included.
kspurgin
approved these changes
Oct 5, 2026
Contributor
|
This looks ok to me, but I have pretty limited experience with this codebase. @mark-cooper - Do you also want to take a look before this is merged? |
mark-cooper
self-requested a review
October 5, 2026 21:25
Member
|
😎 I've just a few changes to request: diff --git a/lib/archivesspace/client/client.rb b/lib/archivesspace/client/client.rb
index 20723ac..e14a106 100644
--- a/lib/archivesspace/client/client.rb
+++ b/lib/archivesspace/client/client.rb
@@ -33,9 +33,10 @@ module ArchivesSpace
request "POST", path, {body: payload.to_json, query: params}
end
- # Allow passing a file object (multipart = true, no calling .to_json)
+ # Allow passing a file object (multipart = true)
def post_multipart(path, payload, params = {})
- request "POST", path, {body: payload, query: params, multipart: true}
+ body = payload.transform_values { |v| v.is_a?(Hash) ? v.to_json : v }
+ request "POST", path, {body: body, query: params, multipart: true}
end
def put(path, payload, params = {})
@@ -81,11 +82,7 @@ module ArchivesSpace
def request(method, path, options = {})
sleep config.throttle
options = options.dup
- # Avoid overwriting all the headers (needed for file uploads)
- if token
- options[:headers] = (options[:headers] || {})
- .merge(TOKEN => token)
- end
+ options[:headers] = options.fetch(:headers, {}).merge(TOKEN => token) if token
Request.new(context, config, method, path, options).execute
end
end
diff --git a/lib/archivesspace/client/request.rb b/lib/archivesspace/client/request.rb
index 0187dff..779c784 100644
--- a/lib/archivesspace/client/request.rb
+++ b/lib/archivesspace/client/request.rb
@@ -16,7 +16,7 @@ module ArchivesSpace
@options = options.dup
- @options[:headers] = DEFAULT_HEADERS.merge(@options[:headers] || {})
+ @options[:headers] = DEFAULT_HEADERS.merge(@options.fetch(:headers, {}))
@options[:headers].delete("Content-Type") if @options[:multipart]
@options[:headers]["User-Agent"] = "#{Client::NAME}/#{Client::VERSION}"
diff --git a/spec/archivesspace/client_spec.rb b/spec/archivesspace/client_spec.rb
index 35561d7..93dffcf 100644
--- a/spec/archivesspace/client_spec.rb
+++ b/spec/archivesspace/client_spec.rb
@@ -222,7 +222,7 @@ describe ArchivesSpace::Client do
.to_return(status: 200, body: "{}", headers: {"Content-Type" => "application/json"})
File.open(__FILE__) do |file|
client.repository(2) do
- client.post_multipart("jobs_with_files", {job: {jsonmodel_type: "job"}.to_json, files: [file]})
+ client.post_multipart("jobs_with_files", {job: {jsonmodel_type: "job"}, files: [file]})
end
end
expect(stub).to have_been_requestedBump the gemspec min version of httparty to "0.16": Add a small example to the README.md. |
This commit includes the few requested changes and a short example of how to use the uploader and check the job status. It was a little too long for the README, so it's a separate thing under examples/. Updates required httparty gem version to 0.16 to ensure support for multipart uploads.
Contributor
Author
|
Thanks @mark-cooper! I've made the requested revisions and added an example of the multipart uploader, i.e. how to set up calls to post_multipart(). It's in its own file under |
mark-cooper
approved these changes
Oct 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
These changes are minor updates required to use the jobs_with_files endpoint in an upcoming change to aspace-data-tools. Essentially, this PR adds a way to use that endpoint via a new post_multipart() function. A simple test for the function is included.