collectionspace-client 0.3.0 → 0.15.0

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.git-blame-ignore-revs +8 -0
  3. data/.github/workflows/ci.yml +30 -0
  4. data/.github/workflows/publish.yml +42 -0
  5. data/.gitignore +6 -0
  6. data/.rubocop.yml +4 -8
  7. data/.ruby-version +1 -0
  8. data/Gemfile +3 -1
  9. data/README.md +11 -14
  10. data/Rakefile +44 -2
  11. data/bin/console +26 -0
  12. data/bin/rspec +29 -0
  13. data/collectionspace-client.gemspec +26 -23
  14. data/examples/batches.rb +50 -0
  15. data/examples/demo.rb +10 -8
  16. data/examples/media_with_external_file.rb +11 -9
  17. data/examples/purge_empty_vocabs.rb +10 -8
  18. data/examples/reports.rb +45 -0
  19. data/examples/reset_media_blob.rb +35 -0
  20. data/examples/search.rb +25 -12
  21. data/examples/update_password.rb +1 -31
  22. data/lib/collectionspace/client/batch.rb +55 -0
  23. data/lib/collectionspace/client/client.rb +19 -6
  24. data/lib/collectionspace/client/configuration.rb +16 -14
  25. data/lib/collectionspace/client/helpers.rb +197 -15
  26. data/lib/collectionspace/client/refname.rb +114 -0
  27. data/lib/collectionspace/client/report.rb +180 -0
  28. data/lib/collectionspace/client/request.rb +12 -9
  29. data/lib/collectionspace/client/response.rb +14 -3
  30. data/lib/collectionspace/client/search.rb +9 -5
  31. data/lib/collectionspace/client/service.rb +204 -0
  32. data/lib/collectionspace/client/template.rb +26 -0
  33. data/lib/collectionspace/client/templates/batch.xml.erb +18 -0
  34. data/lib/collectionspace/client/templates/reindex_by_csids.xml.erb +10 -0
  35. data/lib/collectionspace/client/templates/reindex_by_doctype.xml.erb +5 -0
  36. data/lib/collectionspace/client/templates/reindex_full_text.xml.erb +51 -0
  37. data/lib/collectionspace/client/templates/report.xml.erb +16 -0
  38. data/lib/collectionspace/client/templates/reset_media_blob.xml.erb +6 -0
  39. data/lib/collectionspace/client/version.rb +3 -1
  40. data/lib/collectionspace/client.rb +25 -12
  41. metadata +68 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e63c182e9731f5868556d805eed65b8c85d32789363c90f4ac763cff06e2b693
4
- data.tar.gz: 00d6e5804a0131adad73d28eee0dd32a95dd9b9a05346bf4e1374d54bfa1f2b5
3
+ metadata.gz: d797561c0b44c79ce0bda224d05ff05de6fa7c932b2c33d4a9c888116c6d6fbb
4
+ data.tar.gz: bfbd46caa314f5fc6620b468e14e262983f3f52a444622ef55669c60ad5c4f84
5
5
  SHA512:
6
- metadata.gz: fa76fc6c2b8f1761c01dc195198445eba31698d0d530d0993c5fa64ceb1ace2fbc44153a7d8c4dd29fe3d272463e1f82d3185f5a8d46ddfbec9252f0b8ec0ca5
7
- data.tar.gz: b67294a65c42c52804af6e429f45e2ea9bcb1a5e4ea4d78fb3da0cfeafb8018221d835a29b81c48fea6e43b287b88e549e6bfd746f124a9814c1079fdae3abc7
6
+ metadata.gz: 697f5207854022997a0acf1e2249113c763447a5597677d4b7f7b157244467a2c0bee0d163d152ee2191950e41c9478a21443f967087c87e85a765c137542865
7
+ data.tar.gz: 71d59341de8048599691df601042915c803c10c6710982c76eeda366684aab1ba27ce694a285bcf349d9de08faba78d4951838114ff96059f24c417dc6b9f1a8
@@ -0,0 +1,8 @@
1
+ # Appease standard
2
+ 63444da90ce50afd5d282c6cfb5ca6dc3210be7d
3
+ # Lint/format
4
+ 0dc6263edaed69d0d472626974a1317c059b3337
5
+ # Make standard happy
6
+ 5cbdb2d41997f05e6cbad814c11e2893706ac152
7
+ # Use standard for linting
8
+ e5ba9f76a333609734079c3ec6102c2cbe4974b7
@@ -0,0 +1,30 @@
1
+ name: CI
2
+ on: [pull_request]
3
+
4
+ jobs:
5
+ tests:
6
+ name: Tests
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ matrix:
10
+ ruby-version: ['3.2', '3.1', '3.0']
11
+ steps:
12
+ - name: Checkout code
13
+ uses: actions/checkout@v3
14
+
15
+ - name: Set up Ruby ${{ matrix.ruby-version }}
16
+ uses: ruby/setup-ruby@v1
17
+ with:
18
+ bundler-cache: true
19
+ ruby-version: ${{ matrix.ruby-version }}
20
+
21
+ - name: Install dependencies
22
+ run: bundle install
23
+
24
+ - name: Lint
25
+ run: |
26
+ bundle exec standardrb
27
+
28
+ - name: Run tests
29
+ run: |
30
+ 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: collectionspace-client
data/.gitignore CHANGED
@@ -1,6 +1,9 @@
1
1
  *.gem
2
+ *.jpg
3
+ *.pdf
2
4
  *.swp
3
5
  /.bundle/
6
+ /.vscode
4
7
  /.yardoc
5
8
  /Gemfile.lock
6
9
  /_yardoc/
@@ -9,5 +12,8 @@
9
12
  /examples/my_*.rb
10
13
  /pkg/
11
14
  /spec/reports/
15
+ .byebug_history
16
+ .rspec_status
12
17
  /tmp/
13
18
  collectionobject.rb
19
+ coverage
data/.rubocop.yml CHANGED
@@ -1,8 +1,4 @@
1
- # .rubocop.yml
2
- AllCops:
3
- Exclude:
4
- - '*.gemspec'
5
- - '*.rake'
6
- Metrics/BlockLength:
7
- Exclude:
8
- - !ruby/regexp /_spec.rb/
1
+ require: standard
2
+
3
+ inherit_gem:
4
+ standard: config/base.yml
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.1
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in collectionspace-client.gemspec
4
6
  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 --pretend # dryrun
43
+ gem bump --version minor # 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,48 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "base64"
6
+ require "collectionspace/client"
7
+ require "standard/rake"
3
8
 
4
9
  RSpec::Core::RakeTask.new(:spec)
5
10
 
6
11
  task default: :spec
12
+
13
+ task :version do
14
+ puts CollectionSpace::Client::VERSION
15
+ end
16
+
17
+ namespace :cli do
18
+ desc "Update a user's password: requires an Admin level account to perform the update"
19
+ task :update_password, [:endpoint, :admin, :password, :user, :new_password] do |_t, args|
20
+ endpoint = args[:endpoint]
21
+ admin = args[:admin]
22
+ password = args[:password]
23
+ user = args[:user]
24
+ new_password = args[:new_password]
25
+
26
+ client = CollectionSpace::Client.new(
27
+ CollectionSpace::Configuration.new(
28
+ base_uri: endpoint,
29
+ username: admin,
30
+ password: password
31
+ )
32
+ )
33
+
34
+ payload = <<~XML
35
+ <ns2:accounts_common xmlns:ns2="http://collectionspace.org/services/account">
36
+ <userId>#{user}</userId>
37
+ <password>#{Base64.encode64(new_password).chomp}</password>
38
+ </ns2:accounts_common>
39
+ XML
40
+
41
+ client.all("accounts").each do |account|
42
+ if account["email"] == user
43
+ puts client.put(account["uri"], payload).parsed
44
+ break
45
+ end
46
+ end
47
+ end
48
+ 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 /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
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")
@@ -1,31 +1,34 @@
1
- lib = File.expand_path('lib', __dir__)
1
+ lib = File.expand_path("lib", __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'collectionspace/client/version'
3
+ require "collectionspace/client/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = 'collectionspace-client'
7
- spec.version = CollectionSpace::Client::VERSION
8
- spec.authors = ['Mark Cooper']
9
- spec.email = ['mark.cooper@lyrasis.org']
6
+ spec.name = "collectionspace-client"
7
+ spec.version = CollectionSpace::Client::VERSION
8
+ spec.authors = ["Mark Cooper"]
9
+ spec.email = ["mark.cooper@lyrasis.org"]
10
10
 
11
- spec.summary = 'CollectionSpace API client.'
12
- spec.homepage = 'https://github.com/lyrasis/collectionspace-client.git'
13
- spec.license = 'MIT'
11
+ spec.summary = "CollectionSpace API client."
12
+ spec.homepage = "https://github.com/lyrasis/collectionspace-client.git"
13
+ spec.license = "MIT"
14
14
 
15
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
- spec.bindir = 'exe'
17
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
- spec.require_paths = ['lib']
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
19
 
20
- spec.add_dependency 'httparty'
21
- spec.add_dependency 'json'
22
- spec.add_dependency 'nokogiri'
20
+ spec.add_dependency "httparty"
21
+ spec.add_dependency "json"
22
+ spec.add_dependency "nokogiri"
23
23
 
24
- spec.add_development_dependency 'awesome_print'
25
- spec.add_development_dependency 'bundler'
26
- spec.add_development_dependency 'rake', '~> 10.0'
27
- spec.add_development_dependency 'rspec'
28
- spec.add_development_dependency 'rubocop'
29
- spec.add_development_dependency 'vcr'
30
- spec.add_development_dependency 'webmock'
24
+ spec.add_development_dependency "awesome_print"
25
+ spec.add_development_dependency "bundler"
26
+ spec.add_development_dependency "pry"
27
+ spec.add_development_dependency "rake", "~> 13.0"
28
+ spec.add_development_dependency "rspec"
29
+ spec.add_development_dependency "rubocop"
30
+ spec.add_development_dependency "simplecov", "~> 0.21"
31
+ spec.add_development_dependency "standard"
32
+ spec.add_development_dependency "vcr", "~> 6.1"
33
+ spec.add_development_dependency "webmock"
31
34
  end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Install batches (aka data updates)
4
+ # Based on:
5
+ # https://github.com/collectionspace/Tools/blob/master/scripts/install_batch_records.sh
6
+ # https://github.com/collectionspace/Tools/blob/master/scripts/create-batch-records.sh
7
+
8
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
9
+ require "awesome_print"
10
+ require "collectionspace/client"
11
+ require "pry"
12
+
13
+ STANDARD_TENANTS = [
14
+ :anthro,
15
+ :bonsai,
16
+ :botgarden,
17
+ :core,
18
+ :fcart,
19
+ :herbarium,
20
+ :lhmc,
21
+ :materials,
22
+ :publicart
23
+ ]
24
+
25
+ STANDARD_BATCHES = CollectionSpace::Batch.all
26
+
27
+ STANDARD_TENANTS.each do |tenant|
28
+ client = CollectionSpace::Client.new(
29
+ CollectionSpace::Configuration.new(
30
+ base_uri: "https://#{tenant}.dev.collectionspace.org/cspace-services",
31
+ username: "admin@#{tenant}.collectionspace.org",
32
+ password: "Administrator"
33
+ )
34
+ )
35
+ base = client.config.base_uri
36
+ .delete_suffix("/cspace-services")
37
+ .delete_prefix("https://")
38
+ merge_doctypes = client.authority_doctypes
39
+
40
+ STANDARD_BATCHES.each do |batch|
41
+ batch[:doctype] = merge_doctypes if batch[:name] == "Merge Authority Items"
42
+ response = client.add_batch(batch)
43
+ if response.result.success?
44
+ puts "Added #{batch[:name]} to #{base}"
45
+ else
46
+ puts "FAILED TO ADD #{batch[:name]} to #{base}"
47
+ puts response.inspect
48
+ end
49
+ end
50
+ end
data/examples/demo.rb CHANGED
@@ -1,20 +1,22 @@
1
- $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
2
- require 'awesome_print'
3
- require 'collectionspace/client'
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
+ require "awesome_print"
5
+ require "collectionspace/client"
4
6
 
5
7
  client = CollectionSpace::Client.new(
6
8
  CollectionSpace::Configuration.new(
7
- base_uri: 'https://core.dev.collectionspace.org/cspace-services',
8
- username: 'admin@core.collectionspace.org',
9
- password: 'Administrator'
9
+ base_uri: "https://core.dev.collectionspace.org/cspace-services",
10
+ username: "admin@core.collectionspace.org",
11
+ password: "Administrator"
10
12
  )
11
13
  )
12
14
 
13
15
  # GET REQUEST FOR CONDITIONCHECK RECORDS AND PRINT THE PARSED RESPONSE AND XML
14
- response = client.get('conditionchecks')
16
+ response = client.get("conditionchecks")
15
17
  ap response.parsed if response.result.success?
16
18
 
17
19
  # GET ALL PERSON RECORDS AND PROCESS PER PAGE (INSTEAD OF WAITING FOR ALL)
18
- client.all('personauthorities/urn:cspace:name(person)/items').each do |item|
20
+ client.all("personauthorities/urn:cspace:name(person)/items").each do |item|
19
21
  puts item
20
22
  end
@@ -1,17 +1,19 @@
1
- $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
2
- require 'awesome_print'
3
- require 'collectionspace/client'
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
+ require "awesome_print"
5
+ require "collectionspace/client"
4
6
 
5
7
  client = CollectionSpace::Client.new(
6
8
  CollectionSpace::Configuration.new(
7
- base_uri: 'https://core.dev.collectionspace.org/cspace-services',
8
- username: 'admin@core.collectionspace.org',
9
- password: 'Administrator'
9
+ base_uri: "https://core.dev.collectionspace.org/cspace-services",
10
+ username: "admin@core.collectionspace.org",
11
+ password: "Administrator"
10
12
  )
11
13
  )
12
14
  client.config.throttle = 1
13
15
 
14
- media_url = 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'
16
+ media_url = "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"
15
17
  media = <<-XML
16
18
  <?xml version="1.0" encoding="UTF-8"?>
17
19
  <document name="media">
@@ -22,5 +24,5 @@ media = <<-XML
22
24
  </document>
23
25
  XML
24
26
 
25
- response = client.post('media', media, query: { 'blobUri' => media_url })
26
- puts response.result.headers['location'] if response.result.success?
27
+ response = client.post("media", media, query: {"blobUri" => media_url})
28
+ puts response.result.headers["location"] if response.result.success?
@@ -1,20 +1,22 @@
1
- $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
2
- require 'collectionspace/client'
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
+ require "collectionspace/client"
3
5
 
4
6
  client = CollectionSpace::Client.new(
5
7
  CollectionSpace::Configuration.new(
6
- base_uri: 'https://core.dev.collectionspace.org/cspace-services',
7
- username: 'admin@core.collectionspace.org',
8
- password: 'Administrator'
8
+ base_uri: "https://core.dev.collectionspace.org/cspace-services",
9
+ username: "admin@core.collectionspace.org",
10
+ password: "Administrator"
9
11
  )
10
12
  )
11
13
  client.config.throttle = 1
12
14
 
13
- client.all('vocabularies').each do |item|
14
- uri = item['uri']
15
+ client.all("vocabularies").each do |item|
16
+ uri = item["uri"]
15
17
  puts "Checking vocabulary: #{uri}"
16
18
  next unless client.count("#{uri}/items").zero?
17
19
 
18
- puts "Purging empty vocabulary:\t#{item['displayName']} (#{item['csid']})"
20
+ puts "Purging empty vocabulary:\t#{item["displayName"]} (#{item["csid"]})"
19
21
  client.delete uri
20
22
  end
@@ -0,0 +1,45 @@
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
+ STANDARD_TENANTS = [
8
+ :anthro,
9
+ :bonsai,
10
+ :botgarden,
11
+ :core,
12
+ :fcart,
13
+ :herbarium,
14
+ :lhmc,
15
+ :materials,
16
+ :publicart
17
+ ]
18
+
19
+ # https://github.com/collectionspace/Tools/blob/master/scripts/install_report_records.sh
20
+ # https://github.com/collectionspace/Tools/blob/master/scripts/create-report-records.sh
21
+
22
+ STANDARD_REPORTS = CollectionSpace::Report.all
23
+
24
+ STANDARD_TENANTS.each do |tenant|
25
+ client = CollectionSpace::Client.new(
26
+ CollectionSpace::Configuration.new(
27
+ base_uri: "https://#{tenant}.dev.collectionspace.org/cspace-services",
28
+ username: "admin@#{tenant}.collectionspace.org",
29
+ password: "Administrator"
30
+ )
31
+ )
32
+ base = client.config.base_uri
33
+ .delete_suffix("/cspace-services")
34
+ .delete_prefix("https://")
35
+
36
+ STANDARD_REPORTS.each do |report|
37
+ response = client.add_report(report)
38
+ if response.result.success?
39
+ puts "Added #{report[:name]} to #{base}"
40
+ else
41
+ puts "FAILED TO ADD #{report[:name]} to #{base}"
42
+ puts response.inspect
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
+ require "awesome_print"
5
+ require "collectionspace/client"
6
+ require "csv"
7
+
8
+ client = CollectionSpace::Client.new(
9
+ CollectionSpace::Configuration.new(
10
+ base_uri: "https://core.dev.collectionspace.org/cspace-services",
11
+ username: "admin@core.collectionspace.org",
12
+ password: "Administrator"
13
+ )
14
+ )
15
+ client.config.throttle = 1
16
+
17
+ path = File.expand_path("~/your/path/here.csv")
18
+
19
+ CSV.foreach(path, headers: true) do |row|
20
+ client.reset_media_blob(
21
+ id: row["identificationnumber"],
22
+ url: row["mediafileuri"],
23
+ verbose: true,
24
+ # client files are on same server as CS instance, and ingestable
25
+ # file paths do not all parse as URIs safely
26
+ ensure_safe_url: false,
27
+ # This example script used to fix media where the blobs had already
28
+ # been deleted, but the blobcsid value was not removed from the
29
+ # media record. Attempts to delete the media failed, so this option
30
+ # was used to add new blobs without attempting to delete the already
31
+ # deleted old blobs (and erroring out)
32
+ delete_existing_blob: false
33
+ )
34
+ sleep 1.5
35
+ end
data/examples/search.rb CHANGED
@@ -1,21 +1,34 @@
1
- $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
2
- require 'awesome_print'
3
- require 'collectionspace/client'
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
+ require "awesome_print"
5
+ require "collectionspace/client"
4
6
 
5
7
  config = CollectionSpace::Configuration.new(
6
- base_uri: 'https://core.dev.collectionspace.org/cspace-services',
7
- username: 'admin@core.collectionspace.org',
8
- password: 'Administrator'
8
+ base_uri: "https://core.dev.collectionspace.org/cspace-services",
9
+ username: "admin@core.collectionspace.org",
10
+ password: "Administrator"
9
11
  )
10
12
 
11
13
  client = CollectionSpace::Client.new(config)
12
14
 
13
15
  search_args = {
14
- path: 'groups',
15
- type: 'groups_common',
16
- field: 'title',
17
- expression: "ILIKE '%DTS 001%'"
16
+ path: "groups",
17
+ namespace: "groups_common",
18
+ field: "title",
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"