archivesspace-client 0.6.0 → 0.7.0

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: 5c792727aefb570967d0bd3d69330cc609275d0553cfb439392330bcab2af638
4
- data.tar.gz: c33eb46a9194ade5465a64c0bce98b9f5796f22ef097f0e628e171659437a03f
3
+ metadata.gz: b567aa6c6f40826a102d43a028600f562d8842f791d8f26269668eaf23757c95
4
+ data.tar.gz: 318036e1c02449bf25265431d44baa2d765970f782cc836daa9db25bd2ca3f89
5
5
  SHA512:
6
- metadata.gz: afcb7ffbf95842a8c62a7e1a8616c98f3a5113cfdedd8a47d069cde7a495604a02476f3cbfe75a9192fc14772738da22ea61f1c47682e6d094eaf590070ee722
7
- data.tar.gz: e8ea7debe60ac9eaf21b4e413703e12c322f935842e54488fcde08806b1babecba1bf91e1ad4e6cf9df53447416b23267f27a0cdc514244db1510b41707a46ac
6
+ metadata.gz: 10bae2e2c595663d40ec0629444639acd5c3750ea866a3dc0623152a5598818b33d2d511346d702759cbab9948941fc7fe9b4f0208cabd0c17cbee66d3b52ea3
7
+ data.tar.gz: 000440d2cfeed3c329c08b37040a3b1be15189f41d69afc0ff54e9426915c70165122d320687ad32eae1fc7277fa1321bc22b8cc26e480b8cb166bc03b213868
data/README.md CHANGED
@@ -4,22 +4,22 @@ Interact with ArchivesSpace via the API.
4
4
 
5
5
  <!-- TOC start (generated with https://github.com/derlin/bitdowntoc) -->
6
6
 
7
- * [Installation](#installation)
8
- * [Usage](#usage)
9
- * [Configuring a client](#configuring-a-client)
10
- * [Default configuration](#default-configuration)
11
- * [Custom configuration, on the fly](#custom-configuration-on-the-fly)
12
- * [Custom configuration, stored for use with CLI or console](#custom-configuration-stored-for-use-with-cli-or-console)
13
- * [Making basic requests](#making-basic-requests)
14
- * [Setting a repository context](#setting-a-repository-context)
15
- * [Templates](#templates)
16
- * [CLI](#cli)
17
- * [Console usage](#console-usage)
18
- * [Development](#development)
19
- * [Publishing](#publishing)
20
- * [Changelog](#changelog)
21
- * [Contributing](#contributing)
22
- * [License](#license)
7
+ - [Installation](#installation)
8
+ - [Usage](#usage)
9
+ - [Configuring a client](#configuring-a-client)
10
+ - [Default configuration](#default-configuration)
11
+ - [Custom configuration, on the fly](#custom-configuration-on-the-fly)
12
+ - [Custom configuration, stored for use with CLI or console](#custom-configuration-stored-for-use-with-cli-or-console)
13
+ - [Making basic requests](#making-basic-requests)
14
+ - [Setting a repository context](#setting-a-repository-context)
15
+ - [Templates](#templates)
16
+ - [CLI](#cli)
17
+ - [Console usage](#console-usage)
18
+ - [Development](#development)
19
+ - [Publishing](#publishing)
20
+ - [Changelog](#changelog)
21
+ - [Contributing](#contributing)
22
+ - [License](#license)
23
23
 
24
24
  <!-- TOC end -->
25
25
 
@@ -266,28 +266,33 @@ main/master branch a new release will be built and published.
266
266
 
267
267
  ## Changelog
268
268
 
269
+ ### 0.7.0
270
+
271
+ - Add support for multipart POST requests, including file uploads to the
272
+ `jobs_with_files` endpoint.
273
+
269
274
  ### 0.6.0
270
275
 
271
- * Support global scope within a nested context. This makes it much
276
+ - Support global scope within a nested context. This makes it much
272
277
  more ergonomic to request uris within a repository context.
273
278
 
274
279
  ### 0.5.1
275
280
 
276
- * Fix: prevent caller options passed to request from being mutated.
281
+ - Fix: prevent caller options passed to request from being mutated.
277
282
 
278
283
  ### 0.5.0
279
284
 
280
285
  Breaking changes:
281
286
 
282
- * Removed the `base_repo` configuration option. Use `client.repository(id)` to
287
+ - Removed the `base_repo` configuration option. Use `client.repository(id)` to
283
288
  scope requests to a repository instead, either persistently or with a
284
289
  block that auto-restores the previous scope.
285
- * `client.repository(id)` with a block now saves and restores the previous
290
+ - `client.repository(id)` with a block now saves and restores the previous
286
291
  context (including when nested or when the block raises), instead of always
287
292
  resetting to the global scope.
288
- * Login failure now raises `ArchivesSpace::AuthenticationError` (was
293
+ - Login failure now raises `ArchivesSpace::AuthenticationError` (was
289
294
  `ConnectionError`). `ConnectionError` has been removed.
290
- * `Client.new` raises `ArchivesSpace::ConfigurationError` (was `RuntimeError`)
295
+ - `Client.new` raises `ArchivesSpace::ConfigurationError` (was `RuntimeError`)
291
296
  when given a non-`Configuration` argument.
292
297
 
293
298
  ## Contributing
@@ -29,8 +29,8 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency "vcr", "~> 6.3"
30
30
  spec.add_development_dependency "webmock", "~> 3.24"
31
31
 
32
- spec.add_dependency "dry-cli", "~> 0.7"
33
- spec.add_dependency "httparty", "~> 0.14"
32
+ spec.add_dependency "dry-cli", "< 2.0"
33
+ spec.add_dependency "httparty", "~> 0.16"
34
34
  spec.add_dependency "json", "~> 2.0"
35
35
  spec.add_dependency "jbuilder", "~> 2.12"
36
36
  end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
+ require "archivesspace/client"
5
+
6
+ # usage: ruby examples/upload_ead.rb path/to/ead.xml
7
+ path = ARGV.fetch(0) { abort "usage: ruby #{$PROGRAM_NAME} path/to/ead.xml" }
8
+
9
+ # official sandbox, config boilerplate
10
+ config = ArchivesSpace::Configuration.new(
11
+ {
12
+ base_uri: "https://test.archivesspace.org/staff/api",
13
+ username: "admin",
14
+ password: "admin",
15
+ page_size: 50,
16
+ throttle: 0,
17
+ verify_ssl: false
18
+ }
19
+ )
20
+
21
+ client = ArchivesSpace::Client.new(config).login
22
+
23
+ job = {
24
+ jsonmodel_type: "job",
25
+ job: {
26
+ jsonmodel_type: "import_job",
27
+ import_type: "ead_xml",
28
+ filenames: [File.basename(path)]
29
+ }
30
+ }
31
+
32
+ client.repository 2 do
33
+ response = File.open(path) do |file|
34
+ client.post_multipart("jobs_with_files", {job: job.to_json, files: [file]})
35
+ end
36
+ abort "upload failed (#{response.status_code}): #{response.body}" unless
37
+ response.status_code == 200
38
+
39
+ job_id = response.parsed["id"]
40
+ puts "created import job #{job_id}"
41
+
42
+ # poll until the import finishes, but not for more than ~60s
43
+ status = nil
44
+ 30.times do
45
+ status = client.get("jobs/#{job_id}").parsed["status"]
46
+ puts "status: #{status}"
47
+ break if %w[completed failed canceled].include?(status)
48
+
49
+ sleep 2
50
+ end
51
+
52
+ puts client.get("jobs/#{job_id}/log").body
53
+ end
@@ -33,6 +33,12 @@ module ArchivesSpace
33
33
  request "POST", path, {body: payload.to_json, query: params}
34
34
  end
35
35
 
36
+ # Allow passing a file object (multipart = true)
37
+ def post_multipart(path, payload, params = {})
38
+ body = payload.transform_values { |v| v.is_a?(Hash) ? v.to_json : v }
39
+ request "POST", path, {body: body, query: params, multipart: true}
40
+ end
41
+
36
42
  def put(path, payload, params = {})
37
43
  request "PUT", path, {body: payload.to_json, query: params}
38
44
  end
@@ -76,7 +82,7 @@ module ArchivesSpace
76
82
  def request(method, path, options = {})
77
83
  sleep config.throttle
78
84
  options = options.dup
79
- options[:headers] = {TOKEN => token} if token
85
+ options[:headers] = options.fetch(:headers, {}).merge(TOKEN => token) if token
80
86
  Request.new(context, config, method, path, options).execute
81
87
  end
82
88
  end
@@ -17,6 +17,7 @@ module ArchivesSpace
17
17
  @options = options.dup
18
18
 
19
19
  @options[:headers] = DEFAULT_HEADERS.merge(@options.fetch(:headers, {}))
20
+ @options[:headers].delete("Content-Type") if @options[:multipart]
20
21
  @options[:headers]["User-Agent"] = "#{Client::NAME}/#{Client::VERSION}"
21
22
 
22
23
  @options[:verify] = config.verify_ssl
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ArchivesSpace
4
4
  class Client
5
- VERSION = "0.6.0"
5
+ VERSION = "0.7.0"
6
6
  end
7
7
  end
@@ -209,6 +209,24 @@ describe ArchivesSpace::Client do
209
209
  client.get("resources", opts)
210
210
  expect(opts).to eq(caller_opts)
211
211
  end
212
+
213
+ it "posts a file (as multipart form data) with session token" do
214
+ client.token = "abc123"
215
+ stub = stub_request(:post, "#{DEFAULT_BASE_URI}/repositories/2/jobs_with_files")
216
+ .with { |req|
217
+ req.headers["Content-Type"].start_with?("multipart/form-data; boundary=") &&
218
+ req.headers["X-Archivesspace-Session"] == "abc123" &&
219
+ req.body.include?('name="files[]"; filename="client_spec.rb"') &&
220
+ req.body.include?('name="job"')
221
+ }
222
+ .to_return(status: 200, body: "{}", headers: {"Content-Type" => "application/json"})
223
+ File.open(__FILE__) do |file|
224
+ client.repository(2) do
225
+ client.post_multipart("jobs_with_files", {job: {jsonmodel_type: "job"}, files: [file]})
226
+ end
227
+ end
228
+ expect(stub).to have_been_requested
229
+ end
212
230
  end
213
231
 
214
232
  describe "URL construction" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: archivesspace-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Cooper
@@ -145,30 +145,30 @@ dependencies:
145
145
  name: dry-cli
146
146
  requirement: !ruby/object:Gem::Requirement
147
147
  requirements:
148
- - - "~>"
148
+ - - "<"
149
149
  - !ruby/object:Gem::Version
150
- version: '0.7'
150
+ version: '2.0'
151
151
  type: :runtime
152
152
  prerelease: false
153
153
  version_requirements: !ruby/object:Gem::Requirement
154
154
  requirements:
155
- - - "~>"
155
+ - - "<"
156
156
  - !ruby/object:Gem::Version
157
- version: '0.7'
157
+ version: '2.0'
158
158
  - !ruby/object:Gem::Dependency
159
159
  name: httparty
160
160
  requirement: !ruby/object:Gem::Requirement
161
161
  requirements:
162
162
  - - "~>"
163
163
  - !ruby/object:Gem::Version
164
- version: '0.14'
164
+ version: '0.16'
165
165
  type: :runtime
166
166
  prerelease: false
167
167
  version_requirements: !ruby/object:Gem::Requirement
168
168
  requirements:
169
169
  - - "~>"
170
170
  - !ruby/object:Gem::Version
171
- version: '0.14'
171
+ version: '0.16'
172
172
  - !ruby/object:Gem::Dependency
173
173
  name: json
174
174
  requirement: !ruby/object:Gem::Requirement
@@ -223,6 +223,7 @@ files:
223
223
  - examples/templates.rb
224
224
  - examples/test_connection.rb
225
225
  - examples/update_feed.rb
226
+ - examples/upload_ead.rb
226
227
  - examples/user_groups.rb
227
228
  - exe/asclient
228
229
  - features/exec.feature
@@ -269,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
269
270
  - !ruby/object:Gem::Version
270
271
  version: '0'
271
272
  requirements: []
272
- rubygems_version: 4.0.11
273
+ rubygems_version: 4.0.22
273
274
  specification_version: 4
274
275
  summary: Interact with ArchivesSpace via the API.
275
276
  test_files: []