archivesspace-client 0.1.12 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +5 -4
- data/.github/workflows/publish.yml +1 -1
- data/.rubocop.yml +4 -0
- data/.ruby-version +1 -0
- data/Gemfile +1 -1
- data/README.md +10 -5
- data/Rakefile +5 -3
- data/archivesspace-client.gemspec +25 -29
- data/examples/export.rb +11 -11
- data/examples/password_reset.rb +6 -6
- data/examples/repo_and_user.rb +21 -21
- data/examples/templates.rb +18 -0
- data/examples/test_connection.rb +8 -8
- data/examples/user_groups.rb +14 -14
- data/exe/asclient +2 -2
- data/features/support/setup.rb +3 -3
- data/lib/archivesspace/client/cli/exec.rb +18 -18
- data/lib/archivesspace/client/cli/version.rb +1 -1
- data/lib/archivesspace/client/cli.rb +3 -3
- data/lib/archivesspace/client/client.rb +13 -11
- data/lib/archivesspace/client/configuration.rb +8 -7
- data/lib/archivesspace/client/pagination.rb +3 -3
- data/lib/archivesspace/client/request.rb +13 -11
- data/lib/archivesspace/client/response.rb +5 -5
- data/lib/archivesspace/client/task.rb +15 -15
- data/lib/archivesspace/client/template.rb +53 -10
- data/lib/archivesspace/client/templates/resource.json.jbuilder +7 -0
- data/lib/archivesspace/client/version.rb +1 -1
- data/lib/archivesspace/client.rb +19 -18
- data/spec/archivesspace/client_spec.rb +36 -38
- data/spec/archivesspace/configuration_spec.rb +8 -8
- data/spec/archivesspace/templates_spec.rb +25 -11
- data/spec/fixtures/cassettes/backend_version.yml +35 -24
- data/spec/spec_helper.rb +8 -8
- metadata +46 -92
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4aa54400871b3c9e356f6750ba9aa9fbba6111869ad57bcfe548334296fbf146
|
4
|
+
data.tar.gz: 8fede8b9a6e86517ebea6fa8f3ed0c5e3cb3b18966137a0d7133453bf5f67d1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0f5d93549e1357eb6f6a1470faeeb4b36dfc1f43676ffed68c148298c23f8a4263ac88befebd4d85ba54cdd0a2b9bc69c53eac8a038aa5ce18962c57cf8afaf
|
7
|
+
data.tar.gz: 71cc7ac848b1c60744f122156706e88457da232e08184cff9c2b53fa32871f585743de9c1d87b26a96105f8c98d72b7221b5dfca8bcc828a3b50845089901a1b
|
data/.github/workflows/ci.yml
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
name: CI
|
2
2
|
on: [pull_request]
|
3
3
|
|
4
|
-
# TODO: add linters (rubocop)
|
5
|
-
|
6
4
|
jobs:
|
7
5
|
tests:
|
8
6
|
name: Tests
|
@@ -15,8 +13,11 @@ jobs:
|
|
15
13
|
uses: ruby/setup-ruby@v1
|
16
14
|
with:
|
17
15
|
bundler-cache: true
|
18
|
-
|
16
|
+
|
17
|
+
- name: Lint
|
18
|
+
run: |
|
19
|
+
bundle exec standardrb
|
19
20
|
|
20
21
|
- name: Run tests
|
21
22
|
run: |
|
22
|
-
bundle exec
|
23
|
+
bundle exec rspec
|
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.2
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -45,6 +45,7 @@ config = ArchivesSpace::Configuration.new({
|
|
45
45
|
page_size: 50,
|
46
46
|
throttle: 0,
|
47
47
|
verify_ssl: false,
|
48
|
+
timeout: 60
|
48
49
|
})
|
49
50
|
|
50
51
|
client = ArchivesSpace::Client.new(config).login
|
@@ -73,7 +74,8 @@ user = client.all('users').find { |user| user["username"] == "jdoe" }
|
|
73
74
|
user = client.users.find { |user| user["username"] == "jdoe" }
|
74
75
|
```
|
75
76
|
|
76
|
-
See `
|
77
|
+
See `pagination.rb` for endpoints that support record type methods such as
|
78
|
+
`client.digital_objects` etc.
|
77
79
|
|
78
80
|
**Setting a repository context**
|
79
81
|
|
@@ -93,11 +95,11 @@ client.use_global_repository
|
|
93
95
|
|
94
96
|
Templates are an optional feature that can help simplify the effort of creating
|
95
97
|
json payloads for ArchivesSpace. Rather than construct the json programatically
|
96
|
-
according to the schemas a
|
97
|
-
|
98
|
+
according to the schemas a template can be used to generate payloads instead which
|
99
|
+
are transformed to json automatically. There are a small number of
|
98
100
|
templates provided with the client, but you can create your own and access them
|
99
101
|
by setting the `ARCHIVESSPACE_CLIENT_TEMPLATES_PATH` envvar. A particularly simple
|
100
|
-
template might look like:
|
102
|
+
`erb` template might look like:
|
101
103
|
|
102
104
|
```erb
|
103
105
|
{
|
@@ -113,11 +115,13 @@ assembling the payload. To process a template:
|
|
113
115
|
|
114
116
|
```ruby
|
115
117
|
data = { repo_code: 'ABC', name: 'ABC Archive', agent_contact_name: 'ABC Admin' }
|
116
|
-
json = ArchivesSpace::Template.process(
|
118
|
+
json = ArchivesSpace::Template.process("repository_with_agent.json.erb", data)
|
117
119
|
response = client.post('/repositories/with_agent', json)
|
118
120
|
puts response.result.success? ? '=)' : '=('
|
119
121
|
```
|
120
122
|
|
123
|
+
To view available templates use: `ArchivesSpace::Template.list`
|
124
|
+
|
121
125
|
## CLI
|
122
126
|
|
123
127
|
Create an `~/.asclientrc` file with a json version of the client configuration:
|
@@ -130,6 +134,7 @@ Create an `~/.asclientrc` file with a json version of the client configuration:
|
|
130
134
|
"password": "123456",
|
131
135
|
"page_size": 50,
|
132
136
|
"throttle": 0,
|
137
|
+
"timeout": 60,
|
133
138
|
"verify_ssl": false
|
134
139
|
}
|
135
140
|
```
|
data/Rakefile
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "bundler/gem_tasks"
|
4
4
|
|
5
|
-
require
|
5
|
+
require "rspec/core/rake_task"
|
6
6
|
RSpec::Core::RakeTask.new(:spec)
|
7
7
|
|
8
8
|
# require 'rubocop/rake_task'
|
9
9
|
# RuboCop::RakeTask.new
|
10
10
|
|
11
|
-
require
|
11
|
+
require "cucumber/rake/task"
|
12
12
|
Cucumber::Rake::Task.new
|
13
13
|
|
14
|
+
require "standard/rake"
|
15
|
+
|
14
16
|
task default: %i[spec cucumber]
|
15
17
|
|
16
18
|
task :version do
|
@@ -1,38 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
lib = File.expand_path(
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require
|
5
|
+
require "archivesspace/client/version"
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name
|
9
|
-
spec.version
|
10
|
-
spec.authors
|
11
|
-
spec.email
|
12
|
-
spec.summary
|
13
|
-
spec.description
|
14
|
-
spec.homepage
|
15
|
-
spec.license
|
8
|
+
spec.name = "archivesspace-client"
|
9
|
+
spec.version = ArchivesSpace::Client::VERSION
|
10
|
+
spec.authors = ["Mark Cooper"]
|
11
|
+
spec.email = ["mark.c.cooper@outlook.com"]
|
12
|
+
spec.summary = "Interact with ArchivesSpace via the API."
|
13
|
+
spec.description = "Interact with ArchivesSpace via the API."
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
16
|
|
17
|
-
spec.files
|
18
|
-
spec.executables
|
19
|
-
spec.
|
20
|
-
spec.require_paths = ['lib']
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
21
20
|
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency 'rspec', '3.6.0'
|
30
|
-
spec.add_development_dependency 'rubocop'
|
31
|
-
spec.add_development_dependency 'vcr', '3.0.3'
|
32
|
-
spec.add_development_dependency 'webmock', '3.0.1'
|
21
|
+
spec.add_development_dependency "aruba", "~> 2.0"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "3.6.0"
|
24
|
+
spec.add_development_dependency "rubocop", "1.56"
|
25
|
+
spec.add_development_dependency "standard", "1.31.0"
|
26
|
+
spec.add_development_dependency "vcr", "6.2.0"
|
27
|
+
spec.add_development_dependency "webmock", "3.19.1"
|
33
28
|
|
34
|
-
spec.add_dependency
|
35
|
-
spec.add_dependency
|
36
|
-
spec.add_dependency
|
37
|
-
spec.add_dependency
|
29
|
+
spec.add_dependency "dry-cli", "~> 0.7"
|
30
|
+
spec.add_dependency "httparty", "~> 0.14"
|
31
|
+
spec.add_dependency "json", "~> 2.0"
|
32
|
+
spec.add_dependency "nokogiri", "~> 1.10"
|
33
|
+
spec.add_dependency "jbuilder", "~> 2.11.5"
|
38
34
|
end
|
data/examples/export.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
$LOAD_PATH.unshift File.expand_path(
|
4
|
-
require
|
5
|
-
require
|
3
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
4
|
+
require "awesome_print"
|
5
|
+
require "archivesspace/client"
|
6
6
|
|
7
7
|
# official sandbox
|
8
8
|
config = ArchivesSpace::Configuration.new(
|
9
9
|
{
|
10
|
-
base_uri:
|
11
|
-
base_repo:
|
12
|
-
username:
|
13
|
-
password:
|
10
|
+
base_uri: "http://test.archivesspace.org/staff/api",
|
11
|
+
base_repo: "",
|
12
|
+
username: "admin",
|
13
|
+
password: "admin",
|
14
14
|
page_size: 50,
|
15
15
|
throttle: 0,
|
16
16
|
verify_ssl: false
|
@@ -19,15 +19,15 @@ config = ArchivesSpace::Configuration.new(
|
|
19
19
|
|
20
20
|
client = ArchivesSpace::Client.new(config).login
|
21
21
|
client.config.throttle = 0.5
|
22
|
-
client.config.base_repo =
|
22
|
+
client.config.base_repo = "repositories/2"
|
23
23
|
|
24
24
|
begin
|
25
25
|
# date -d '2021-02-01 00:00:00' +'%s' # 1612166400
|
26
|
-
client.resources(query: {
|
26
|
+
client.resources(query: {modified_since: "1612166400"}).each do |resource|
|
27
27
|
# for now we are just printing ...
|
28
28
|
# but you would actually write to a zip file or whatever
|
29
|
-
id
|
30
|
-
opts = {
|
29
|
+
id = resource["uri"].split("/")[-1]
|
30
|
+
opts = {include_unpublished: false}
|
31
31
|
response = client.get("resource_descriptions/#{id}.xml", opts)
|
32
32
|
puts Nokogiri::XML(response.body).to_xml
|
33
33
|
end
|
data/examples/password_reset.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
$LOAD_PATH.unshift File.expand_path(
|
4
|
-
require
|
5
|
-
require
|
3
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
4
|
+
require "awesome_print"
|
5
|
+
require "archivesspace/client"
|
6
6
|
|
7
|
-
username =
|
8
|
-
password =
|
7
|
+
username = "admin"
|
8
|
+
password = "admin"
|
9
9
|
|
10
10
|
# default client connection: localhost:8089, admin, admin
|
11
11
|
client = ArchivesSpace::Client.new.login
|
12
12
|
begin
|
13
13
|
puts client.password_reset(username, password).parsed
|
14
|
-
rescue
|
14
|
+
rescue => e
|
15
15
|
puts "Failed to update password for #{username},\n#{e.message}"
|
16
16
|
end
|
data/examples/repo_and_user.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
$LOAD_PATH.unshift File.expand_path(
|
4
|
-
require
|
5
|
-
require
|
3
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
4
|
+
require "awesome_print"
|
5
|
+
require "archivesspace/client"
|
6
6
|
|
7
7
|
# official sandbox
|
8
8
|
config = ArchivesSpace::Configuration.new(
|
9
9
|
{
|
10
|
-
base_uri:
|
11
|
-
base_repo:
|
12
|
-
username:
|
13
|
-
password:
|
10
|
+
base_uri: "http://sandbox.archivesspace.org/api",
|
11
|
+
base_repo: "",
|
12
|
+
username: "admin",
|
13
|
+
password: "admin",
|
14
14
|
page_size: 50,
|
15
15
|
throttle: 0,
|
16
16
|
verify_ssl: false
|
@@ -22,36 +22,36 @@ client = ArchivesSpace::Client.new(config).login
|
|
22
22
|
ap ArchivesSpace::Template.list # view available templates
|
23
23
|
|
24
24
|
repo_data = {
|
25
|
-
repo_code:
|
26
|
-
name:
|
27
|
-
agent_contact_name:
|
25
|
+
repo_code: "XYZ",
|
26
|
+
name: "XYZ Archive",
|
27
|
+
agent_contact_name: "XYZ Admin"
|
28
28
|
}
|
29
29
|
|
30
30
|
user_data = {
|
31
|
-
username:
|
32
|
-
name:
|
31
|
+
username: "lmessi",
|
32
|
+
name: "Lionel Messi",
|
33
33
|
is_admin: true
|
34
34
|
}
|
35
|
-
user_password =
|
35
|
+
user_password = "123456"
|
36
36
|
|
37
|
-
repository = ArchivesSpace::Template.process(
|
37
|
+
repository = ArchivesSpace::Template.process("repository_with_agent.json.erb", repo_data)
|
38
38
|
|
39
39
|
begin
|
40
|
-
response = client.post(
|
40
|
+
response = client.post("/repositories/with_agent", repository)
|
41
41
|
if response.result.success?
|
42
|
-
repository = client.repositories.find { |r| r[
|
42
|
+
repository = client.repositories.find { |r| r["repo_code"] == "XYZ" }
|
43
43
|
ap repository
|
44
|
-
ap client.delete(repository[
|
44
|
+
ap client.delete(repository["uri"])
|
45
45
|
else
|
46
46
|
ap response.parsed
|
47
47
|
end
|
48
48
|
|
49
|
-
user = ArchivesSpace::Template.process(
|
50
|
-
response = client.post(
|
49
|
+
user = ArchivesSpace::Template.process("user.json.erb", user_data)
|
50
|
+
response = client.post("users", user, {password: user_password})
|
51
51
|
if response.result.success?
|
52
|
-
user = client.users.find { |r| r[
|
52
|
+
user = client.users.find { |r| r["username"] == "lmessi" }
|
53
53
|
ap user
|
54
|
-
ap client.delete user[
|
54
|
+
ap client.delete user["uri"]
|
55
55
|
else
|
56
56
|
ap response.parsed
|
57
57
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
4
|
+
require "awesome_print"
|
5
|
+
require "archivesspace/client"
|
6
|
+
|
7
|
+
puts ArchivesSpace::Template.list
|
8
|
+
|
9
|
+
template = "repository_with_agent.json.erb"
|
10
|
+
user_data = {
|
11
|
+
username: "harrykane",
|
12
|
+
name: "Harry Kane",
|
13
|
+
is_admin: false
|
14
|
+
}
|
15
|
+
|
16
|
+
puts ArchivesSpace::Template.process(template, user_data)
|
17
|
+
# or, if you really want ...
|
18
|
+
puts ArchivesSpace::Template::Erb.new(template, user_data).process
|
data/examples/test_connection.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
$LOAD_PATH.unshift File.expand_path(
|
4
|
-
require
|
5
|
-
require
|
3
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
4
|
+
require "awesome_print"
|
5
|
+
require "archivesspace/client"
|
6
6
|
|
7
7
|
# official sandbox
|
8
8
|
config = ArchivesSpace::Configuration.new(
|
9
9
|
{
|
10
|
-
base_uri:
|
11
|
-
base_repo:
|
12
|
-
username:
|
13
|
-
password:
|
10
|
+
base_uri: "http://sandbox.archivesspace.org/api",
|
11
|
+
base_repo: "",
|
12
|
+
username: "admin",
|
13
|
+
password: "admin",
|
14
14
|
page_size: 50,
|
15
15
|
throttle: 0,
|
16
16
|
verify_ssl: false
|
@@ -18,4 +18,4 @@ config = ArchivesSpace::Configuration.new(
|
|
18
18
|
)
|
19
19
|
|
20
20
|
client = ArchivesSpace::Client.new(config).login
|
21
|
-
puts client.get(
|
21
|
+
puts client.get("version").body
|
data/examples/user_groups.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
$LOAD_PATH.unshift File.expand_path(
|
4
|
-
require
|
5
|
-
require
|
3
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
4
|
+
require "awesome_print"
|
5
|
+
require "archivesspace/client"
|
6
6
|
|
7
7
|
# official sandbox
|
8
8
|
config = ArchivesSpace::Configuration.new(
|
9
9
|
{
|
10
|
-
base_uri:
|
11
|
-
base_repo:
|
12
|
-
username:
|
13
|
-
password:
|
10
|
+
base_uri: "http://sandbox.archivesspace.org/api",
|
11
|
+
base_repo: "",
|
12
|
+
username: "admin",
|
13
|
+
password: "admin",
|
14
14
|
page_size: 50,
|
15
15
|
throttle: 0,
|
16
16
|
verify_ssl: false
|
@@ -20,23 +20,23 @@ config = ArchivesSpace::Configuration.new(
|
|
20
20
|
client = ArchivesSpace::Client.new(config).login
|
21
21
|
|
22
22
|
user_data = {
|
23
|
-
username:
|
24
|
-
name:
|
23
|
+
username: "bde",
|
24
|
+
name: "BDE",
|
25
25
|
is_admin: false
|
26
26
|
}
|
27
27
|
|
28
28
|
client.post(
|
29
|
-
|
30
|
-
ArchivesSpace::Template.process(
|
31
|
-
{
|
29
|
+
"users",
|
30
|
+
ArchivesSpace::Template.process("user.json.erb", user_data),
|
31
|
+
{password: "123456"}
|
32
32
|
)
|
33
33
|
|
34
34
|
users_with_roles = {
|
35
|
-
|
35
|
+
"bde" => ["repository-basic-data-entry"]
|
36
36
|
}
|
37
37
|
|
38
38
|
begin
|
39
|
-
client.config.base_repo =
|
39
|
+
client.config.base_repo = "repositories/2"
|
40
40
|
results = client.group_user_assignment users_with_roles
|
41
41
|
ap results.map(&:parsed)
|
42
42
|
rescue ArchivesSpace::RequestError => e
|
data/exe/asclient
CHANGED
data/features/support/setup.rb
CHANGED
@@ -5,37 +5,37 @@ module ArchivesSpace
|
|
5
5
|
module CLI
|
6
6
|
# ArchivesSpace::Client::CLI::Exec executes an API request
|
7
7
|
class Exec < Dry::CLI::Command
|
8
|
-
desc
|
8
|
+
desc "Execute an API request"
|
9
9
|
|
10
|
-
argument :type, required: true, values: %i[get post put delete], desc:
|
11
|
-
argument :path, required: true, desc:
|
10
|
+
argument :type, required: true, values: %i[get post put delete], desc: "API request type"
|
11
|
+
argument :path, required: true, desc: "API request path"
|
12
12
|
|
13
|
-
option
|
14
|
-
option
|
15
|
-
option
|
13
|
+
option :rid, type: :integer, default: nil, desc: "Repository id"
|
14
|
+
option :payload, type: :string, default: "{}", desc: "Data payload (json)"
|
15
|
+
option :params, type: :string, default: "{}", desc: "Params (json)"
|
16
16
|
|
17
17
|
example [
|
18
18
|
'exec get --rid 2 "resources/1"',
|
19
19
|
'exec get users --params \'{"query": {"page": 1}}\''
|
20
20
|
]
|
21
21
|
|
22
|
-
def call(type:, path:, rid: nil, payload:
|
22
|
+
def call(type:, path:, rid: nil, payload: "{}", params: "{}", **)
|
23
23
|
client = ArchivesSpace::Client::CLI.client
|
24
24
|
client.repository(rid) if rid
|
25
|
-
type
|
25
|
+
type = type.to_sym
|
26
26
|
payload = JSON.parse(payload, symbolize_names: true)
|
27
|
-
params
|
27
|
+
params = JSON.parse(params, symbolize_names: true)
|
28
28
|
|
29
29
|
response = case type
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
30
|
+
when :get
|
31
|
+
client.get(path, params)
|
32
|
+
when :post
|
33
|
+
client.post(path, payload, params)
|
34
|
+
when :put
|
35
|
+
client.put(path, payload, params)
|
36
|
+
when :delete
|
37
|
+
client.delete(path)
|
38
|
+
end
|
39
39
|
puts JSON.generate(response.parsed)
|
40
40
|
end
|
41
41
|
end
|
@@ -5,7 +5,7 @@ module ArchivesSpace
|
|
5
5
|
module CLI
|
6
6
|
# ArchivesSpace::Client::CLI::Version prints version
|
7
7
|
class Version < Dry::CLI::Command
|
8
|
-
desc
|
8
|
+
desc "Print ArchivesSpace Client version"
|
9
9
|
|
10
10
|
def call(*)
|
11
11
|
puts ArchivesSpace::Client::VERSION
|
@@ -11,14 +11,14 @@ module ArchivesSpace
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.find_config
|
14
|
-
config = ENV.fetch(
|
14
|
+
config = ENV.fetch("ASCLIENT_CFG", File.join(ENV["HOME"], ".asclientrc"))
|
15
15
|
raise "Unable to find asclient configuration file at: #{config}" unless File.file?(config)
|
16
16
|
|
17
17
|
JSON.parse(File.read(config), symbolize_names: true)
|
18
18
|
end
|
19
19
|
|
20
|
-
register
|
21
|
-
register
|
20
|
+
register "exec", Exec, aliases: ["e", "-e"]
|
21
|
+
register "version", Version, aliases: ["v", "-v", "--version"]
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -5,33 +5,35 @@ module ArchivesSpace
|
|
5
5
|
include Pagination
|
6
6
|
include Task
|
7
7
|
attr_accessor :token
|
8
|
-
attr_reader
|
8
|
+
attr_reader :config
|
9
|
+
|
10
|
+
NAME = "ArchivesSpaceClient"
|
9
11
|
|
10
12
|
def initialize(config = Configuration.new)
|
11
|
-
raise
|
13
|
+
raise "Invalid configuration object" unless config.is_a? ArchivesSpace::Configuration
|
12
14
|
|
13
15
|
@config = config
|
14
|
-
@token
|
16
|
+
@token = nil
|
15
17
|
end
|
16
18
|
|
17
19
|
def backend_version
|
18
|
-
get
|
20
|
+
get "version"
|
19
21
|
end
|
20
22
|
|
21
23
|
def get(path, options = {})
|
22
|
-
request
|
24
|
+
request "GET", path, options
|
23
25
|
end
|
24
26
|
|
25
27
|
def post(path, payload, params = {})
|
26
|
-
request
|
28
|
+
request "POST", path, {body: payload, query: params}
|
27
29
|
end
|
28
30
|
|
29
31
|
def put(path, payload, params = {})
|
30
|
-
request
|
32
|
+
request "PUT", path, {body: payload, query: params}
|
31
33
|
end
|
32
34
|
|
33
35
|
def delete(path)
|
34
|
-
request
|
36
|
+
request "DELETE", path
|
35
37
|
end
|
36
38
|
|
37
39
|
# Scoping requests
|
@@ -43,7 +45,7 @@ module ArchivesSpace
|
|
43
45
|
|
44
46
|
begin
|
45
47
|
Integer(id)
|
46
|
-
rescue
|
48
|
+
rescue
|
47
49
|
raise RepositoryIdError, "Invalid Repository id: #{id}"
|
48
50
|
end
|
49
51
|
|
@@ -51,14 +53,14 @@ module ArchivesSpace
|
|
51
53
|
end
|
52
54
|
|
53
55
|
def use_global_repository
|
54
|
-
@config.base_repo =
|
56
|
+
@config.base_repo = ""
|
55
57
|
end
|
56
58
|
|
57
59
|
private
|
58
60
|
|
59
61
|
def request(method, path, options = {})
|
60
62
|
sleep config.throttle
|
61
|
-
options[:headers] = {
|
63
|
+
options[:headers] = {"X-ArchivesSpace-Session" => token} if token
|
62
64
|
result = Request.new(config, method, path, options).execute
|
63
65
|
Response.new result
|
64
66
|
end
|