Skip to content

Allow use of the jobs_with_files endpoint in ADT - #36

Merged
mark-cooper merged 2 commits into
masterfrom
feat/upload-files
Oct 6, 2026
Merged

mark-cooper merged 2 commits into
masterfrom
feat/upload-files

Conversation

@wsshaw

@wsshaw wsshaw commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

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.

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.
@wsshaw
wsshaw requested a review from kspurgin October 5, 2026 16:52
@kspurgin

kspurgin commented Oct 5, 2026

Copy link
Copy Markdown
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
mark-cooper self-requested a review October 5, 2026 21:25
@mark-cooper

Copy link
Copy Markdown
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_requested

Bump the gemspec min version of httparty to "0.16":
https://github.com/jnunemaker/httparty/blob/main/Changelog.md#0160

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.
@wsshaw

wsshaw commented Oct 6, 2026

Copy link
Copy Markdown
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 examples/ because it takes some setup that felt too long for the README.

@mark-cooper
mark-cooper merged commit 9934e02 into master Oct 6, 2026
2 checks passed
@mark-cooper
mark-cooper deleted the feat/upload-files branch October 6, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants