sdr-client 2.13.1 → 2.14.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: 073d9149d7aade5f78842251778f8731ca9ef8e767ab0abe59f5ff360f3d8c2a
4
- data.tar.gz: 1085b1b409a72c1a7d0377198199f44244ea7f4db17e78449a1931ac0e1502af
3
+ metadata.gz: 92a856bedc983187ec0a1721ca4ec66ee7eaa1986fa1ed795fc079bf1140c956
4
+ data.tar.gz: c53dd7fbff6953c2a333245b631dcc8c24d84e9d10833e2c91b92f6cb534feaa
5
5
  SHA512:
6
- metadata.gz: 84aff6cb5c387c48fded7fa363f486e7123f3c2e2d55396e0fe7c9e785fd1a268158d5cc65eb77cd34dfaea8d66654f1a2e727ee0d366f66ce53f50087054840
7
- data.tar.gz: aafac64bc2a0bd62c06085288858d19e1d9ea17c88fd5d8b58edc6172c5ebd907c091d577a7b778bf00c2cfff0ac155810bad7387eab3f8665c393cd75eb366e
6
+ metadata.gz: b1000308c12ebab774556315768ccc2100b19fa95d9df91fa63356cb9e2b85b4965d32c59de6b6a2f9ba7217477dad3d59102a7185db17a3da5314a9daaafc0c
7
+ data.tar.gz: f6cc0eb1b8d0beff8e46c54f56743ab576d6318148c4fe0bc1360eca7e995171a49fd448a7c246533ac23c816df8a60f3dfb50da51c12d73f332c62438dd41f4
data/.rubocop.yml CHANGED
@@ -30,6 +30,9 @@ Naming/FileName:
30
30
  Exclude:
31
31
  - 'lib/sdr-client.rb'
32
32
 
33
+ RSpec/MultipleExpectations:
34
+ Enabled: false
35
+
33
36
  RSpec/MultipleMemoizedHelpers:
34
37
  Enabled: false
35
38
 
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config --auto-gen-only-exclude`
3
- # on 2024-03-26 19:28:56 UTC using RuboCop version 1.62.0.
3
+ # on 2024-05-01 23:27:58 UTC using RuboCop version 1.63.4.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -13,6 +13,19 @@ Gemspec/RequiredRubyVersion:
13
13
  Exclude:
14
14
  - 'sdr-client.gemspec'
15
15
 
16
+ # Offense count: 35
17
+ # This cop supports safe autocorrection (--autocorrect).
18
+ # Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
19
+ # URISchemes: http, https
20
+ Layout/LineLength:
21
+ Exclude:
22
+ - 'lib/sdr_client/cli.rb'
23
+ - 'lib/sdr_client/deposit/model_process.rb'
24
+ - 'lib/sdr_client/update.rb'
25
+ - 'spec/sdr_client/deposit/model_process_spec.rb'
26
+ - 'spec/sdr_client/deposit/process_spec.rb'
27
+ - 'spec/sdr_client/update_spec.rb'
28
+
16
29
  # Offense count: 1
17
30
  Lint/NoReturnInBeginEndBlocks:
18
31
  Exclude:
@@ -26,11 +39,12 @@ Lint/UnusedMethodArgument:
26
39
  - 'lib/sdr_client/deposit/file_type_file_set_strategy.rb'
27
40
  - 'lib/sdr_client/deposit/image_file_set_strategy.rb'
28
41
 
29
- # Offense count: 11
42
+ # Offense count: 15
30
43
  # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
31
44
  Metrics/AbcSize:
32
45
  Exclude:
33
46
  - 'lib/sdr_client/cli.rb'
47
+ - 'lib/sdr_client/deposit/request.rb'
34
48
  - 'lib/sdr_client/redesigned_client.rb'
35
49
  - 'lib/sdr_client/redesigned_client/cli.rb'
36
50
  - 'lib/sdr_client/redesigned_client/cli/update.rb'
@@ -74,20 +88,6 @@ RSpec/MessageSpies:
74
88
  Exclude:
75
89
  - 'spec/sdr_client/deposit_spec.rb'
76
90
 
77
- # Offense count: 19
78
- # Configuration parameters: Max.
79
- RSpec/MultipleExpectations:
80
- Exclude:
81
- - 'spec/sdr_client/connection_spec.rb'
82
- - 'spec/sdr_client/deposit/metadata_builder_spec.rb'
83
- - 'spec/sdr_client/deposit_model_spec.rb'
84
- - 'spec/sdr_client/deposit_spec.rb'
85
- - 'spec/sdr_client/find_spec.rb'
86
- - 'spec/sdr_client/login_spec.rb'
87
- - 'spec/sdr_client/redesigned_client/deposit_spec.rb'
88
- - 'spec/sdr_client/redesigned_client/job_status_spec.rb'
89
- - 'spec/sdr_client/redesigned_client/upload_files_spec.rb'
90
-
91
91
  # Offense count: 24
92
92
  # Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
93
93
  # SupportedStyles: always, named_only
@@ -117,7 +117,7 @@ RSpec/ReceiveMessages:
117
117
  Exclude:
118
118
  - 'spec/sdr_client/update_spec.rb'
119
119
 
120
- # Offense count: 21
120
+ # Offense count: 23
121
121
  # This cop supports safe autocorrection (--autocorrect).
122
122
  Style/KeywordParametersOrder:
123
123
  Exclude:
@@ -138,16 +138,3 @@ Style/StringConcatenation:
138
138
  Exclude:
139
139
  - 'lib/sdr_client/deposit/create_resource.rb'
140
140
  - 'spec/sdr_client/deposit_spec.rb'
141
-
142
- # Offense count: 35
143
- # This cop supports safe autocorrection (--autocorrect).
144
- # Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
145
- # URISchemes: http, https
146
- Layout/LineLength:
147
- Exclude:
148
- - 'lib/sdr_client/cli.rb'
149
- - 'lib/sdr_client/deposit/model_process.rb'
150
- - 'lib/sdr_client/update.rb'
151
- - 'spec/sdr_client/deposit/model_process_spec.rb'
152
- - 'spec/sdr_client/deposit/process_spec.rb'
153
- - 'spec/sdr_client/update_spec.rb'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sdr-client (2.13.1)
4
+ sdr-client (2.14.0)
5
5
  activesupport
6
6
  cocina-models (~> 0.96.0)
7
7
  config
@@ -28,7 +28,7 @@ GEM
28
28
  ast (2.4.2)
29
29
  attr_extras (7.1.0)
30
30
  base64 (0.2.0)
31
- bigdecimal (3.1.7)
31
+ bigdecimal (3.1.8)
32
32
  byebug (11.1.3)
33
33
  childprocess (5.0.0)
34
34
  cocina-models (0.96.0)
@@ -94,14 +94,14 @@ GEM
94
94
  faraday-net_http (3.1.0)
95
95
  net-http
96
96
  hashdiff (1.1.0)
97
- i18n (1.14.4)
97
+ i18n (1.14.5)
98
98
  concurrent-ruby (~> 1.0)
99
99
  ice_nine (0.11.2)
100
100
  json (2.7.2)
101
101
  jsonpath (1.1.5)
102
102
  multi_json
103
103
  language_server-protocol (3.17.0.3)
104
- launchy (3.0.0)
104
+ launchy (3.0.1)
105
105
  addressable (~> 2.8)
106
106
  childprocess (~> 5.0)
107
107
  minitest (5.22.3)
@@ -109,16 +109,18 @@ GEM
109
109
  mutex_m (0.2.0)
110
110
  net-http (0.4.1)
111
111
  uri
112
- nokogiri (1.16.4-x86_64-darwin)
112
+ nokogiri (1.16.5-arm64-darwin)
113
113
  racc (~> 1.4)
114
- nokogiri (1.16.4-x86_64-linux)
114
+ nokogiri (1.16.5-x86_64-darwin)
115
+ racc (~> 1.4)
116
+ nokogiri (1.16.5-x86_64-linux)
115
117
  racc (~> 1.4)
116
118
  openapi3_parser (0.9.2)
117
119
  commonmarker (~> 0.17)
118
120
  openapi_parser (1.0.0)
119
121
  optimist (3.1.0)
120
122
  parallel (1.24.0)
121
- parser (3.3.0.5)
123
+ parser (3.3.1.0)
122
124
  ast (~> 2.4.1)
123
125
  racc
124
126
  patience_diff (1.2.0)
@@ -127,7 +129,7 @@ GEM
127
129
  racc (1.7.3)
128
130
  rainbow (3.1.1)
129
131
  rake (13.2.1)
130
- regexp_parser (2.9.0)
132
+ regexp_parser (2.9.1)
131
133
  rexml (3.2.6)
132
134
  rspec (3.13.0)
133
135
  rspec-core (~> 3.13.0)
@@ -138,7 +140,7 @@ GEM
138
140
  rspec-expectations (3.13.0)
139
141
  diff-lcs (>= 1.2.0, < 2.0)
140
142
  rspec-support (~> 3.13.0)
141
- rspec-mocks (3.13.0)
143
+ rspec-mocks (3.13.1)
142
144
  diff-lcs (>= 1.2.0, < 2.0)
143
145
  rspec-support (~> 3.13.0)
144
146
  rspec-support (3.13.1)
@@ -146,7 +148,7 @@ GEM
146
148
  rspec-core (>= 2, < 4, != 2.12.0)
147
149
  rss (0.3.0)
148
150
  rexml
149
- rubocop (1.63.2)
151
+ rubocop (1.63.5)
150
152
  json (~> 2.3)
151
153
  language_server-protocol (>= 3.17.0)
152
154
  parallel (~> 1.10)
@@ -157,15 +159,15 @@ GEM
157
159
  rubocop-ast (>= 1.31.1, < 2.0)
158
160
  ruby-progressbar (~> 1.7)
159
161
  unicode-display_width (>= 2.4.0, < 3.0)
160
- rubocop-ast (1.31.2)
161
- parser (>= 3.3.0.4)
162
+ rubocop-ast (1.31.3)
163
+ parser (>= 3.3.1.0)
162
164
  rubocop-capybara (2.20.0)
163
165
  rubocop (~> 1.41)
164
166
  rubocop-factory_bot (2.25.1)
165
167
  rubocop (~> 1.41)
166
168
  rubocop-rake (0.6.0)
167
169
  rubocop (~> 1.0)
168
- rubocop-rspec (2.29.1)
170
+ rubocop-rspec (2.29.2)
169
171
  rubocop (~> 1.40)
170
172
  rubocop-capybara (~> 2.17)
171
173
  rubocop-factory_bot (~> 2.22)
@@ -179,7 +181,7 @@ GEM
179
181
  simplecov_json_formatter (~> 0.1)
180
182
  simplecov-html (0.12.3)
181
183
  simplecov_json_formatter (0.1.4)
182
- super_diff (0.11.0)
184
+ super_diff (0.12.1)
183
185
  attr_extras (>= 6.2.4)
184
186
  diff-lcs
185
187
  patience_diff
@@ -195,6 +197,7 @@ GEM
195
197
  zeitwerk (2.6.13)
196
198
 
197
199
  PLATFORMS
200
+ arm64-darwin-23
198
201
  x86_64-darwin-19
199
202
  x86_64-darwin-20
200
203
  x86_64-darwin-21
@@ -83,6 +83,8 @@ module SdrClient
83
83
  option :use_and_reproduction, desc: 'Use and reproduction statement'
84
84
  option :viewing_direction, enum: %w[left-to-right right-to-left], desc: 'Viewing direction (if a book)'
85
85
  option :view, enum: %w[world stanford location-based citation-only dark], desc: 'Access view level for the object'
86
+ option :download, enum: %w[world stanford location-based none], desc: 'Access download level for the object'
87
+ option :location, enum: %w[spec music ars art hoover m&m], desc: 'Access location for the object'
86
88
  option :files_metadata, desc: 'JSON string representing per-file metadata'
87
89
  option :grouping_strategy, enum: %w[default filename], desc: 'Strategy for grouping files into filesets'
88
90
  option :basepath, default: Dir.getwd, desc: 'Base path for the files'
@@ -103,6 +105,8 @@ module SdrClient
103
105
  option :use_and_reproduction, desc: 'Use and reproduction statement'
104
106
  option :viewing_direction, enum: %w[left-to-right right-to-left], desc: 'Viewing direction (if a book)'
105
107
  option :view, enum: %w[world stanford location-based citation-only dark], desc: 'Access view level for the object'
108
+ option :download, enum: %w[world stanford location-based none], desc: 'Access download level for the object'
109
+ option :location, enum: %w[spec music ars art hoover m&m], desc: 'Access location for the object'
106
110
  option :files_metadata, desc: 'JSON string representing per-file metadata'
107
111
  option :grouping_strategy, enum: %w[default filename], desc: 'Strategy for grouping files into filesets'
108
112
  option :basepath, default: Dir.getwd, desc: 'Base path for the files'
@@ -5,8 +5,8 @@ module SdrClient
5
5
  # Creates a resource (metadata) in SDR
6
6
  class CreateResource
7
7
  DRO_PATH = '/v1/resources'
8
- def self.run(**args)
9
- new(**args).run
8
+ def self.run(...)
9
+ new(...).run
10
10
  end
11
11
 
12
12
  # @param [Boolean] accession should the accessionWF be started
@@ -15,14 +15,16 @@ module SdrClient
15
15
  # @param [Hash<Symbol,String>] the result of the metadata call
16
16
  # @param [String] priority what processing priority should be used
17
17
  # either 'low' or 'default'
18
+ # @param [String] user_versions action (none, new, update) to take for user version when closing version
18
19
  # rubocop:disable Metrics/ParameterLists
19
- def initialize(accession:, metadata:, logger:, connection:, assign_doi: false, priority: nil)
20
+ def initialize(accession:, metadata:, logger:, connection:, assign_doi: false, priority: nil, user_versions: nil)
20
21
  @accession = accession
21
22
  @priority = priority
22
23
  @assign_doi = assign_doi
23
24
  @metadata = metadata
24
25
  @logger = logger
25
26
  @connection = connection
27
+ @user_versions = user_versions
26
28
  end
27
29
  # rubocop:enable Metrics/ParameterLists
28
30
 
@@ -39,7 +41,7 @@ module SdrClient
39
41
 
40
42
  private
41
43
 
42
- attr_reader :metadata, :logger, :connection, :priority
44
+ attr_reader :metadata, :logger, :connection, :priority, :user_versions
43
45
 
44
46
  def metadata_request
45
47
  json = metadata.to_json
@@ -62,6 +64,7 @@ module SdrClient
62
64
  params = { accession: accession? }
63
65
  params[:priority] = priority if priority
64
66
  params[:assign_doi] = true if assign_doi? # false is default
67
+ params[:user_versions] = user_versions if user_versions.present?
65
68
  DRO_PATH + '?' + params.map { |k, v| "#{k}=#{v}" }.join('&')
66
69
  end
67
70
  end
@@ -6,7 +6,7 @@ module SdrClient
6
6
  class File
7
7
  # rubocop:disable Metrics/ParameterLists
8
8
  def initialize(external_identifier:, label:, filename:,
9
- view: 'dark', download: 'none', preserve: true, shelve: true,
9
+ view: 'dark', download: 'none', location: nil, preserve: true, shelve: true,
10
10
  publish: true, mime_type: nil, md5: nil, sha1: nil,
11
11
  use: nil)
12
12
  @external_identifier = external_identifier
@@ -14,6 +14,7 @@ module SdrClient
14
14
  @filename = filename
15
15
  @view = view
16
16
  @download = download
17
+ @location = location
17
18
  @preserve = preserve
18
19
  @shelve = view == 'dark' ? false : shelve
19
20
  @publish = publish
@@ -44,6 +45,7 @@ module SdrClient
44
45
  }.tap do |json|
45
46
  json['hasMimeType'] = @mime_type if @mime_type
46
47
  json['use'] = @use if @use
48
+ json[:access][:location] = @location if @location
47
49
  end
48
50
  end
49
51
 
@@ -35,7 +35,7 @@ module SdrClient
35
35
  return 'application/octet-stream' if content_type.blank?
36
36
 
37
37
  # ActiveStorage is expecting "application/x-stata-dta" not "application/x-stata-dta;version=14"
38
- content_type = content_type.split(';')&.first
38
+ content_type = content_type.split(';').first
39
39
 
40
40
  content_type == 'application/json' ? 'application/x-stanford-json' : content_type
41
41
  end
@@ -15,6 +15,7 @@ module SdrClient
15
15
  def initialize(label: nil,
16
16
  view: 'dark',
17
17
  download: 'none',
18
+ location: nil,
18
19
  use_and_reproduction: nil,
19
20
  copyright: nil,
20
21
  apo:,
@@ -40,6 +41,7 @@ module SdrClient
40
41
  @embargo_download = embargo_download
41
42
  @view = view
42
43
  @download = download
44
+ @location = location
43
45
  @use_and_reproduction = use_and_reproduction
44
46
  @copyright = copyright
45
47
  @apo = apo
@@ -66,6 +68,7 @@ module SdrClient
66
68
  Request.new(label: label,
67
69
  view: view,
68
70
  download: download,
71
+ location: location,
69
72
  apo: apo,
70
73
  collection: collection,
71
74
  copyright: copyright,
@@ -88,6 +91,7 @@ module SdrClient
88
91
  metadata = files_metadata.fetch(filename, {}).with_indifferent_access
89
92
  metadata[:view] = view unless metadata.key?(:view)
90
93
  metadata[:download] = download unless metadata.key?(:download)
94
+ metadata[:location] = location unless metadata.key?(:location)
91
95
  metadata
92
96
  end
93
97
 
@@ -97,7 +101,7 @@ module SdrClient
97
101
 
98
102
  attr_reader :view, :label, :file_sets, :source_id, :catkey, :folio_instance_hrid, :apo, :collection,
99
103
  :files_metadata, :embargo_release_date, :embargo_access, :embargo_download,
100
- :viewing_direction, :use_and_reproduction, :copyright, :download
104
+ :viewing_direction, :use_and_reproduction, :copyright, :download, :location
101
105
 
102
106
  def administrative
103
107
  {
@@ -132,6 +136,7 @@ module SdrClient
132
136
  }.tap do |json|
133
137
  json[:useAndReproductionStatement] = use_and_reproduction if use_and_reproduction
134
138
  json[:copyright] = copyright if copyright
139
+ json[:location] = location if location
135
140
 
136
141
  if embargo_release_date
137
142
  json[:embargo] = {
@@ -6,18 +6,20 @@ module SdrClient
6
6
  class UpdateResource
7
7
  DRO_PATH = '/v1/resources/%<id>s'
8
8
 
9
- def self.run(metadata:, logger:, connection:, version_description: nil)
10
- new(metadata: metadata, logger: logger, connection: connection, version_description: version_description).run
9
+ def self.run(...)
10
+ new(...).run
11
11
  end
12
12
 
13
13
  # @param [Cocina::Models::DRO] metadata
14
14
  # @param [Hash<Symbol,String>] the result of the metadata call
15
15
  # @param [String] version_description
16
- def initialize(metadata:, logger:, connection:, version_description: nil)
16
+ # @param [String] user_versions action (none, new, update) to take for user version when closing version
17
+ def initialize(metadata:, logger:, connection:, version_description: nil, user_versions: nil)
17
18
  @metadata = metadata
18
19
  @logger = logger
19
20
  @connection = connection
20
21
  @version_description = version_description
22
+ @user_versions = user_versions
21
23
  end
22
24
 
23
25
  # @param [Hash<Symbol,String>] the result of the metadata call
@@ -33,8 +35,9 @@ module SdrClient
33
35
 
34
36
  private
35
37
 
36
- attr_reader :metadata, :logger, :connection, :version_description
38
+ attr_reader :metadata, :logger, :connection, :version_description, :user_versions
37
39
 
40
+ # rubocop:disable Metrics/AbcSize
38
41
  def metadata_request
39
42
  json = metadata.to_json
40
43
  logger.debug("Starting update metadata: #{json}")
@@ -43,8 +46,10 @@ module SdrClient
43
46
  'Content-Type' => 'application/json',
44
47
  'X-Cocina-Models-Version' => Cocina::Models::VERSION) do |req|
45
48
  req.params['versionDescription'] = version_description if version_description
49
+ req.params['user_versions'] = user_versions if user_versions.present?
46
50
  end
47
51
  end
52
+ # rubocop:enable Metrics/AbcSize
48
53
 
49
54
  def path(metadata)
50
55
  format(DRO_PATH, id: metadata.externalIdentifier)
@@ -15,6 +15,7 @@ module SdrClient
15
15
  viewing_direction: nil,
16
16
  view: 'dark',
17
17
  download: 'none',
18
+ location: nil,
18
19
  use_and_reproduction: nil,
19
20
  copyright: nil,
20
21
  apo:,
@@ -40,6 +41,7 @@ module SdrClient
40
41
  type: type,
41
42
  view: view,
42
43
  download: download,
44
+ location: location,
43
45
  apo: apo,
44
46
  use_and_reproduction: use_and_reproduction,
45
47
  copyright: copyright,
@@ -9,25 +9,25 @@ module SdrClient
9
9
  def self.write(body)
10
10
  token = JSON.parse(body).fetch('token')
11
11
  FileUtils.mkdir_p(credentials_path, mode: 0o700)
12
- File.atomic_write(credentials_file) { |file| file.write(token) }
13
- File.chmod(0o600, credentials_file)
12
+ ::File.atomic_write(credentials_file) { |file| file.write(token) }
13
+ ::File.chmod(0o600, credentials_file)
14
14
  end
15
15
 
16
16
  def self.read
17
17
  return unless ::File.exist?(credentials_file)
18
18
 
19
- creds = File.read(credentials_file, chomp: true)
19
+ creds = ::File.read(credentials_file, chomp: true)
20
20
  return if creds.nil?
21
21
 
22
22
  creds
23
23
  end
24
24
 
25
25
  def self.credentials_path
26
- @credentials_path ||= File.join(Dir.home, '.sdr')
26
+ @credentials_path ||= ::File.join(Dir.home, '.sdr')
27
27
  end
28
28
 
29
29
  def self.credentials_file
30
- File.join(credentials_path, 'credentials')
30
+ ::File.join(credentials_path, 'credentials')
31
31
  end
32
32
  end
33
33
  end
@@ -46,7 +46,7 @@ module SdrClient
46
46
  end
47
47
 
48
48
  def cocina_hash_from_file
49
- @cocina_hash_from_file ||= JSON.parse(File.read(options[:cocina_file]), symbolize_names: true)
49
+ @cocina_hash_from_file ||= JSON.parse(::File.read(options[:cocina_file]), symbolize_names: true)
50
50
  end
51
51
 
52
52
  def cocina_hash_from_pipe
@@ -65,7 +65,7 @@ module SdrClient
65
65
  end
66
66
 
67
67
  def update_cocina_from_file(cocina_object)
68
- if !File.file?(options[:cocina_file]) || !File.readable?(options[:cocina_file])
68
+ if !::File.file?(options[:cocina_file]) || !::File.readable?(options[:cocina_file])
69
69
  raise "File not found: #{options[:cocina_file]}"
70
70
  end
71
71
 
@@ -64,17 +64,26 @@ module SdrClient
64
64
  validate_druid!(druid)
65
65
  # Make sure client is configured
66
66
  client
67
- job_id = CLI::Update.run(druid, **options)
67
+ job_id = Update.run(druid, **options)
68
68
  if options[:skip_polling]
69
69
  say "job ID #{job_id} queued (not polling because `-s` flag was supplied)"
70
70
  return
71
71
  end
72
72
 
73
+ # the extra args to `say` prevent appending a newline
74
+ say('SDR is processing your request.', nil, false)
75
+
73
76
  job_status = client.job_status(job_id: job_id)
74
- if job_status.wait_until_complete
75
- say "success! (druid: #{job_status.druid})"
77
+ job_status.wait_until_complete { say('.', nil, false) }
78
+
79
+ if job_status.complete?
80
+ if job_status.errors
81
+ say_error " errored! #{job_status.errors}"
82
+ else
83
+ say " success! (druid: #{job_status.druid})"
84
+ end
76
85
  else
77
- say_error "errored! #{job_status.errors}"
86
+ say_error " job #{job_id} did not complete\n#{job_status.result.inspect}"
78
87
  end
79
88
  end
80
89
 
@@ -93,6 +102,8 @@ module SdrClient
93
102
  option :use_and_reproduction, desc: 'Use and reproduction statement'
94
103
  option :viewing_direction, enum: %w[left-to-right right-to-left], desc: 'Viewing direction (if a book)'
95
104
  option :view, enum: %w[world stanford location-based citation-only dark], desc: 'Access view level for the object'
105
+ option :download, enum: %w[world stanford location-based none], desc: 'Access download level for the object'
106
+ option :location, enum: %w[spec music ars art hoover m&m], desc: 'Access location for the object'
96
107
  option :files_metadata, desc: 'JSON string representing per-file metadata'
97
108
  option :grouping_strategy, enum: %w[default filename], desc: 'Strategy for grouping files into filesets'
98
109
  option :basepath, default: Dir.getwd, desc: 'Base path for the files'
@@ -115,6 +126,8 @@ module SdrClient
115
126
  option :use_and_reproduction, desc: 'Use and reproduction statement'
116
127
  option :viewing_direction, enum: %w[left-to-right right-to-left], desc: 'Viewing direction (if a book)'
117
128
  option :view, enum: %w[world stanford location-based citation-only dark], desc: 'Access view level for the object'
129
+ option :download, enum: %w[world stanford location-based none], desc: 'Access download level for the object'
130
+ option :location, enum: %w[spec music ars art hoover m&m], desc: 'Access location for the object'
118
131
  option :files_metadata, desc: 'JSON string representing per-file metadata'
119
132
  option :grouping_strategy, enum: %w[default filename], desc: 'Strategy for grouping files into filesets'
120
133
  option :basepath, default: Dir.getwd, desc: 'Base path for the files'
@@ -143,7 +156,7 @@ module SdrClient
143
156
  sleep 0.5
144
157
  token_string = ask('Paste token here:')
145
158
  expiry = JSON.parse(token_string)['exp']
146
- CLI::Credentials.write(token_string)
159
+ Credentials.write(token_string)
147
160
  say "You are now authenticated for #{options[:url]} until #{expiry}"
148
161
  token_string
149
162
  end
@@ -14,11 +14,13 @@ module SdrClient
14
14
  # @param [Hash<Symbol,String>] the result of the metadata call
15
15
  # @param [String] priority what processing priority should be used
16
16
  # either 'low' or 'default'
17
- def initialize(accession:, metadata:, assign_doi: false, priority: nil)
17
+ # @param [String] user_versions action (none, new, update) to take for user version when closing version
18
+ def initialize(accession:, metadata:, assign_doi: false, priority: nil, user_versions: nil)
18
19
  @accession = accession
19
20
  @priority = priority
20
21
  @assign_doi = assign_doi
21
22
  @metadata = metadata
23
+ @user_versions = user_versions
22
24
  end
23
25
 
24
26
  # @param [Hash<Symbol,String>] the result of the metadata call
@@ -41,7 +43,7 @@ module SdrClient
41
43
 
42
44
  private
43
45
 
44
- attr_reader :metadata, :priority
46
+ attr_reader :metadata, :priority, :user_versions
45
47
 
46
48
  def logger
47
49
  SdrClient::RedesignedClient.config.logger
@@ -63,6 +65,7 @@ module SdrClient
63
65
  params = { accession: accession? }
64
66
  params[:priority] = priority if priority
65
67
  params[:assign_doi] = true if assign_doi? # false is default
68
+ params[:user_versions] = user_versions if user_versions.present?
66
69
  query_string = params.map { |k, v| "#{k}=#{v}" }.join('&')
67
70
  "/v1/resources?#{query_string}"
68
71
  end
@@ -36,7 +36,7 @@ module SdrClient
36
36
  return 'application/octet-stream' if content_type.blank?
37
37
 
38
38
  # ActiveStorage is expecting "application/x-stata-dta" not "application/x-stata-dta;version=14"
39
- content_type = content_type.split(';')&.first
39
+ content_type = content_type.split(';').first
40
40
 
41
41
  content_type == 'application/json' ? 'application/x-stanford-json' : content_type
42
42
  end
@@ -10,6 +10,7 @@ module SdrClient
10
10
  # @param [Hash] options optional parameters
11
11
  # @option options [String] view the access level for viewing the object
12
12
  # @option options [String] download the access level for downloading the object
13
+ # @option options [String] location the location for location-based access
13
14
  # @option options [Boolean] preserve whether to preserve the file or not
14
15
  # @option options [Boolean] shelve whether to shelve the file or not
15
16
  # @option options [Boolean] publish whether to publish the file or not
@@ -44,6 +45,7 @@ module SdrClient
44
45
  }.tap do |json|
45
46
  json['hasMimeType'] = mime_type if mime_type
46
47
  json['use'] = use if use
48
+ json[:access]['location'] if location
47
49
  end
48
50
  end
49
51
 
@@ -66,6 +68,10 @@ module SdrClient
66
68
  options.fetch(:download, 'none')
67
69
  end
68
70
 
71
+ def location
72
+ options[:location]
73
+ end
74
+
69
75
  def preserve
70
76
  options.fetch(:preserve, true)
71
77
  end
@@ -6,6 +6,8 @@ module SdrClient
6
6
  class RedesignedClient
7
7
  # Wraps operations waiting for results from jobs
8
8
  class JobStatus
9
+ attr_reader :result
10
+
9
11
  def initialize(job_id:)
10
12
  @job_id = job_id
11
13
  @result = {
@@ -35,11 +37,26 @@ module SdrClient
35
37
  # @param [Integer] timeout_in_secs (180) timeout after this many secs
36
38
  # @param [Float] backoff_factor (2.0) how quickly to backoff. This should be > 1.0 and probably ought to be <= 2.0
37
39
  # @return [Boolean] true if successful false if unsuccessful.
38
- def wait_until_complete(secs_between_requests: 3.0,
40
+ def wait_until_complete(secs_between_requests: 3.0, # rubocop:disable Metrics/MethodLength
39
41
  timeout_in_secs: 180,
40
42
  backoff_factor: 2.0,
41
43
  max_secs_between_requests: 60)
42
- poll_until_complete(secs_between_requests, timeout_in_secs, backoff_factor, max_secs_between_requests)
44
+ begin
45
+ Timeout.timeout(timeout_in_secs) do
46
+ loop do
47
+ break if complete?
48
+
49
+ yield if block_given?
50
+
51
+ sleep(secs_between_requests)
52
+ # Exponential backoff, limited to max_secs_between_requests
53
+ secs_between_requests = [secs_between_requests * backoff_factor, max_secs_between_requests].min
54
+ end
55
+ end
56
+ rescue Timeout::Error
57
+ @result[:output][:errors] = ["Not complete after #{timeout_in_secs} seconds"]
58
+ end
59
+
43
60
  errors.nil?
44
61
  end
45
62
 
@@ -54,21 +71,6 @@ module SdrClient
54
71
  def path
55
72
  "/v1/background_job_results/#{job_id}"
56
73
  end
57
-
58
- def poll_until_complete(secs_between_requests, timeout_in_secs, backoff_factor, max_secs_between_requests)
59
- interval = secs_between_requests
60
- Timeout.timeout(timeout_in_secs) do
61
- loop do
62
- break if complete?
63
-
64
- sleep(interval)
65
- # Exponential backoff, limited to max_secs_between_requests
66
- interval = [interval * backoff_factor, max_secs_between_requests].min
67
- end
68
- end
69
- rescue Timeout::Error
70
- @result[:output][:errors] = ["Not complete after #{timeout_in_secs} seconds"]
71
- end
72
74
  end
73
75
  end
74
76
  end
@@ -35,6 +35,7 @@ module SdrClient
35
35
  model: request_builder.to_cocina,
36
36
  basepath: basepath,
37
37
  files: files,
38
+ accession: accession,
38
39
  request_builder: request_builder,
39
40
  **options
40
41
  )
@@ -10,6 +10,7 @@ module SdrClient
10
10
  # @option options [String] label the required object label
11
11
  # @option options [String] view the access level for viewing the object
12
12
  # @option options [String] download the access level for downloading the object
13
+ # @option options [String] location the location for location-based access
13
14
  # @option options [String] type (https://cocina.sul.stanford.edu/models/object) the required object type.
14
15
  # @option options [String] use_and_reproduction the use and reproduction statement
15
16
  # @option options [String] copyright the copyright statement
@@ -93,13 +94,14 @@ module SdrClient
93
94
  end
94
95
  end
95
96
 
96
- def access_struct # rubocop:disable Metrics/MethodLength
97
+ def access_struct # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
97
98
  {
98
99
  view: view,
99
100
  download: download
100
101
  }.tap do |json|
101
102
  json[:useAndReproductionStatement] = use_and_reproduction if use_and_reproduction
102
103
  json[:copyright] = copyright if copyright
104
+ json[:location] = location if location
103
105
 
104
106
  if embargo_release_date
105
107
  json[:embargo] = {
@@ -119,6 +121,10 @@ module SdrClient
119
121
  options.fetch(:download, 'none')
120
122
  end
121
123
 
124
+ def location
125
+ options[:location]
126
+ end
127
+
122
128
  def label
123
129
  options[:label]
124
130
  end
@@ -12,9 +12,11 @@ module SdrClient
12
12
 
13
13
  # @param [Cocina::Models::DRO] model
14
14
  # @param [String] version_description
15
- def initialize(model:, version_description: nil)
15
+ # @param [String] user_versions action (none, new, update) to take for user version when closing version
16
+ def initialize(model:, version_description: nil, user_versions: nil)
16
17
  @model = model
17
18
  @version_description = version_description
19
+ @user_versions = user_versions
18
20
  end
19
21
 
20
22
  # @return [String] job id for the background job result
@@ -37,7 +39,7 @@ module SdrClient
37
39
 
38
40
  private
39
41
 
40
- attr_reader :model, :version_description
42
+ attr_reader :model, :version_description, :user_versions
41
43
 
42
44
  def client
43
45
  SdrClient::RedesignedClient.instance
@@ -52,9 +54,10 @@ module SdrClient
52
54
  end
53
55
 
54
56
  def request_params
55
- return { 'versionDescription' => version_description } if version_description
56
-
57
- {}
57
+ {
58
+ versionDescription: version_description,
59
+ user_versions: user_versions
60
+ }.compact
58
61
  end
59
62
  end
60
63
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SdrClient
4
- VERSION = '2.13.1'
4
+ VERSION = '2.14.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sdr-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.13.1
4
+ version: 2.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-24 00:00:00.000000000 Z
11
+ date: 2024-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -224,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
224
224
  - !ruby/object:Gem::Version
225
225
  version: '0'
226
226
  requirements: []
227
- rubygems_version: 3.5.7
227
+ rubygems_version: 3.4.19
228
228
  signing_key:
229
229
  specification_version: 4
230
230
  summary: The CLI for https://github.com/sul-dlss/sdr-api