archivesspace-client 0.1.12 → 0.2.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 +4 -2
- data/.github/workflows/publish.yml +1 -1
- data/.rubocop.yml +4 -0
- data/Gemfile +1 -1
- data/README.md +4 -1
- data/Rakefile +5 -3
- data/archivesspace-client.gemspec +29 -29
- data/examples/export.rb +11 -11
- data/examples/password_reset.rb +6 -6
- data/examples/repo_and_user.rb +19 -19
- data/examples/test_connection.rb +8 -8
- data/examples/user_groups.rb +13 -13
- 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 +11 -11
- data/lib/archivesspace/client/configuration.rb +7 -6
- data/lib/archivesspace/client/pagination.rb +3 -3
- data/lib/archivesspace/client/request.rb +12 -11
- data/lib/archivesspace/client/response.rb +5 -5
- data/lib/archivesspace/client/task.rb +15 -15
- data/lib/archivesspace/client/template.rb +4 -4
- data/lib/archivesspace/client/version.rb +1 -1
- data/lib/archivesspace/client.rb +18 -18
- data/spec/archivesspace/client_spec.rb +29 -29
- data/spec/archivesspace/configuration_spec.rb +8 -8
- data/spec/archivesspace/templates_spec.rb +9 -9
- data/spec/spec_helper.rb +8 -8
- metadata +19 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26be5a79844d110ef48e58aff9f3e1d77a9c30cbdcdad23939fce33853a21f1c
|
4
|
+
data.tar.gz: 0b9751a44ecd8e594eaad01395c088b78c438759b7691bcaacc6160262e35325
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93475f09b5b24182646d0dce07b57aa2cc1e98a6e78be5874ee20454f9603736f86fe2c0bba360c72641e1364ffec9d28bdbbad12683c7c86d061486148814ad
|
7
|
+
data.tar.gz: 6671814168066bc5c4ad04c436bed59e50fbec5febd6a11867b7f97f93c1be15d40e2d3147c19283ced5f435702f1107bf2476abe0a966dbffc149e461595911
|
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
|
@@ -17,6 +15,10 @@ jobs:
|
|
17
15
|
bundler-cache: true
|
18
16
|
ruby-version: 2.7
|
19
17
|
|
18
|
+
- name: Lint
|
19
|
+
run: |
|
20
|
+
bundle exec standardrb
|
21
|
+
|
20
22
|
- name: Run tests
|
21
23
|
run: |
|
22
24
|
bundle exec rake
|
data/.rubocop.yml
ADDED
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
|
|
@@ -130,6 +132,7 @@ Create an `~/.asclientrc` file with a json version of the client configuration:
|
|
130
132
|
"password": "123456",
|
131
133
|
"page_size": 50,
|
132
134
|
"throttle": 0,
|
135
|
+
"timeout": 60,
|
133
136
|
"verify_ssl": false
|
134
137
|
}
|
135
138
|
```
|
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,38 @@
|
|
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
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency
|
21
|
+
spec.add_development_dependency "aruba"
|
22
|
+
spec.add_development_dependency "awesome_print", "~> 1.8.0"
|
23
|
+
spec.add_development_dependency "bundler"
|
24
|
+
spec.add_development_dependency "capybara_discoball"
|
25
|
+
spec.add_development_dependency "cucumber"
|
26
|
+
spec.add_development_dependency "json_spec"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "3.6.0"
|
29
|
+
spec.add_development_dependency "rubocop"
|
30
|
+
spec.add_development_dependency "standard"
|
31
|
+
spec.add_development_dependency "vcr", "3.0.3"
|
32
|
+
spec.add_development_dependency "webmock", "3.0.1"
|
33
33
|
|
34
|
-
spec.add_dependency
|
35
|
-
spec.add_dependency
|
36
|
-
spec.add_dependency
|
37
|
-
spec.add_dependency
|
34
|
+
spec.add_dependency "dry-cli", "~> 0.7"
|
35
|
+
spec.add_dependency "httparty", "~> 0.14"
|
36
|
+
spec.add_dependency "json", "~> 2.0"
|
37
|
+
spec.add_dependency "nokogiri", "~> 1.10"
|
38
38
|
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
37
|
repository = ArchivesSpace::Template.process(:repository_with_agent, 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
49
|
user = ArchivesSpace::Template.process(:user, user_data)
|
50
|
-
response = client.post(
|
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
|
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
|
-
|
29
|
+
"users",
|
30
30
|
ArchivesSpace::Template.process(:user, user_data),
|
31
|
-
{
|
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,33 @@ module ArchivesSpace
|
|
5
5
|
include Pagination
|
6
6
|
include Task
|
7
7
|
attr_accessor :token
|
8
|
-
attr_reader
|
8
|
+
attr_reader :config
|
9
9
|
|
10
10
|
def initialize(config = Configuration.new)
|
11
|
-
raise
|
11
|
+
raise "Invalid configuration object" unless config.is_a? ArchivesSpace::Configuration
|
12
12
|
|
13
13
|
@config = config
|
14
|
-
@token
|
14
|
+
@token = nil
|
15
15
|
end
|
16
16
|
|
17
17
|
def backend_version
|
18
|
-
get
|
18
|
+
get "version"
|
19
19
|
end
|
20
20
|
|
21
21
|
def get(path, options = {})
|
22
|
-
request
|
22
|
+
request "GET", path, options
|
23
23
|
end
|
24
24
|
|
25
25
|
def post(path, payload, params = {})
|
26
|
-
request
|
26
|
+
request "POST", path, {body: payload, query: params}
|
27
27
|
end
|
28
28
|
|
29
29
|
def put(path, payload, params = {})
|
30
|
-
request
|
30
|
+
request "PUT", path, {body: payload, query: params}
|
31
31
|
end
|
32
32
|
|
33
33
|
def delete(path)
|
34
|
-
request
|
34
|
+
request "DELETE", path
|
35
35
|
end
|
36
36
|
|
37
37
|
# Scoping requests
|
@@ -43,7 +43,7 @@ module ArchivesSpace
|
|
43
43
|
|
44
44
|
begin
|
45
45
|
Integer(id)
|
46
|
-
rescue
|
46
|
+
rescue
|
47
47
|
raise RepositoryIdError, "Invalid Repository id: #{id}"
|
48
48
|
end
|
49
49
|
|
@@ -51,14 +51,14 @@ module ArchivesSpace
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def use_global_repository
|
54
|
-
@config.base_repo =
|
54
|
+
@config.base_repo = ""
|
55
55
|
end
|
56
56
|
|
57
57
|
private
|
58
58
|
|
59
59
|
def request(method, path, options = {})
|
60
60
|
sleep config.throttle
|
61
|
-
options[:headers] = {
|
61
|
+
options[:headers] = {"X-ArchivesSpace-Session" => token} if token
|
62
62
|
result = Request.new(config, method, path, options).execute
|
63
63
|
Response.new result
|
64
64
|
end
|
@@ -4,21 +4,22 @@ module ArchivesSpace
|
|
4
4
|
class Configuration
|
5
5
|
def defaults
|
6
6
|
{
|
7
|
-
base_uri:
|
8
|
-
base_repo:
|
7
|
+
base_uri: "http://localhost:8089",
|
8
|
+
base_repo: "",
|
9
9
|
debug: false,
|
10
|
-
username:
|
11
|
-
password:
|
10
|
+
username: "admin",
|
11
|
+
password: "admin",
|
12
12
|
page_size: 50,
|
13
13
|
throttle: 0,
|
14
|
-
verify_ssl: true
|
14
|
+
verify_ssl: true,
|
15
|
+
timeout: 60
|
15
16
|
}
|
16
17
|
end
|
17
18
|
|
18
19
|
def initialize(settings = {})
|
19
20
|
settings = defaults.merge(settings)
|
20
21
|
settings.each do |property, value|
|
21
|
-
next unless defaults.
|
22
|
+
next unless defaults.key?(property)
|
22
23
|
|
23
24
|
instance_variable_set("@#{property}", value)
|
24
25
|
self.class.send(:attr_accessor, property)
|
@@ -20,7 +20,7 @@ module ArchivesSpace
|
|
20
20
|
]
|
21
21
|
|
22
22
|
ENDPOINTS.each do |endpoint|
|
23
|
-
method_name = endpoint.split(
|
23
|
+
method_name = endpoint.split("/").last # remove prefix
|
24
24
|
define_method(method_name) do |options = {}|
|
25
25
|
all(endpoint, options)
|
26
26
|
end
|
@@ -36,8 +36,8 @@ module ArchivesSpace
|
|
36
36
|
result = get(path, options)
|
37
37
|
results = []
|
38
38
|
|
39
|
-
if result.parsed.respond_to?(:key) && result.parsed.key?(
|
40
|
-
results = result.parsed[
|
39
|
+
if result.parsed.respond_to?(:key) && result.parsed.key?("results")
|
40
|
+
results = result.parsed["results"]
|
41
41
|
else
|
42
42
|
results = result.parsed
|
43
43
|
unlimited_listing = true
|
@@ -10,26 +10,27 @@ module ArchivesSpace
|
|
10
10
|
delete: {},
|
11
11
|
get: {},
|
12
12
|
post: {
|
13
|
-
|
14
|
-
|
13
|
+
"Content-Type" => "application/json",
|
14
|
+
"Content-Length" => "nnnn"
|
15
15
|
},
|
16
16
|
put: {
|
17
|
-
|
18
|
-
|
17
|
+
"Content-Type" => "application/json",
|
18
|
+
"Content-Length" => "nnnn"
|
19
19
|
}
|
20
20
|
}
|
21
21
|
headers[method]
|
22
22
|
end
|
23
23
|
|
24
|
-
def initialize(config, method =
|
25
|
-
@config
|
26
|
-
@method
|
27
|
-
@path
|
28
|
-
@options
|
24
|
+
def initialize(config, method = "GET", path = "", options = {})
|
25
|
+
@config = config
|
26
|
+
@method = method.downcase.to_sym
|
27
|
+
@path = path.gsub(%r{^/+}, "")
|
28
|
+
@options = options
|
29
29
|
@options[:headers] =
|
30
30
|
options[:headers] ? default_headers(@method).merge(options[:headers]) : default_headers(@method)
|
31
|
-
@options[:verify]
|
32
|
-
@options[:
|
31
|
+
@options[:verify] = config.verify_ssl
|
32
|
+
@options[:timeout] = config.timeout
|
33
|
+
@options[:query] = {} unless options.key? :query
|
33
34
|
|
34
35
|
self.class.debug_output($stdout) if @config.debug
|
35
36
|
|
@@ -5,11 +5,11 @@ module ArchivesSpace
|
|
5
5
|
attr_reader :result, :parsed, :body, :headers, :status, :status_code
|
6
6
|
|
7
7
|
def initialize(result)
|
8
|
-
@result
|
9
|
-
@parsed
|
10
|
-
@body
|
11
|
-
@headers
|
12
|
-
@status
|
8
|
+
@result = result
|
9
|
+
@parsed = result.parsed_response
|
10
|
+
@body = result.body
|
11
|
+
@headers = result.headers
|
12
|
+
@status = result.response
|
13
13
|
@status_code = result.code.to_i
|
14
14
|
end
|
15
15
|
end
|
@@ -10,51 +10,51 @@ module ArchivesSpace
|
|
10
10
|
def group_user_assignment(users_with_roles)
|
11
11
|
updated = []
|
12
12
|
groups.each do |group|
|
13
|
-
group = get("groups/#{uri_to_id(group[
|
13
|
+
group = get("groups/#{uri_to_id(group["uri"])}").parsed
|
14
14
|
update = false
|
15
15
|
|
16
16
|
users_with_roles.each do |user, roles|
|
17
17
|
# should the user still belong to this group?
|
18
|
-
if group[
|
19
|
-
unless roles.include? group[
|
20
|
-
group[
|
18
|
+
if group["member_usernames"].include?(user)
|
19
|
+
unless roles.include? group["group_code"]
|
20
|
+
group["member_usernames"].delete user
|
21
21
|
update = true
|
22
22
|
end
|
23
23
|
# should the user be added to this group?
|
24
|
-
elsif roles.include? group[
|
25
|
-
group[
|
24
|
+
elsif roles.include? group["group_code"]
|
25
|
+
group["member_usernames"] << user
|
26
26
|
update = true
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
next unless update
|
31
31
|
|
32
|
-
response = post("/groups/#{uri_to_id(group[
|
32
|
+
response = post("/groups/#{uri_to_id(group["uri"])}", group.to_json)
|
33
33
|
updated << response
|
34
34
|
end
|
35
35
|
updated
|
36
36
|
end
|
37
37
|
|
38
38
|
def login
|
39
|
-
username
|
40
|
-
password
|
39
|
+
username = config.username
|
40
|
+
password = config.password
|
41
41
|
base_repo = config.base_repo
|
42
42
|
use_global_repository # ensure we're in the global scope to login
|
43
|
-
result = request(
|
44
|
-
unless result.parsed[
|
43
|
+
result = request("POST", "/users/#{username}/login", {query: {password: password}})
|
44
|
+
unless result.parsed["session"]
|
45
45
|
raise ConnectionError, "API client login failed as user [#{username}], check username and password are correct"
|
46
46
|
end
|
47
47
|
|
48
48
|
config.base_repo = base_repo # reset repo as set by the cfg
|
49
|
-
@token = result.parsed[
|
49
|
+
@token = result.parsed["session"]
|
50
50
|
self
|
51
51
|
end
|
52
52
|
|
53
53
|
def password_reset(username, password)
|
54
|
-
user = all(
|
54
|
+
user = all("users").find { |u| u["username"] == username }
|
55
55
|
raise RequestError, user.status unless user
|
56
56
|
|
57
|
-
post(user[
|
57
|
+
post(user["uri"], user.to_json, {password: password})
|
58
58
|
end
|
59
59
|
|
60
60
|
# def search(params)
|
@@ -64,7 +64,7 @@ module ArchivesSpace
|
|
64
64
|
private
|
65
65
|
|
66
66
|
def uri_to_id(uri)
|
67
|
-
uri.split(
|
67
|
+
uri.split("/").last
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
@@ -3,12 +3,12 @@
|
|
3
3
|
module ArchivesSpace
|
4
4
|
module Template
|
5
5
|
def self.list
|
6
|
-
Dir.glob File.join(templates_path,
|
6
|
+
Dir.glob File.join(templates_path, "*.erb")
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.process(template, data)
|
10
10
|
t = ERB.new(read(template))
|
11
|
-
r = t.result(binding).
|
11
|
+
r = t.result(binding).squeeze("\n")
|
12
12
|
JSON.parse(r).to_json
|
13
13
|
end
|
14
14
|
|
@@ -18,8 +18,8 @@ module ArchivesSpace
|
|
18
18
|
|
19
19
|
def self.templates_path
|
20
20
|
ENV.fetch(
|
21
|
-
|
22
|
-
File.join(File.dirname(File.expand_path(__FILE__)),
|
21
|
+
"ARCHIVESSPACE_CLIENT_TEMPLATES_PATH",
|
22
|
+
File.join(File.dirname(File.expand_path(__FILE__)), "templates")
|
23
23
|
)
|
24
24
|
end
|
25
25
|
end
|
data/lib/archivesspace/client.rb
CHANGED
@@ -1,34 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require "dry/cli"
|
4
|
+
require "httparty"
|
5
|
+
require "json"
|
6
|
+
require "nokogiri"
|
7
7
|
|
8
8
|
# mixins required first
|
9
|
-
require
|
10
|
-
require
|
9
|
+
require "archivesspace/client/pagination"
|
10
|
+
require "archivesspace/client/task"
|
11
11
|
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
12
|
+
require "archivesspace/client/client"
|
13
|
+
require "archivesspace/client/configuration"
|
14
|
+
require "archivesspace/client/request"
|
15
|
+
require "archivesspace/client/response"
|
16
|
+
require "archivesspace/client/template"
|
17
|
+
require "archivesspace/client/version"
|
18
18
|
|
19
19
|
# cli
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
20
|
+
require "archivesspace/client/cli/exec"
|
21
|
+
require "archivesspace/client/cli/version"
|
22
|
+
require "archivesspace/client/cli" # load the registry last
|
23
23
|
|
24
24
|
module ArchivesSpace
|
25
25
|
class ConnectionError < RuntimeError; end
|
26
26
|
|
27
|
-
class ContextError
|
27
|
+
class ContextError < RuntimeError; end
|
28
28
|
|
29
29
|
class RepositoryIdError < RuntimeError; end
|
30
30
|
|
31
|
-
class ParamsError
|
31
|
+
class ParamsError < RuntimeError; end
|
32
32
|
|
33
|
-
class RequestError
|
33
|
+
class RequestError < RuntimeError; end
|
34
34
|
end
|
@@ -1,87 +1,87 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
describe ArchivesSpace::Client do
|
6
6
|
let(:client) { ArchivesSpace::Client.new }
|
7
|
-
let(:login)
|
7
|
+
let(:login) { -> { client.login } }
|
8
8
|
|
9
|
-
describe
|
10
|
-
it
|
9
|
+
describe "Configuration" do
|
10
|
+
it "will use the default configuration if none is provided" do
|
11
11
|
client = ArchivesSpace::Client.new
|
12
12
|
expect(client.config.base_uri).to eq DEFAULT_BASE_URI
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
16
|
-
expect { ArchivesSpace::Client.new({
|
15
|
+
it "will raise an error if supplied configuration is of invalid type" do
|
16
|
+
expect { ArchivesSpace::Client.new({base_uri: CUSTOM_BASE_URI}) }.to raise_error(RuntimeError)
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
20
|
-
client = ArchivesSpace::Client.new(ArchivesSpace::Configuration.new({
|
19
|
+
it "will allow a configuration object to be provided" do
|
20
|
+
client = ArchivesSpace::Client.new(ArchivesSpace::Configuration.new({base_uri: CUSTOM_BASE_URI}))
|
21
21
|
expect(client.config.base_uri).to eq CUSTOM_BASE_URI
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
describe
|
26
|
-
it
|
25
|
+
describe "Repository scoping" do
|
26
|
+
it "will set the repository with an integer id" do
|
27
27
|
client = ArchivesSpace::Client.new
|
28
28
|
client.repository 2
|
29
|
-
expect(client.config.base_repo).to eq
|
29
|
+
expect(client.config.base_repo).to eq "repositories/2"
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
32
|
+
it "will set the repository with a string id cast to integer" do
|
33
33
|
client = ArchivesSpace::Client.new
|
34
|
-
client.repository
|
35
|
-
expect(client.config.base_repo).to eq
|
34
|
+
client.repository "2"
|
35
|
+
expect(client.config.base_repo).to eq "repositories/2"
|
36
36
|
end
|
37
37
|
|
38
|
-
it
|
38
|
+
it "will fail if the id cannot be cast to integer" do
|
39
39
|
client = ArchivesSpace::Client.new
|
40
|
-
expect { client.repository(
|
40
|
+
expect { client.repository("xyz") }.to raise_error(
|
41
41
|
ArchivesSpace::RepositoryIdError
|
42
42
|
)
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
45
|
+
it "will use the global repo if repository is passed nil" do
|
46
46
|
client = ArchivesSpace::Client.new
|
47
47
|
client.repository 2
|
48
48
|
client.repository nil
|
49
|
-
expect(client.config.base_repo).to eq
|
49
|
+
expect(client.config.base_repo).to eq ""
|
50
50
|
end
|
51
51
|
|
52
|
-
it
|
52
|
+
it "will use the global repo when the method is called" do
|
53
53
|
client = ArchivesSpace::Client.new
|
54
54
|
client.repository 2
|
55
55
|
client.use_global_repository
|
56
|
-
expect(client.config.base_repo).to eq
|
56
|
+
expect(client.config.base_repo).to eq ""
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
describe
|
61
|
-
it
|
60
|
+
describe "Pagination" do
|
61
|
+
it "will have a method for defined paginated record types" do
|
62
62
|
client = ArchivesSpace::Client.new
|
63
63
|
ArchivesSpace::Pagination::ENDPOINTS.each do |e|
|
64
|
-
next if e.match?(
|
64
|
+
next if e.match?("/")
|
65
65
|
|
66
66
|
expect(client.respond_to?(e.to_sym)).to be true
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
it
|
70
|
+
it "will have a method for defined paginated record types with multipart path" do
|
71
71
|
client = ArchivesSpace::Client.new
|
72
72
|
expect(client.respond_to?(:people)).to be true
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
-
describe
|
77
|
-
it
|
76
|
+
describe "Version information" do
|
77
|
+
it "has a version number" do
|
78
78
|
expect(ArchivesSpace::Client::VERSION).not_to be nil
|
79
79
|
end
|
80
80
|
|
81
|
-
it
|
82
|
-
VCR.use_cassette(
|
81
|
+
it "can retrieve the backend version info" do
|
82
|
+
VCR.use_cassette("backend_version") do
|
83
83
|
login.call
|
84
|
-
response = client.get
|
84
|
+
response = client.get "version"
|
85
85
|
expect(response.status_code).to eq(200)
|
86
86
|
expect(response.body).to match(/ArchivesSpace \(.*\)/)
|
87
87
|
end
|
@@ -1,28 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
describe ArchivesSpace::Configuration do
|
6
|
-
it
|
6
|
+
it "uses the default profile for configuration settings" do
|
7
7
|
config = ArchivesSpace::Configuration.new
|
8
8
|
expect(config.base_uri).to eq DEFAULT_BASE_URI
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
11
|
+
it "allows configuration settings to be provided" do
|
12
12
|
config = ArchivesSpace::Configuration.new({
|
13
|
-
|
14
|
-
|
13
|
+
base_uri: CUSTOM_BASE_URI
|
14
|
+
})
|
15
15
|
expect(config.base_uri).to eq CUSTOM_BASE_URI
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it "allows the configuration properties to be updated" do
|
19
19
|
config = ArchivesSpace::Configuration.new
|
20
20
|
config.base_uri = CUSTOM_BASE_URI
|
21
21
|
expect(config.base_uri).to eq CUSTOM_BASE_URI
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
25
|
-
config = ArchivesSpace::Configuration.new({
|
24
|
+
it "ignores unrecognized configuration properties" do
|
25
|
+
config = ArchivesSpace::Configuration.new({xyz: 123})
|
26
26
|
expect { config.xyz }.to raise_error(NoMethodError)
|
27
27
|
end
|
28
28
|
end
|
@@ -1,26 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
describe ArchivesSpace::Template do
|
6
|
-
it
|
6
|
+
it "can list the default templates" do
|
7
7
|
templates = ArchivesSpace::Template.list
|
8
8
|
expect(templates).to_not be_empty
|
9
9
|
expect(templates).to include(/repository_with_agent.*erb/)
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it "can change the path when template envvar is set" do
|
13
13
|
expect(ArchivesSpace::Template.templates_path).to match(
|
14
14
|
/#{File.join('lib', 'archivesspace', 'client', 'templates')}/
|
15
15
|
)
|
16
|
-
ENV[
|
17
|
-
expect(ArchivesSpace::Template.templates_path).to eq
|
18
|
-
ENV.delete(
|
16
|
+
ENV["ARCHIVESSPACE_CLIENT_TEMPLATES_PATH"] = "/path/to/nowhere"
|
17
|
+
expect(ArchivesSpace::Template.templates_path).to eq "/path/to/nowhere"
|
18
|
+
ENV.delete("ARCHIVESSPACE_CLIENT_TEMPLATES_PATH")
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
22
|
-
data = {
|
21
|
+
it "can process a template" do
|
22
|
+
data = {repo_code: "ABC", name: "ABC Archive", agent_contact_name: "ABC Admin"}
|
23
23
|
json = JSON.parse(ArchivesSpace::Template.process(:repository_with_agent, data))
|
24
|
-
expect(json[
|
24
|
+
expect(json["repository"]["repo_code"]).to eq data[:repo_code]
|
25
25
|
end
|
26
26
|
end
|
data/spec/spec_helper.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
|
6
|
-
require
|
3
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
4
|
+
require "archivesspace/client"
|
5
|
+
require "vcr"
|
6
|
+
require "webmock/rspec"
|
7
7
|
|
8
8
|
# GLOBAL VALUES FOR SPECS
|
9
|
-
DEFAULT_BASE_URI =
|
10
|
-
CUSTOM_BASE_URI
|
9
|
+
DEFAULT_BASE_URI = "http://localhost:8089"
|
10
|
+
CUSTOM_BASE_URI = "https://archives.university.edu/api"
|
11
11
|
|
12
12
|
VCR.configure do |c|
|
13
|
-
c.cassette_library_dir =
|
13
|
+
c.cassette_library_dir = "spec/fixtures/cassettes"
|
14
14
|
c.hook_into :webmock
|
15
|
-
c.default_cassette_options = {
|
15
|
+
c.default_cassette_options = {record: :once}
|
16
16
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: archivesspace-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Cooper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aruba
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: standard
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: vcr
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -231,6 +245,7 @@ files:
|
|
231
245
|
- ".github/workflows/publish.yml"
|
232
246
|
- ".gitignore"
|
233
247
|
- ".rspec"
|
248
|
+
- ".rubocop.yml"
|
234
249
|
- ".travis.yml"
|
235
250
|
- Gemfile
|
236
251
|
- LICENSE.txt
|
@@ -286,16 +301,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
286
301
|
- !ruby/object:Gem::Version
|
287
302
|
version: '0'
|
288
303
|
requirements: []
|
289
|
-
rubygems_version: 3.3.
|
304
|
+
rubygems_version: 3.3.21
|
290
305
|
signing_key:
|
291
306
|
specification_version: 4
|
292
307
|
summary: Interact with ArchivesSpace via the API.
|
293
|
-
test_files:
|
294
|
-
- features/exec.feature
|
295
|
-
- features/support/setup.rb
|
296
|
-
- features/version.feature
|
297
|
-
- spec/archivesspace/client_spec.rb
|
298
|
-
- spec/archivesspace/configuration_spec.rb
|
299
|
-
- spec/archivesspace/templates_spec.rb
|
300
|
-
- spec/fixtures/cassettes/backend_version.yml
|
301
|
-
- spec/spec_helper.rb
|
308
|
+
test_files: []
|