collectionspace-client 0.3.0 → 0.14.1

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: e63c182e9731f5868556d805eed65b8c85d32789363c90f4ac763cff06e2b693
4
- data.tar.gz: 00d6e5804a0131adad73d28eee0dd32a95dd9b9a05346bf4e1374d54bfa1f2b5
3
+ metadata.gz: 89651eb1e87693f52f835cbe34eccc510f40888db54696a41082ae114a084817
4
+ data.tar.gz: e3c161e2a64848a1f0065e18da8aa23ad6117995daf62538cf5437bc0192cfc6
5
5
  SHA512:
6
- metadata.gz: fa76fc6c2b8f1761c01dc195198445eba31698d0d530d0993c5fa64ceb1ace2fbc44153a7d8c4dd29fe3d272463e1f82d3185f5a8d46ddfbec9252f0b8ec0ca5
7
- data.tar.gz: b67294a65c42c52804af6e429f45e2ea9bcb1a5e4ea4d78fb3da0cfeafb8018221d835a29b81c48fea6e43b287b88e549e6bfd746f124a9814c1079fdae3abc7
6
+ metadata.gz: 7d9d9989ff3272bffe9fc99c19036e72004b7e672bc3d02ce5556b69bb478a441a78768d394685534ba83144d76054903bac35fa4f715c50cff32b838e60132c
7
+ data.tar.gz: 7bea83ddcadf1aa7019e196c8ede59cd9e9ffd6fdd9b23a90ff7d0f89666122cb6c865a0b422287cb8a04d4032718e493e48f23b6356d65039a1bde00626e53b
@@ -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: collectionspace-client
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  *.gem
2
2
  *.swp
3
3
  /.bundle/
4
+ /.vscode
4
5
  /.yardoc
5
6
  /Gemfile.lock
6
7
  /_yardoc/
@@ -9,5 +10,8 @@
9
10
  /examples/my_*.rb
10
11
  /pkg/
11
12
  /spec/reports/
13
+ .byebug_history
14
+ .rspec_status
12
15
  /tmp/
13
16
  collectionobject.rb
17
+ coverage
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.4
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in collectionspace-client.gemspec
data/README.md CHANGED
@@ -4,13 +4,13 @@ CollectionSpace API client.
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
7
+ Add this line to your application's Gemfile (replace `$VERSION` with an available tag):
8
8
 
9
9
  ```ruby
10
- gem 'collectionspace-client'
10
+ gem 'collectionspace-client', tag: $VERSION, git: 'https://github.com/collectionspace/collectionspace-client.git'
11
11
  ```
12
12
 
13
- And then execute `bundle install`, or install it yourself as: `gem install collectionspace-client`.
13
+ And then execute `bundle install`.
14
14
 
15
15
  ## Usage
16
16
 
@@ -32,19 +32,16 @@ To run the tests:
32
32
  bundle exec rake
33
33
  ```
34
34
 
35
- ## Publishing
36
-
37
- Bump version in `lib/collectionspace/client/version.rb` then:
35
+ ## Releasing
38
36
 
39
37
  ```bash
40
- VERSION=0.3.0
41
- git add .
42
- git commit -m "Bump version: v${VERSION}"
43
- git push origin master
44
- git tag v$VERSION
45
- git push --tags
46
- gem build collectionspace-client
47
- gem push collectionspace-client-$VERSION.gem
38
+ gem install gem-release
39
+ # https://github.com/svenfuchs/gem-release#gem-bump
40
+ gem bump --version $VERSION --tag
41
+ # i.e.
42
+ gem bump --version minor --tag --pretend # dryrun
43
+ gem bump --version minor --tag # do it for real
44
+ # PR and merge will publish new version
48
45
  ```
49
46
 
50
47
  ## Contributing
data/Rakefile CHANGED
@@ -1,6 +1,47 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
5
+ require 'base64'
6
+ require 'collectionspace/client'
3
7
 
4
8
  RSpec::Core::RakeTask.new(:spec)
5
9
 
6
10
  task default: :spec
11
+
12
+ task :version do
13
+ puts CollectionSpace::Client::VERSION
14
+ end
15
+
16
+ namespace :cli do
17
+ desc "Update a user's password: requires an Admin level account to perform the update"
18
+ task :update_password, [:endpoint, :admin, :password, :user, :new_password] do |_t, args|
19
+ endpoint = args[:endpoint]
20
+ admin = args[:admin]
21
+ password = args[:password]
22
+ user = args[:user]
23
+ new_password = args[:new_password]
24
+
25
+ client = CollectionSpace::Client.new(
26
+ CollectionSpace::Configuration.new(
27
+ base_uri: endpoint,
28
+ username: admin,
29
+ password: password
30
+ )
31
+ )
32
+
33
+ payload = <<~XML
34
+ <ns2:accounts_common xmlns:ns2="http://collectionspace.org/services/account">
35
+ <userId>#{user}</userId>
36
+ <password>#{Base64.encode64(new_password).chomp}</password>
37
+ </ns2:accounts_common>
38
+ XML
39
+
40
+ client.all('accounts').each do |account|
41
+ if account['email'] == user
42
+ puts client.put(account['uri'], payload).parsed
43
+ break
44
+ end
45
+ end
46
+ end
47
+ end
data/bin/console ADDED
@@ -0,0 +1,26 @@
1
+ #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ Bundler.require(:tools)
6
+
7
+ require_relative '../lib/collectionspace/client'
8
+ require 'irb'
9
+
10
+ module CollectionSpace
11
+ ::CS = CollectionSpace # alias only in console to minimize typing
12
+
13
+ module_function
14
+
15
+ def coredev
16
+ CollectionSpace::Client.new(
17
+ CollectionSpace::Configuration.new(
18
+ base_uri: 'https://core.dev.collectionspace.org/cspace-services',
19
+ username: 'admin@core.collectionspace.org',
20
+ password: 'Administrator'
21
+ )
22
+ )
23
+ end
24
+ end
25
+
26
+ IRB.start(__FILE__)
data/bin/rspec ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")
@@ -23,9 +23,11 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_development_dependency 'awesome_print'
25
25
  spec.add_development_dependency 'bundler'
26
+ spec.add_development_dependency 'pry'
26
27
  spec.add_development_dependency 'rake', '~> 10.0'
27
28
  spec.add_development_dependency 'rspec'
28
29
  spec.add_development_dependency 'rubocop'
30
+ spec.add_development_dependency 'simplecov', '~> 0.21'
29
31
  spec.add_development_dependency 'vcr'
30
32
  spec.add_development_dependency 'webmock'
31
33
  end
data/examples/demo.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
2
4
  require 'awesome_print'
3
5
  require 'collectionspace/client'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
2
4
  require 'awesome_print'
3
5
  require 'collectionspace/client'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
2
4
  require 'collectionspace/client'
3
5
 
@@ -0,0 +1,178 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
4
+ require 'awesome_print'
5
+ require 'collectionspace/client'
6
+
7
+ client = CollectionSpace::Client.new(
8
+ CollectionSpace::Configuration.new(
9
+ base_uri: 'https://core.dev.collectionspace.org/cspace-services',
10
+ username: 'admin@core.collectionspace.org',
11
+ password: 'Administrator'
12
+ )
13
+ )
14
+
15
+ # https://github.com/collectionspace/Tools/blob/master/scripts/install_report_records.sh
16
+ # https://github.com/collectionspace/Tools/blob/master/scripts/create-report-records.sh
17
+
18
+ STANDARD_REPORTS = [
19
+ {
20
+ name: 'Acquisition Summary',
21
+ notes: 'An acquisition summary report. Runs on a single record only.',
22
+ doctype: 'Acquisition',
23
+ supports_single_doc: 'true',
24
+ supports_doc_list: 'false',
25
+ supports_group: 'false',
26
+ supports_no_context: 'false',
27
+ filename: 'acq_basic.jrxml',
28
+ mimetype: 'application/pdf'
29
+ },
30
+ {
31
+ name: 'Acquisition Basic List',
32
+ notes: 'Catalog info for objects related to an acquisition record. Runs on a single record only.',
33
+ doctype: 'Acquisition',
34
+ supports_single_doc: 'true',
35
+ supports_doc_list: 'false',
36
+ supports_group: 'false',
37
+ supports_no_context: 'false',
38
+ filename: 'Acq_List_Basic.jrxml',
39
+ mimetype: 'application/pdf'
40
+ },
41
+ {
42
+ name: 'Condition Check Basic List',
43
+ notes: 'Catalog info for objects related to a condition check record. Runs on a single record only.',
44
+ doctype: 'Conditioncheck',
45
+ supports_single_doc: 'true',
46
+ supports_doc_list: 'false',
47
+ supports_group: 'false',
48
+ supports_no_context: 'false',
49
+ filename: 'CC_List_Basic.jrxml',
50
+ mimetype: 'application/pdf'
51
+ },
52
+ {
53
+ name: 'Exhibition Basic List',
54
+ notes: 'Catalog info for objects related to a exhibition record. Runs on a single record only.',
55
+ doctype: 'Exhibition',
56
+ supports_single_doc: 'true',
57
+ supports_doc_list: 'false',
58
+ supports_group: 'false',
59
+ supports_no_context: 'false',
60
+ filename: 'Exhibition_List_Basic.jrxml',
61
+ mimetype: 'application/pdf'
62
+ },
63
+ {
64
+ name: 'Group Basic List',
65
+ notes: 'Catalog info for objects related to a group record. Runs on a single record only.',
66
+ doctype: 'Group',
67
+ supports_single_doc: 'true',
68
+ supports_doc_list: 'false',
69
+ supports_group: 'false',
70
+ supports_no_context: 'false',
71
+ filename: 'Group_List_Basic.jrxml',
72
+ mimetype: 'application/pdf'
73
+ },
74
+ {
75
+ name: 'Loan In Basic List',
76
+ notes: 'Catalog info for objects related to a loan in record. Runs on a single record only.',
77
+ doctype: 'Loanin',
78
+ supports_single_doc: 'true',
79
+ supports_doc_list: 'false',
80
+ supports_group: 'false',
81
+ supports_no_context: 'false',
82
+ filename: 'LoansIn_List_Basic.jrxml',
83
+ mimetype: 'application/pdf'
84
+ },
85
+ {
86
+ name: 'Loan Out Basic List',
87
+ notes: 'Catalog info for objects related to a loan out record. Runs on a single record only.',
88
+ doctype: 'Loanout',
89
+ supports_single_doc: 'true',
90
+ supports_doc_list: 'false',
91
+ supports_group: 'false',
92
+ supports_no_context: 'false',
93
+ filename: 'LoansOut_List_Basic.jrxml',
94
+ mimetype: 'application/pdf'
95
+ },
96
+ {
97
+ name: 'Acquisition Ethnographic Object List',
98
+ notes: 'Core acquisition report. Runs on a single record only.',
99
+ doctype: 'Acquisition',
100
+ supports_single_doc: 'true',
101
+ supports_doc_list: 'false',
102
+ supports_group: 'false',
103
+ supports_no_context: 'false',
104
+ filename: 'coreAcquisition.jrxml',
105
+ mimetype: 'application/pdf'
106
+ },
107
+ {
108
+ name: 'Group Object Ethnographic Object List',
109
+ notes: 'Core group object report. Runs on a single record only.',
110
+ doctype: 'Group',
111
+ supports_single_doc: 'true',
112
+ supports_doc_list: 'false',
113
+ supports_group: 'false',
114
+ supports_no_context: 'false',
115
+ filename: 'coreGroupObject.jrxml',
116
+ mimetype: 'application/pdf'
117
+ },
118
+ {
119
+ name: 'Intake Ethnographic Object List',
120
+ notes: 'Core intake report. Runs on a single record only.',
121
+ doctype: 'Intake',
122
+ supports_single_doc: 'true',
123
+ supports_doc_list: 'false',
124
+ supports_group: 'false',
125
+ supports_no_context: 'false',
126
+ filename: 'coreIntake.jrxml',
127
+ mimetype: 'application/pdf'
128
+ },
129
+ {
130
+ name: 'Loan In Ethnographic Object List',
131
+ notes: 'Core loan in report. Runs on a single record only.',
132
+ doctype: 'Loanin',
133
+ supports_single_doc: 'true',
134
+ supports_doc_list: 'false',
135
+ supports_group: 'false',
136
+ supports_no_context: 'false',
137
+ filename: 'coreLoanIn.jrxml',
138
+ mimetype: 'application/pdf'
139
+ },
140
+ {
141
+ name: 'Loan Out Ethnographic Object List',
142
+ notes: 'Core loan out report. Runs on a single record only.',
143
+ doctype: 'Loanout',
144
+ supports_single_doc: 'true',
145
+ supports_doc_list: 'false',
146
+ supports_group: 'false',
147
+ supports_no_context: 'false',
148
+ filename: 'coreLoanOut.jrxml',
149
+ mimetype: 'application/pdf'
150
+ },
151
+ {
152
+ name: 'Object Exit Ethnographic Object List',
153
+ notes: 'Core object exit report. Runs on a single record only.',
154
+ doctype: 'ObjectExit',
155
+ supports_single_doc: 'true',
156
+ supports_doc_list: 'false',
157
+ supports_group: 'false',
158
+ supports_no_context: 'false',
159
+ filename: 'coreObjectExit.jrxml',
160
+ mimetype: 'application/pdf'
161
+ },
162
+ {
163
+ name: 'Systematic Inventory',
164
+ notes: 'Generate a checklist for performing an inventory on a range of storage locations. Runs on all records, using the provided start and end locations.',
165
+ doctype: 'Locationitem',
166
+ supports_single_doc: 'false',
167
+ supports_doc_list: 'false',
168
+ supports_group: 'false',
169
+ supports_no_context: 'true',
170
+ filename: 'systematicInventory.jrxml',
171
+ mimetype: 'application/pdf'
172
+ }
173
+ ]
174
+
175
+ STANDARD_REPORTS.each do |report|
176
+ response = client.add_report(report)
177
+ puts response.inspect
178
+ end
data/examples/search.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
2
4
  require 'awesome_print'
3
5
  require 'collectionspace/client'
@@ -12,10 +14,21 @@ client = CollectionSpace::Client.new(config)
12
14
 
13
15
  search_args = {
14
16
  path: 'groups',
15
- type: 'groups_common',
17
+ namespace: 'groups_common',
16
18
  field: 'title',
17
- expression: "ILIKE '%DTS 001%'"
19
+ expression: "ILIKE '%D%'"
18
20
  }
19
21
 
20
- response = client.search(CollectionSpace::Search.new.from_hash(search_args))
21
- ap response.parsed['abstract_common_list'] if response.result.success?
22
+ puts 'Search: %D'
23
+ response = client.search(
24
+ CollectionSpace::Search.new.from_hash(search_args),
25
+ { sortBy: CollectionSpace::Search::DEFAULT_SORT }
26
+ )
27
+ if response.result.success?
28
+ response.parsed['abstract_common_list']['list_item'].map do |i|
29
+ puts i['uri']
30
+ end
31
+ end
32
+
33
+ puts 'Object and authority term searches have been moved to spec.'
34
+ puts 'See helpers_spec.rb examples describing find'
@@ -1,33 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
4
- require 'awesome_print'
5
- require 'base64'
6
- require 'collectionspace/client'
7
-
8
- CS_CFG_URL = ENV.fetch('CS_CFG_URL', 'https://core.dev.collectionspace.org/cspace-services')
9
- CS_CFG_USER = ENV.fetch('CS_CFG_USER', 'admin@core.collectionspace.org')
10
- CS_CFG_PASS = ENV.fetch('CS_CFG_PASS', 'Administrator')
11
- CS_UPD_USER = ENV.fetch('CS_UPD_USER', 'admin@core.collectionspace.org')
12
- CS_UPD_PASS = Base64.encode64(ENV.fetch('CS_UPD_PASS', 'Administrator')).chomp
13
-
14
- client = CollectionSpace::Client.new(
15
- CollectionSpace::Configuration.new(
16
- base_uri: CS_CFG_URL,
17
- username: CS_CFG_USER,
18
- password: CS_CFG_PASS
19
- )
20
- )
21
-
22
- PAYLOAD = <<~XML
23
- <ns2:accounts_common xmlns:ns2="http://collectionspace.org/services/account">
24
- <userId>#{CS_UPD_USER}</userId>
25
- <password>#{CS_UPD_PASS}</password>
26
- </ns2:accounts_common>
27
- XML
28
-
29
- client.all('accounts').each do |item|
30
- next unless item['email'] == CS_UPD_USER
31
-
32
- ap client.put(item['uri'], PAYLOAD).parsed
33
- end
3
+ puts 'Update password has been moved to Rake task: `cli:update_password[args...]`'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CollectionSpace
2
4
  # CollectionSpace client
3
5
  class Client
@@ -21,9 +23,9 @@ module CollectionSpace
21
23
  request 'POST', path, { body: payload }.merge(options)
22
24
  end
23
25
 
24
- def put(path, payload)
26
+ def put(path, payload, options = {})
25
27
  check_payload(payload)
26
- request 'PUT', path, body: payload
28
+ request 'PUT', path, { body: payload }.merge(options)
27
29
  end
28
30
 
29
31
  def delete(path)
@@ -1,25 +1,26 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CollectionSpace
2
4
  # CollectionSpace configuration
3
5
  class Configuration
4
- def defaults
5
- {
6
- base_uri: nil,
7
- username: nil,
8
- password: nil,
9
- page_size: 25,
10
- include_deleted: false,
11
- throttle: 0,
12
- verify_ssl: true
13
- }
14
- end
6
+ DEFAULTS = {
7
+ base_uri: nil,
8
+ username: nil,
9
+ password: nil,
10
+ page_size: 25,
11
+ include_deleted: false,
12
+ throttle: 0,
13
+ verify_ssl: true
14
+ }.freeze
15
+
16
+ attr_accessor :base_uri, :username, :password, :page_size, :include_deleted, :throttle, :verify_ssl
15
17
 
16
18
  def initialize(settings = {})
17
- settings = defaults.merge(settings)
19
+ settings = DEFAULTS.merge(settings)
18
20
  settings.each do |property, value|
19
- next unless defaults.key? property
21
+ next unless DEFAULTS.key?(property)
20
22
 
21
23
  instance_variable_set("@#{property}", value)
22
- self.class.send(:attr_accessor, property)
23
24
  end
24
25
  end
25
26
  end