archivesspace-client 0.1.10 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b68b6cb7fcd238639742c355e7256cea1ae76536762425d535e49ad0aaec309
4
- data.tar.gz: 7188d9e03e36c0ffefb3abd1694bdc5b21e7a5e74aee9e5e9396ee30571d3919
3
+ metadata.gz: 26be5a79844d110ef48e58aff9f3e1d77a9c30cbdcdad23939fce33853a21f1c
4
+ data.tar.gz: 0b9751a44ecd8e594eaad01395c088b78c438759b7691bcaacc6160262e35325
5
5
  SHA512:
6
- metadata.gz: 122cf84d68c31fc2a69423489c15ae93fbf671a039ab1f7753f5ab0b47056640e186f073c276ac53f3b145f76663be6cddc9cb23c364bd5e88a0d431b755d6e9
7
- data.tar.gz: eb8c1f20902bdf57c7d04a664d0f739878e1521c6d7a8ddcb5a0e2c08da9f1d9c7cb52789f409ac4ecee3705303aa07dd127d6584bb17ba5650c65049361275e
6
+ metadata.gz: 93475f09b5b24182646d0dce07b57aa2cc1e98a6e78be5874ee20454f9603736f86fe2c0bba360c72641e1364ffec9d28bdbbad12683c7c86d061486148814ad
7
+ data.tar.gz: 6671814168066bc5c4ad04c436bed59e50fbec5febd6a11867b7f97f93c1be15d40e2d3147c19283ced5f435702f1107bf2476abe0a966dbffc149e461595911
@@ -0,0 +1,24 @@
1
+ name: CI
2
+ on: [pull_request]
3
+
4
+ jobs:
5
+ tests:
6
+ name: Tests
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - name: Checkout code
10
+ uses: actions/checkout@v3
11
+
12
+ - name: Setup Ruby and install gems
13
+ uses: ruby/setup-ruby@v1
14
+ with:
15
+ bundler-cache: true
16
+ ruby-version: 2.7
17
+
18
+ - name: Lint
19
+ run: |
20
+ bundle exec standardrb
21
+
22
+ - name: Run tests
23
+ run: |
24
+ bundle exec rake
@@ -0,0 +1,42 @@
1
+ name: Publish Gem
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - master
8
+ jobs:
9
+ publish:
10
+ runs-on: ubuntu-latest
11
+ permissions:
12
+ contents: write
13
+
14
+ steps:
15
+ - uses: actions/checkout@v3
16
+
17
+ - name: Setup Ruby and install gems
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ bundler-cache: true
21
+ ruby-version: 2.7
22
+ rubygems: latest
23
+
24
+ - name: Release Gem
25
+ run: |
26
+ VERSION=$(bundle exec rake version)
27
+ GEM_VERSION=$(gem list --exact --remote $GEM_NAME)
28
+
29
+ # Publish to RubyGems.org
30
+ if [ "${GEM_VERSION}" != "$GEM_NAME (${VERSION})" ]; then
31
+ gem build $GEM_NAME.gemspec
32
+ gem push "$GEM_NAME-${VERSION}.gem"
33
+ fi
34
+
35
+ # Create a release tag
36
+ if ! git ls-remote --tags --exit-code origin v${VERSION}; then
37
+ git tag v${VERSION}
38
+ git push --tags
39
+ fi
40
+ env:
41
+ GEM_HOST_API_KEY: "${{ secrets.RUBYGEMS_AUTH_TOKEN }}"
42
+ GEM_NAME: archivesspace-client
data/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ require: standard
2
+
3
+ inherit_gem:
4
+ standard: config/base.yml
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in archivesspace-client.gemspec
6
6
  gemspec
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 `helpers.rb` for more convenience methods such as `client.digital_objects` etc.
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
  ```
@@ -161,17 +164,8 @@ bundle exec rake
161
164
 
162
165
  ## Publishing
163
166
 
164
- Bump version in `lib/archivesspace/client/version.rb` then:
165
-
166
- ```bash
167
- VERSION=0.1.9
168
- gem build archivesspace-client
169
- git add . && git commit -m "Bump to $VERSION"
170
- git tag v$VERSION
171
- git push origin master
172
- git push --tags
173
- gem push archivesspace-client-$VERSION.gem
174
- ```
167
+ When an updated version (`lib/archivesspace/client/version.rb`) is merged into the
168
+ main/master branch a new release will be built and published.
175
169
 
176
170
  ## Contributing
177
171
 
data/Rakefile CHANGED
@@ -1,14 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/gem_tasks'
3
+ require "bundler/gem_tasks"
4
4
 
5
- require 'rspec/core/rake_task'
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 'cucumber/rake/task'
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]
17
+
18
+ task :version do
19
+ puts ArchivesSpace::Client::VERSION
20
+ end
@@ -1,37 +1,38 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('lib', __dir__)
3
+ lib = File.expand_path("lib", __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'archivesspace/client/version'
5
+ require "archivesspace/client/version"
6
6
 
7
7
  Gem::Specification.new do |spec|
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'
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 = `git ls-files -z`.split("\x0")
18
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
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 'aruba'
23
- spec.add_development_dependency 'awesome_print', '~> 1.8.0'
24
- spec.add_development_dependency 'bundler'
25
- spec.add_development_dependency 'capybara_discoball'
26
- spec.add_development_dependency 'cucumber'
27
- spec.add_development_dependency 'json_spec'
28
- spec.add_development_dependency 'rake', '~> 10.0'
29
- spec.add_development_dependency 'rspec', '3.6.0'
30
- spec.add_development_dependency 'vcr', '3.0.3'
31
- spec.add_development_dependency 'webmock', '3.0.1'
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"
32
33
 
33
- spec.add_dependency 'dry-cli', '~> 0.7'
34
- spec.add_dependency 'httparty', '~> 0.14'
35
- spec.add_dependency 'json', '~> 2.0'
36
- spec.add_dependency 'nokogiri', '~> 1.10'
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"
37
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('../lib', __dir__)
4
- require 'awesome_print'
5
- require 'archivesspace/client'
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: 'http://test.archivesspace.org/staff/api',
11
- base_repo: '',
12
- username: 'admin',
13
- password: 'admin',
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 = 'repositories/2'
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: { modified_since: '1612166400' }).each do |resource|
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 = resource['uri'].split('/')[-1]
30
- opts = { include_unpublished: false }
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
@@ -1,16 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
4
- require 'awesome_print'
5
- require 'archivesspace/client'
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
+ require "awesome_print"
5
+ require "archivesspace/client"
6
6
 
7
- username = 'admin'
8
- password = 'admin'
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 StandardError => e
14
+ rescue => e
15
15
  puts "Failed to update password for #{username},\n#{e.message}"
16
16
  end
@@ -1,16 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
4
- require 'awesome_print'
5
- require 'archivesspace/client'
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: 'http://sandbox.archivesspace.org/api',
11
- base_repo: '',
12
- username: 'admin',
13
- password: 'admin',
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: 'XYZ',
26
- name: 'XYZ Archive',
27
- agent_contact_name: 'XYZ Admin'
25
+ repo_code: "XYZ",
26
+ name: "XYZ Archive",
27
+ agent_contact_name: "XYZ Admin"
28
28
  }
29
29
 
30
30
  user_data = {
31
- username: 'lmessi',
32
- name: 'Lionel Messi',
31
+ username: "lmessi",
32
+ name: "Lionel Messi",
33
33
  is_admin: true
34
34
  }
35
- user_password = '123456'
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('/repositories/with_agent', repository)
40
+ response = client.post("/repositories/with_agent", repository)
41
41
  if response.result.success?
42
- repository = client.repositories.find { |r| r['repo_code'] == 'XYZ' }
42
+ repository = client.repositories.find { |r| r["repo_code"] == "XYZ" }
43
43
  ap repository
44
- ap client.delete(repository['uri'])
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('users', user, { password: user_password })
50
+ response = client.post("users", user, {password: user_password})
51
51
  if response.result.success?
52
- user = client.users.find { |r| r['username'] == 'lmessi' }
52
+ user = client.users.find { |r| r["username"] == "lmessi" }
53
53
  ap user
54
- ap client.delete user['uri']
54
+ ap client.delete user["uri"]
55
55
  else
56
56
  ap response.parsed
57
57
  end
@@ -1,16 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
4
- require 'awesome_print'
5
- require 'archivesspace/client'
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: 'http://sandbox.archivesspace.org/api',
11
- base_repo: '',
12
- username: 'admin',
13
- password: 'admin',
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('version').body
21
+ puts client.get("version").body
@@ -1,16 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
4
- require 'awesome_print'
5
- require 'archivesspace/client'
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: 'http://sandbox.archivesspace.org/api',
11
- base_repo: '',
12
- username: 'admin',
13
- password: 'admin',
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,19 +20,19 @@ config = ArchivesSpace::Configuration.new(
20
20
  client = ArchivesSpace::Client.new(config).login
21
21
 
22
22
  user_data = {
23
- username: 'bde',
24
- name: 'BDE',
23
+ username: "bde",
24
+ name: "BDE",
25
25
  is_admin: false
26
26
  }
27
27
 
28
28
  client.post(
29
- 'users',
29
+ "users",
30
30
  ArchivesSpace::Template.process(:user, user_data),
31
- { password: '123456' }
31
+ {password: "123456"}
32
32
  )
33
33
 
34
34
  users_with_roles = {
35
- 'bde' => ['repository-basic-data-entry']
35
+ "bde" => ["repository-basic-data-entry"]
36
36
  }
37
37
 
38
38
  begin
data/exe/asclient CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'bundler/setup'
5
- require 'archivesspace/client'
4
+ require "bundler/setup"
5
+ require "archivesspace/client"
6
6
 
7
7
  Dry::CLI.new(ArchivesSpace::Client::CLI).call
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'aruba/cucumber'
4
- require 'json_spec/cucumber'
5
- require 'capybara_discoball'
3
+ require "aruba/cucumber"
4
+ require "json_spec/cucumber"
5
+ require "capybara_discoball"
6
6
 
7
7
  def last_json
8
8
  last_command_started.output
@@ -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 'Execute an API request'
8
+ desc "Execute an API request"
9
9
 
10
- argument :type, required: true, values: %i[get post put delete], desc: 'API request type'
11
- argument :path, required: true, desc: 'API request path'
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 :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)'
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: '{}', params: '{}', **)
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 = type.to_sym
25
+ type = type.to_sym
26
26
  payload = JSON.parse(payload, symbolize_names: true)
27
- params = JSON.parse(params, symbolize_names: true)
27
+ params = JSON.parse(params, symbolize_names: true)
28
28
 
29
29
  response = case type
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
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 'Print ArchivesSpace Client version'
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('ASCLIENT_CFG', File.join(ENV['HOME'], '.asclientrc'))
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 'exec', Exec, aliases: ['e', '-e']
21
- register 'version', Version, aliases: ['v', '-v', '--version']
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 :config
8
+ attr_reader :config
9
9
 
10
10
  def initialize(config = Configuration.new)
11
- raise 'Invalid configuration object' unless config.is_a? ArchivesSpace::Configuration
11
+ raise "Invalid configuration object" unless config.is_a? ArchivesSpace::Configuration
12
12
 
13
13
  @config = config
14
- @token = nil
14
+ @token = nil
15
15
  end
16
16
 
17
17
  def backend_version
18
- get 'version'
18
+ get "version"
19
19
  end
20
20
 
21
21
  def get(path, options = {})
22
- request 'GET', path, options
22
+ request "GET", path, options
23
23
  end
24
24
 
25
25
  def post(path, payload, params = {})
26
- request 'POST', path, { body: payload, query: params }
26
+ request "POST", path, {body: payload, query: params}
27
27
  end
28
28
 
29
29
  def put(path, payload, params = {})
30
- request 'PUT', path, { body: payload, query: params }
30
+ request "PUT", path, {body: payload, query: params}
31
31
  end
32
32
 
33
33
  def delete(path)
34
- request 'DELETE', path
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 StandardError
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] = { 'X-ArchivesSpace-Session' => token } if token
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: 'http://localhost:8089',
8
- base_repo: '',
7
+ base_uri: "http://localhost:8089",
8
+ base_repo: "",
9
9
  debug: false,
10
- username: 'admin',
11
- password: 'admin',
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.keys.include? property
22
+ next unless defaults.key?(property)
22
23
 
23
24
  instance_variable_set("@#{property}", value)
24
25
  self.class.send(:attr_accessor, property)
@@ -13,14 +13,14 @@ module ArchivesSpace
13
13
  archival_objects
14
14
  digital_objects
15
15
  groups
16
- repositiories
16
+ repositories
17
17
  resources
18
18
  subjects
19
19
  users
20
20
  ]
21
21
 
22
22
  ENDPOINTS.each do |endpoint|
23
- method_name = endpoint.split('/').last # remove prefix
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?('results')
40
- results = result.parsed['results']
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,25 +10,27 @@ module ArchivesSpace
10
10
  delete: {},
11
11
  get: {},
12
12
  post: {
13
- 'Content-Type' => 'application/json',
14
- 'Content-Length' => 'nnnn'
13
+ "Content-Type" => "application/json",
14
+ "Content-Length" => "nnnn"
15
15
  },
16
16
  put: {
17
- 'Content-Type' => 'application/json',
18
- 'Content-Length' => 'nnnn'
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 = 'GET', path = '', options = {})
25
- @config = config
26
- @method = method.downcase.to_sym
27
- @path = path.gsub(%r{^/+}, '')
28
- @options = options
29
- @options[:headers] = options[:headers] ? default_headers(@method).merge(options[:headers]) : default_headers(@method)
30
- @options[:verify] = config.verify_ssl
31
- @options[:query] = {} unless options.key? :query
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
+ @options[:headers] =
30
+ options[:headers] ? default_headers(@method).merge(options[:headers]) : default_headers(@method)
31
+ @options[:verify] = config.verify_ssl
32
+ @options[:timeout] = config.timeout
33
+ @options[:query] = {} unless options.key? :query
32
34
 
33
35
  self.class.debug_output($stdout) if @config.debug
34
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 = result
9
- @parsed = result.parsed_response
10
- @body = result.body
11
- @headers = result.headers
12
- @status = result.response
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['uri'])}").parsed
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['member_usernames'].include?(user)
19
- unless roles.include? group['group_code']
20
- group['member_usernames'].delete user
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['group_code']
25
- group['member_usernames'] << user
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['uri'])}", group.to_json)
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 = config.username
40
- password = config.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('POST', "/users/#{username}/login", { query: { password: password } })
44
- unless result.parsed['session']
45
- raise ConnectionError, "Failed to connect to ArchivesSpace backend as #{username} #{password}"
43
+ result = request("POST", "/users/#{username}/login", {query: {password: password}})
44
+ unless result.parsed["session"]
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['session']
49
+ @token = result.parsed["session"]
50
50
  self
51
51
  end
52
52
 
53
53
  def password_reset(username, password)
54
- user = all('users').find { |u| u['username'] == username }
54
+ user = all("users").find { |u| u["username"] == username }
55
55
  raise RequestError, user.status unless user
56
56
 
57
- post(user['uri'], user.to_json, { password: password })
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('/').last
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, '*.erb')
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).gsub(/\n+/, "\n")
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
- 'ARCHIVESSPACE_CLIENT_TEMPLATES_PATH',
22
- File.join(File.dirname(File.expand_path(__FILE__)), 'templates')
21
+ "ARCHIVESSPACE_CLIENT_TEMPLATES_PATH",
22
+ File.join(File.dirname(File.expand_path(__FILE__)), "templates")
23
23
  )
24
24
  end
25
25
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ArchivesSpace
4
4
  class Client
5
- VERSION = '0.1.10'
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
@@ -1,34 +1,34 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/cli'
4
- require 'httparty'
5
- require 'json'
6
- require 'nokogiri'
3
+ require "dry/cli"
4
+ require "httparty"
5
+ require "json"
6
+ require "nokogiri"
7
7
 
8
8
  # mixins required first
9
- require 'archivesspace/client/pagination'
10
- require 'archivesspace/client/task'
9
+ require "archivesspace/client/pagination"
10
+ require "archivesspace/client/task"
11
11
 
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'
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 'archivesspace/client/cli/exec'
21
- require 'archivesspace/client/cli/version'
22
- require 'archivesspace/client/cli' # load the registry last
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 < RuntimeError; end
27
+ class ContextError < RuntimeError; end
28
28
 
29
29
  class RepositoryIdError < RuntimeError; end
30
30
 
31
- class ParamsError < RuntimeError; end
31
+ class ParamsError < RuntimeError; end
32
32
 
33
- class RequestError < RuntimeError; end
33
+ class RequestError < RuntimeError; end
34
34
  end
@@ -1,87 +1,87 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
5
  describe ArchivesSpace::Client do
6
6
  let(:client) { ArchivesSpace::Client.new }
7
- let(:login) { -> { client.login } }
7
+ let(:login) { -> { client.login } }
8
8
 
9
- describe 'Configuration' do
10
- it 'will use the default configuration if none is provided' do
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 '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)
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 'will allow a configuration object to be provided' do
20
- client = ArchivesSpace::Client.new(ArchivesSpace::Configuration.new({ base_uri: CUSTOM_BASE_URI }))
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 'Repository scoping' do
26
- it 'will set the repository with an integer id' do
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 'repositories/2'
29
+ expect(client.config.base_repo).to eq "repositories/2"
30
30
  end
31
31
 
32
- it 'will set the repository with a string id cast to integer' do
32
+ it "will set the repository with a string id cast to integer" do
33
33
  client = ArchivesSpace::Client.new
34
- client.repository '2'
35
- expect(client.config.base_repo).to eq 'repositories/2'
34
+ client.repository "2"
35
+ expect(client.config.base_repo).to eq "repositories/2"
36
36
  end
37
37
 
38
- it 'will fail if the id cannot be cast to integer' do
38
+ it "will fail if the id cannot be cast to integer" do
39
39
  client = ArchivesSpace::Client.new
40
- expect { client.repository('xyz') }.to raise_error(
40
+ expect { client.repository("xyz") }.to raise_error(
41
41
  ArchivesSpace::RepositoryIdError
42
42
  )
43
43
  end
44
44
 
45
- it 'will use the global repo if repository is passed nil' do
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 'will use the global repo when the method is called' do
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 'Pagination' do
61
- it 'will have a method for defined paginated record types' do
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 'will have a method for defined paginated record types with multipart path' do
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 'Version information' do
77
- it 'has a version number' do
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 'can retrieve the backend version info' do
82
- VCR.use_cassette('backend_version') do
81
+ it "can retrieve the backend version info" do
82
+ VCR.use_cassette("backend_version") do
83
83
  login.call
84
- response = client.get 'version'
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 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
5
  describe ArchivesSpace::Configuration do
6
- it 'uses the default profile for configuration settings' do
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 'allows configuration settings to be provided' do
11
+ it "allows configuration settings to be provided" do
12
12
  config = ArchivesSpace::Configuration.new({
13
- base_uri: CUSTOM_BASE_URI
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 'allows the configuration properties to be updated' do
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 'ignores unrecognized configuration properties' do
25
- config = ArchivesSpace::Configuration.new({ xyz: 123 })
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 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
5
  describe ArchivesSpace::Template do
6
- it 'can list the default templates' do
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 'can change the path when template envvar is set' do
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['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')
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 'can process a template' do
22
- data = { repo_code: 'ABC', name: 'ABC Archive', agent_contact_name: 'ABC Admin' }
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['repository']['repo_code']).to eq data[:repo_code]
24
+ expect(json["repository"]["repo_code"]).to eq data[:repo_code]
25
25
  end
26
- end
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('../lib', __dir__)
4
- require 'archivesspace/client'
5
- require 'vcr'
6
- require 'webmock/rspec'
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 = 'http://localhost:8089'
10
- CUSTOM_BASE_URI = 'https://archives.university.edu/api'
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 = 'spec/fixtures/cassettes'
13
+ c.cassette_library_dir = "spec/fixtures/cassettes"
14
14
  c.hook_into :webmock
15
- c.default_cassette_options = { record: :once }
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.1.10
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: 2021-10-04 00:00:00.000000000 Z
11
+ date: 2022-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aruba
@@ -122,6 +122,34 @@ dependencies:
122
122
  - - '='
123
123
  - !ruby/object:Gem::Version
124
124
  version: 3.6.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
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'
125
153
  - !ruby/object:Gem::Dependency
126
154
  name: vcr
127
155
  requirement: !ruby/object:Gem::Requirement
@@ -213,8 +241,11 @@ executables: []
213
241
  extensions: []
214
242
  extra_rdoc_files: []
215
243
  files:
244
+ - ".github/workflows/ci.yml"
245
+ - ".github/workflows/publish.yml"
216
246
  - ".gitignore"
217
247
  - ".rspec"
248
+ - ".rubocop.yml"
218
249
  - ".travis.yml"
219
250
  - Gemfile
220
251
  - LICENSE.txt
@@ -270,16 +301,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
301
  - !ruby/object:Gem::Version
271
302
  version: '0'
272
303
  requirements: []
273
- rubygems_version: 3.1.6
304
+ rubygems_version: 3.3.21
274
305
  signing_key:
275
306
  specification_version: 4
276
307
  summary: Interact with ArchivesSpace via the API.
277
- test_files:
278
- - features/exec.feature
279
- - features/support/setup.rb
280
- - features/version.feature
281
- - spec/archivesspace/client_spec.rb
282
- - spec/archivesspace/configuration_spec.rb
283
- - spec/archivesspace/templates_spec.rb
284
- - spec/fixtures/cassettes/backend_version.yml
285
- - spec/spec_helper.rb
308
+ test_files: []