archivesspace-client 0.4.0 → 0.4.2

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: a4ff1d8782c564f4dfdf2dce03267b11f9e60fc14648bd07da6a9882c169050e
4
- data.tar.gz: 23f900ce6d47bf4a4b55646249306c49f0d41ef671f2c8ba30ad8ea1855ca000
3
+ metadata.gz: 0cb687dbc7f3a7a89938658d7024ab955b82004b42e25992b848fb956307d91d
4
+ data.tar.gz: a3ae5bbd93f28c043cbe15d8f4d0f0f3010171710f212116da3c60eecab4f816
5
5
  SHA512:
6
- metadata.gz: 99478138d6f6902b7f3efd07c92f5635f69ee43b4609135c92bb3c541454c95254da6f401de1be0051245e0a99f30de2c6cb2c19661bf2688a09bda789441a05
7
- data.tar.gz: c7f45e1358d6550164a05b1ed966c6ac6cb1f993bd2ab3c570c7ae52ba70de50923c19a4907fbc1951cd8a1db2b82a05062b4b464fa3f6446b6ca50f7a37668e
6
+ metadata.gz: ce3fb2a7fdea4c8fcd40b61f306581f9dbbb2ae2f83b1096500cb571ae6abcc82291d8493bbfff18b56284c33b8507e46f5eed97c25b81e4d4da6edcbf03bbef
7
+ data.tar.gz: 04f948ae7c1060b0872e32051a58936ce792190545841ad5153d741ce3af0d8a43f78db7c22c1486aa1d2bef02c368341fb64073a56d0b76f23c14685bfa10d8
@@ -7,7 +7,7 @@ jobs:
7
7
  runs-on: ubuntu-latest
8
8
  steps:
9
9
  - name: Checkout code
10
- uses: actions/checkout@v3
10
+ uses: actions/checkout@v4
11
11
 
12
12
  - name: Setup Ruby and install gems
13
13
  uses: ruby/setup-ruby@v1
@@ -18,7 +18,6 @@ jobs:
18
18
  uses: ruby/setup-ruby@v1
19
19
  with:
20
20
  bundler-cache: true
21
- ruby-version: 3.2.2
22
21
  rubygems: latest
23
22
 
24
23
  - name: Release Gem
data/README.md CHANGED
@@ -2,6 +2,26 @@
2
2
 
3
3
  Interact with ArchivesSpace via the API.
4
4
 
5
+ <!-- TOC start (generated with https://github.com/derlin/bitdowntoc) -->
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
+ * [Contributing](#contributing)
21
+ * [License](#license)
22
+
23
+ <!-- TOC end -->
24
+
5
25
  ## Installation
6
26
 
7
27
  Add this line to your application's Gemfile:
@@ -26,7 +46,9 @@ gem install archivesspace-client
26
46
 
27
47
  See the examples directory for a range of use cases.
28
48
 
29
- **Default configuration**
49
+ ### Configuring a client
50
+
51
+ #### Default configuration
30
52
 
31
53
  Create client with default settings (`localhost:8089`, `admin`, `admin`):
32
54
 
@@ -34,12 +56,11 @@ Create client with default settings (`localhost:8089`, `admin`, `admin`):
34
56
  client = ArchivesSpace::Client.new.login
35
57
  ```
36
58
 
37
- **Custom configuration**
59
+ #### Custom configuration, on the fly
38
60
 
39
61
  ```ruby
40
62
  config = ArchivesSpace::Configuration.new({
41
- base_uri: "https://archives.university.edu/api",
42
- base_repo: "",
63
+ base_uri: "https://archives.university.edu/staff/api",
43
64
  username: "admin",
44
65
  password: "123456",
45
66
  page_size: 50,
@@ -51,7 +72,35 @@ config = ArchivesSpace::Configuration.new({
51
72
  client = ArchivesSpace::Client.new(config).login
52
73
  ```
53
74
 
54
- **Making basic requests**
75
+ **NOTE:** `ArchivesSpace::Configuration` allows you to set a `base_repo` value as well, but if this value is set in your config at the start, calls to API endpoints that do not include a repository id in the URI may not work correctly. It is recommended you set/unset the client repository as needed during use via the `#repository` method as described below. If you must set `base_repo` in the config used to create your client, note that the value should be like: "repositories/2", and not just the integer repository id.
76
+
77
+ #### Custom configuration, stored for use with CLI or console
78
+
79
+ Create a file containing JSON config data like:
80
+
81
+ ```
82
+ {
83
+ "base_uri": "http://localhost:4567",
84
+ "username": "admin",
85
+ "password": "myverysecurepassword",
86
+ "page_size": 50,
87
+ "throttle": 0,
88
+ "timeout": 60,
89
+ "verify_ssl": false,
90
+ "debug": true
91
+ }
92
+ ```
93
+
94
+ The CLI and console commands will, by default, look for this stored config at `~/.asclientrc`,
95
+
96
+ However, you may also set a custom location for the file by setting an ASCLIENT_CFG environment variable. This is handy if you prefer to use [XDG Base Directory Specification](https://xdgbasedirectoryspecification.com/), or have other opinions about where such config should live:
97
+
98
+ ```
99
+ export ASCLIENT_CFG="$HOME/.config/archivesspace/client.json"
100
+ ```
101
+
102
+
103
+ ### Making basic requests
55
104
 
56
105
  The client responds to the standard request methods:
57
106
 
@@ -77,17 +126,33 @@ user = client.users.find { |user| user["username"] == "jdoe" }
77
126
  See `pagination.rb` for endpoints that support record type methods such as
78
127
  `client.digital_objects` etc.
79
128
 
80
- **Setting a repository context**
129
+ ### Setting a repository context
81
130
 
82
131
  Use the `repository` method to add a repository scope to requests (this is optional).
83
132
 
133
+ Instead of doing:
134
+
135
+ ```ruby
136
+ client.get('repositories/2/digital_objects', query: {page: 1})
137
+ ```
138
+
139
+ You can do:
140
+
84
141
  ```ruby
85
142
  client.repository(2)
86
- client.get('digital_objects', query: {page: 1}) # instead of "repositories/2/digital_objects" etc.
143
+ client.get('digital_objects', query: {page: 1})
144
+ ```
145
+
87
146
 
88
- # to reset
147
+ To reset:
148
+
149
+ ```ruby
89
150
  client.repository(nil)
90
- # or
151
+ ```
152
+
153
+ Or:
154
+
155
+ ```ruby
91
156
  client.use_global_repository
92
157
  ```
93
158
 
@@ -124,26 +189,40 @@ To view available templates use: `ArchivesSpace::Template.list`
124
189
 
125
190
  ## CLI
126
191
 
127
- Create an `~/.asclientrc` file with a json version of the client configuration:
192
+ Create a stored custom configuration to be used with the CLI as described above.
128
193
 
129
- ```json
130
- {
131
- "base_uri": "https://archives.university.edu/api",
132
- "base_repo": "",
133
- "username": "admin",
134
- "password": "123456",
135
- "page_size": 50,
136
- "throttle": 0,
137
- "timeout": 60,
138
- "verify_ssl": false
139
- }
194
+ If you installed this client as a gem via the `gem install archivesspace-client` command, you should be able to use the `asclient` command directly.
195
+
196
+ If entering `asclient` in your terminal returns an error, you will need to use the CLI from within this repository:
197
+
198
+ ```bash
199
+ cd path/to/archivesspace-client
200
+ ./exe/asclient
140
201
  ```
141
202
 
142
- Run commands:
203
+ The `asclient` command is self-documenting and will show you information about the currently supported commands.
204
+
205
+ To get more detailed usage info on a command:
143
206
 
144
207
  ```bash
145
- # when using locally via the repo prefix commands with ./exe/ i.e. ./exe/asclient -v
146
- asclient -v
208
+ asclient exec -h
209
+ ```
210
+
211
+ ## Console usage
212
+
213
+ Loading this application in console allows you to play around with its functionality interactively.
214
+
215
+ Create a stored custom configuration to be used with the console as described above. Then:
216
+
217
+ ```bash
218
+ cd path/to/archivesspace-client
219
+ ./bin/console
220
+ ```
221
+
222
+ An IRB session opens. Entering the following should give you the backend version of the ArchivesSpace instance your stored custom config points to:
223
+
224
+ ```
225
+ @client.backend_version
147
226
  ```
148
227
 
149
228
  ## Development
@@ -33,5 +33,5 @@ Gem::Specification.new do |spec|
33
33
  spec.add_dependency "httparty", "~> 0.14"
34
34
  spec.add_dependency "json", "~> 2.0"
35
35
  spec.add_dependency "nokogiri", "~> 1.10"
36
- spec.add_dependency "jbuilder", "~> 2.11.5"
36
+ spec.add_dependency "jbuilder", "~> 2.12"
37
37
  end
data/bin/console CHANGED
@@ -5,15 +5,7 @@ require "bundler/setup"
5
5
  require "archivesspace/client"
6
6
 
7
7
  config = ArchivesSpace::Configuration.new(
8
- {
9
- base_uri: "https://test.archivesspace.org/staff/api",
10
- base_repo: "",
11
- username: "admin",
12
- password: "admin",
13
- page_size: 50,
14
- throttle: 0,
15
- verify_ssl: false
16
- }
8
+ ArchivesSpace::Client::CLI.find_config
17
9
  )
18
10
  @client = ArchivesSpace::Client.new(config).login
19
11
 
data/examples/export.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
- require "awesome_print"
5
4
  require "archivesspace/client"
6
5
 
7
6
  # official sandbox
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
- require "awesome_print"
5
4
  require "archivesspace/client"
6
5
 
7
6
  username = "admin"
@@ -1,13 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
- require "awesome_print"
5
4
  require "archivesspace/client"
6
5
 
7
6
  # official sandbox
8
7
  config = ArchivesSpace::Configuration.new(
9
8
  {
10
- base_uri: "https://sandbox.archivesspace.org/api",
9
+ base_uri: "https://sandbox.archivesspace.org/staff/api",
11
10
  base_repo: "",
12
11
  username: "admin",
13
12
  password: "admin",
@@ -19,7 +18,7 @@ config = ArchivesSpace::Configuration.new(
19
18
 
20
19
  client = ArchivesSpace::Client.new(config).login
21
20
 
22
- ap ArchivesSpace::Template.list # view available templates
21
+ puts ArchivesSpace::Template.list # view available templates
23
22
 
24
23
  repo_data = {
25
24
  repo_code: "XYZ",
@@ -40,20 +39,20 @@ begin
40
39
  response = client.post("/repositories/with_agent", repository)
41
40
  if response.result.success?
42
41
  repository = client.repositories.find { |r| r["repo_code"] == "XYZ" }
43
- ap repository
44
- ap client.delete(repository["uri"])
42
+ puts repository
43
+ puts client.delete(repository["uri"])
45
44
  else
46
- ap response.parsed
45
+ puts response.parsed
47
46
  end
48
47
 
49
48
  user = ArchivesSpace::Template.process("user.json.erb", user_data)
50
49
  response = client.post("users", user, {password: user_password})
51
50
  if response.result.success?
52
51
  user = client.users.find { |r| r["username"] == "lmessi" }
53
- ap user
54
- ap client.delete user["uri"]
52
+ puts user
53
+ puts client.delete(user["uri"]).inspect
55
54
  else
56
- ap response.parsed
55
+ puts response.parsed
57
56
  end
58
57
  rescue ArchivesSpace::RequestError => e
59
58
  puts e.message
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
- require "awesome_print"
5
4
  require "archivesspace/client"
6
5
 
7
6
  puts ArchivesSpace::Template.list
@@ -1,13 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
- require "awesome_print"
5
4
  require "archivesspace/client"
6
5
 
7
6
  # official sandbox
8
7
  config = ArchivesSpace::Configuration.new(
9
8
  {
10
- base_uri: "https://sandbox.archivesspace.org/api",
9
+ base_uri: "https://sandbox.archivesspace.org/staff/api",
11
10
  base_repo: "",
12
11
  username: "admin",
13
12
  password: "admin",
@@ -1,13 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
- require "awesome_print"
5
4
  require "archivesspace/client"
6
5
 
7
6
  # official sandbox
8
7
  config = ArchivesSpace::Configuration.new(
9
8
  {
10
- base_uri: "https://sandbox.archivesspace.org/api",
9
+ base_uri: "https://sandbox.archivesspace.org/staff/api",
11
10
  base_repo: "",
12
11
  username: "admin",
13
12
  password: "admin",
@@ -19,17 +18,13 @@ config = ArchivesSpace::Configuration.new(
19
18
 
20
19
  client = ArchivesSpace::Client.new(config).login
21
20
 
22
- user_data = {
21
+ user_data = ArchivesSpace::Template.process("user.json.erb", {
23
22
  username: "bde",
24
23
  name: "BDE",
25
24
  is_admin: false
26
- }
25
+ })
27
26
 
28
- client.post(
29
- "users",
30
- ArchivesSpace::Template.process("user.json.erb", user_data),
31
- {password: "123456"}
32
- )
27
+ client.post("users", user_data, {password: "123456"})
33
28
 
34
29
  users_with_roles = {
35
30
  "bde" => ["repository-basic-data-entry"]
@@ -38,7 +33,7 @@ users_with_roles = {
38
33
  begin
39
34
  client.config.base_repo = "repositories/2"
40
35
  results = client.group_user_assignment users_with_roles
41
- ap results.map(&:parsed)
36
+ puts results.map(&:parsed)
42
37
  rescue ArchivesSpace::RequestError => e
43
38
  puts e.message
44
39
  end
@@ -25,11 +25,11 @@ module ArchivesSpace
25
25
  end
26
26
 
27
27
  def post(path, payload, params = {})
28
- request "POST", path, {body: payload, query: params}
28
+ request "POST", path, {body: payload.to_json, query: params}
29
29
  end
30
30
 
31
31
  def put(path, payload, params = {})
32
- request "PUT", path, {body: payload, query: params}
32
+ request "PUT", path, {body: payload.to_json, query: params}
33
33
  end
34
34
 
35
35
  def delete(path)
@@ -3,10 +3,6 @@
3
3
  module ArchivesSpace
4
4
  # Perform specific API tasks
5
5
  module Task
6
- # def batch_import(payload, params = {})
7
- # # TODO: create "batch_import", payload, params
8
- # end
9
-
10
6
  def group_user_assignment(users_with_roles)
11
7
  updated = []
12
8
  groups.each do |group|
@@ -29,7 +25,7 @@ module ArchivesSpace
29
25
 
30
26
  next unless update
31
27
 
32
- response = post("/groups/#{uri_to_id(group["uri"])}", group.to_json)
28
+ response = post("/groups/#{uri_to_id(group["uri"])}", group)
33
29
  updated << response
34
30
  end
35
31
  updated
@@ -54,13 +50,9 @@ module ArchivesSpace
54
50
  user = all("users").find { |u| u["username"] == username }
55
51
  raise RequestError, user.status unless user
56
52
 
57
- post(user["uri"], user.to_json, {password: password})
53
+ post(user["uri"], user, {password: password})
58
54
  end
59
55
 
60
- # def search(params)
61
- # # TODO: get "search", params
62
- # end
63
-
64
56
  private
65
57
 
66
58
  def uri_to_id(uri)
@@ -50,7 +50,7 @@ module ArchivesSpace
50
50
  def process
51
51
  t = ERB.new(read_template)
52
52
  r = t.result(binding).squeeze("\n")
53
- JSON.parse(r).to_json
53
+ JSON.parse(r)
54
54
  end
55
55
  end
56
56
 
@@ -60,9 +60,9 @@ module ArchivesSpace
60
60
  end
61
61
 
62
62
  def process
63
- ::Jbuilder.encode do |json|
63
+ ::Jbuilder.new do |json|
64
64
  eval(read_template, binding) # standard:disable Security/Eval
65
- end
65
+ end.attributes!
66
66
  end
67
67
  end
68
68
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ArchivesSpace
4
4
  class Client
5
- VERSION = "0.4.0"
5
+ VERSION = "0.4.2"
6
6
  end
7
7
  end
@@ -21,14 +21,14 @@ describe ArchivesSpace::Template do
21
21
 
22
22
  it "can process an erb template" do
23
23
  data = {repo_code: "ABC", name: "ABC Archive", agent_contact_name: "ABC Admin"}
24
- json = JSON.parse(ArchivesSpace::Template.process("repository_with_agent.json.erb", data))
25
- expect(json["repository"]["repo_code"]).to eq data[:repo_code]
24
+ record = ArchivesSpace::Template.process("repository_with_agent.json.erb", data)
25
+ expect(record["repository"]["repo_code"]).to eq data[:repo_code]
26
26
  end
27
27
 
28
28
  it "can process a jbuilder template" do
29
29
  data = {"title" => "Title", "object_number" => "001.001", "description_level" => "collection"}
30
- json = JSON.parse(ArchivesSpace::Template.process("resource.json.jbuilder", data))
31
- expect(json["id_0"]).to eq data["object_number"]
30
+ record = ArchivesSpace::Template.process("resource.json.jbuilder", data)
31
+ expect(record["id_0"]).to eq data["object_number"]
32
32
  end
33
33
 
34
34
  it "rejects a template that does not match by extension" do
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: archivesspace-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Cooper
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-04-18 00:00:00.000000000 Z
10
+ date: 2025-02-14 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: aruba
@@ -204,14 +203,14 @@ dependencies:
204
203
  requirements:
205
204
  - - "~>"
206
205
  - !ruby/object:Gem::Version
207
- version: 2.11.5
206
+ version: '2.12'
208
207
  type: :runtime
209
208
  prerelease: false
210
209
  version_requirements: !ruby/object:Gem::Requirement
211
210
  requirements:
212
211
  - - "~>"
213
212
  - !ruby/object:Gem::Version
214
- version: 2.11.5
213
+ version: '2.12'
215
214
  description: Interact with ArchivesSpace via the API.
216
215
  email:
217
216
  - mark.c.cooper@outlook.com
@@ -268,7 +267,6 @@ homepage: ''
268
267
  licenses:
269
268
  - MIT
270
269
  metadata: {}
271
- post_install_message:
272
270
  rdoc_options: []
273
271
  require_paths:
274
272
  - lib
@@ -283,8 +281,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
283
281
  - !ruby/object:Gem::Version
284
282
  version: '0'
285
283
  requirements: []
286
- rubygems_version: 3.5.9
287
- signing_key:
284
+ rubygems_version: 3.6.3
288
285
  specification_version: 4
289
286
  summary: Interact with ArchivesSpace via the API.
290
287
  test_files: []