sdr-client 1.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a66643c6ea7e08e14f529c7e5396a5037ab39cae895fa65bb7ddf7a6d98ca93c
4
- data.tar.gz: 7a7986eb90c7de9eb1f4b0335e4bae0981fe2679ac2317de2f66daaee92f141f
3
+ metadata.gz: 17915ecb6a7106d3236d893589e751def14fbaa53a79eb803a1695b3c71c1a00
4
+ data.tar.gz: 69d87e176f5989baffcafdd0312ba67a6e87df44bd13d5930113e2bbfe058917
5
5
  SHA512:
6
- metadata.gz: 8fc2bb28ace65e03d8cf5336b080924a7ed6d2899cf5d2d54459b38b3d2849738cdaf9bee4fb8021a5b174f3062410748e20345cba9e10e42690995d4e0cd9f9
7
- data.tar.gz: 4a3dcc3903a17266469c3ad2ca18c2d3fbb7ff57b1711b5753993a5202361d7cb9b526fbef9806a31daabcebc307cae4ba052b5f185bd6a34bfb75e694fbfd11
6
+ metadata.gz: febadce28e8d780c62461cf61264cd3080d6e8e56ea403f3586b6d1f918aec1a0f2679443cd08c125c881fdd139ca9067379a39e349f8af48a10d6fedd5df743
7
+ data.tar.gz: 692ce1e5c829206be38d645aca518496b1346cacc09810241ecf4d16d867088ec7f50cd93db312253f76c26d91e270815c70dfbcdb53811a708f71c34d0978d3
data/Gemfile.lock CHANGED
@@ -1,11 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sdr-client (1.0.0)
4
+ sdr-client (2.0.1)
5
5
  activesupport
6
6
  cocina-models (~> 0.86.0)
7
+ config
7
8
  dry-monads
8
9
  faraday (>= 0.16)
10
+ launchy
9
11
 
10
12
  GEM
11
13
  remote: https://rubygems.org/
@@ -37,17 +39,25 @@ GEM
37
39
  zeitwerk (~> 2.1)
38
40
  commonmarker (0.23.6)
39
41
  concurrent-ruby (1.1.10)
42
+ config (4.1.0)
43
+ deep_merge (~> 1.2, >= 1.2.1)
44
+ dry-validation (~> 1.0, >= 1.0.0)
40
45
  crack (0.4.5)
41
46
  rexml
47
+ deep_merge (1.2.2)
42
48
  deprecation (1.1.0)
43
49
  activesupport
44
50
  diff-lcs (1.5.0)
45
51
  docile (1.4.0)
52
+ dry-configurable (1.0.1)
53
+ dry-core (~> 1.0, < 2)
54
+ zeitwerk (~> 2.6)
46
55
  dry-core (1.0.0)
47
56
  concurrent-ruby (~> 1.0)
48
57
  zeitwerk (~> 2.6)
49
58
  dry-inflector (1.0.0)
50
- dry-logic (1.4.0)
59
+ dry-initializer (3.1.1)
60
+ dry-logic (1.5.0)
51
61
  concurrent-ruby (~> 1.0)
52
62
  dry-core (~> 1.0, < 2)
53
63
  zeitwerk (~> 2.6)
@@ -55,6 +65,14 @@ GEM
55
65
  concurrent-ruby (~> 1.0)
56
66
  dry-core (~> 1.0, < 2)
57
67
  zeitwerk (~> 2.6)
68
+ dry-schema (1.13.0)
69
+ concurrent-ruby (~> 1.0)
70
+ dry-configurable (~> 1.0, >= 1.0.1)
71
+ dry-core (~> 1.0, < 2)
72
+ dry-initializer (~> 3.0)
73
+ dry-logic (>= 1.5, < 2)
74
+ dry-types (>= 1.7, < 2)
75
+ zeitwerk (~> 2.6)
58
76
  dry-struct (1.6.0)
59
77
  dry-core (~> 1.0, < 2)
60
78
  dry-types (>= 1.7, < 2)
@@ -66,11 +84,17 @@ GEM
66
84
  dry-inflector (~> 1.0, < 2)
67
85
  dry-logic (>= 1.4, < 2)
68
86
  zeitwerk (~> 2.6)
87
+ dry-validation (1.10.0)
88
+ concurrent-ruby (~> 1.0)
89
+ dry-core (~> 1.0, < 2)
90
+ dry-initializer (~> 3.0)
91
+ dry-schema (>= 1.12, < 2)
92
+ zeitwerk (~> 2.6)
69
93
  edtf (3.1.0)
70
94
  activesupport (>= 3.0, < 8.0)
71
95
  equivalent-xml (0.6.0)
72
96
  nokogiri (>= 1.4.3)
73
- faraday (2.7.0)
97
+ faraday (2.7.2)
74
98
  faraday-net_http (>= 2.0, < 3.1)
75
99
  ruby2_keywords (>= 0.0.4)
76
100
  faraday-net_http (3.0.2)
@@ -78,29 +102,31 @@ GEM
78
102
  i18n (1.12.0)
79
103
  concurrent-ruby (~> 1.0)
80
104
  ice_nine (0.11.2)
81
- json (2.6.2)
105
+ json (2.6.3)
82
106
  jsonpath (1.1.2)
83
107
  multi_json
108
+ launchy (2.5.0)
109
+ addressable (~> 2.7)
84
110
  minitest (5.16.3)
85
111
  multi_json (1.15.0)
86
- nokogiri (1.13.9-x86_64-darwin)
112
+ nokogiri (1.13.10-x86_64-darwin)
87
113
  racc (~> 1.4)
88
- nokogiri (1.13.9-x86_64-linux)
114
+ nokogiri (1.13.10-x86_64-linux)
89
115
  racc (~> 1.4)
90
116
  openapi3_parser (0.9.2)
91
117
  commonmarker (~> 0.17)
92
118
  openapi_parser (0.15.0)
93
119
  optimist (3.0.1)
94
120
  parallel (1.22.1)
95
- parser (3.1.2.1)
121
+ parser (3.1.3.0)
96
122
  ast (~> 2.4.1)
97
123
  patience_diff (1.2.0)
98
124
  optimist (~> 3.0)
99
- public_suffix (5.0.0)
100
- racc (1.6.0)
125
+ public_suffix (5.0.1)
126
+ racc (1.6.1)
101
127
  rainbow (3.1.1)
102
128
  rake (13.0.6)
103
- regexp_parser (2.6.0)
129
+ regexp_parser (2.6.1)
104
130
  rexml (3.2.5)
105
131
  rspec (3.12.0)
106
132
  rspec-core (~> 3.12.0)
@@ -111,7 +137,7 @@ GEM
111
137
  rspec-expectations (3.12.0)
112
138
  diff-lcs (>= 1.2.0, < 2.0)
113
139
  rspec-support (~> 3.12.0)
114
- rspec-mocks (3.12.0)
140
+ rspec-mocks (3.12.1)
115
141
  diff-lcs (>= 1.2.0, < 2.0)
116
142
  rspec-support (~> 3.12.0)
117
143
  rspec-support (3.12.0)
@@ -119,7 +145,7 @@ GEM
119
145
  rspec-core (>= 2, < 4, != 2.12.0)
120
146
  rss (0.2.9)
121
147
  rexml
122
- rubocop (1.39.0)
148
+ rubocop (1.40.0)
123
149
  json (~> 2.3)
124
150
  parallel (~> 1.10)
125
151
  parser (>= 3.1.2.1)
@@ -129,7 +155,7 @@ GEM
129
155
  rubocop-ast (>= 1.23.0, < 2.0)
130
156
  ruby-progressbar (~> 1.7)
131
157
  unicode-display_width (>= 1.4.0, < 3.0)
132
- rubocop-ast (1.23.0)
158
+ rubocop-ast (1.24.0)
133
159
  parser (>= 3.1.1.0)
134
160
  rubocop-rake (0.6.0)
135
161
  rubocop (~> 1.0)
@@ -0,0 +1,4 @@
1
+ authentication_proxy_url:
2
+ 'https://sdr-api-prod.stanford.edu': 'https://argo.stanford.edu/settings/tokens'
3
+ 'https://sdr-api-qa.stanford.edu': 'https://argo-qa.stanford.edu/settings/tokens'
4
+ 'https://sdr-api-stage.stanford.edu': 'https://argo-stage.stanford.edu/settings/tokens'
data/exe/sdr CHANGED
@@ -4,5 +4,6 @@
4
4
  $LOAD_PATH.unshift 'lib'
5
5
 
6
6
  require 'sdr_client'
7
+ require 'sdr_client/cli'
7
8
 
8
9
  SdrClient::CLI.start(ARGV)
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'config'
4
+
5
+ Config.setup do |config|
6
+ # Name of the constant exposing loaded settings
7
+ config.const_name = 'Settings'
8
+
9
+ # Load environment variables from the `ENV` object and override any
10
+ # settings defined in files.
11
+ config.use_env = true
12
+
13
+ # Define ENV variable prefix deciding which variables to load into
14
+ # config.
15
+ config.env_prefix = 'SETTINGS'
16
+
17
+ # What string to use as level separator for settings loaded from ENV
18
+ # variables. Default value of '.' works well with Heroku, but you might
19
+ # want to change it for example for '__' to easy override settings from
20
+ # command line, where using dots in variable names might not be allowed
21
+ # (eg. Bash).
22
+ config.env_separator = '__'
23
+
24
+ # Ability to process variables names:
25
+ # * nil - no change
26
+ # * :downcase - convert to lower case
27
+ config.env_converter = :downcase
28
+ end
29
+
30
+ Config.load_and_set_settings(
31
+ File.join(__dir__, '../../..', 'config/settings.yml')
32
+ )
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'launchy'
3
4
  require 'thor'
5
+ require_relative 'cli/config'
4
6
 
5
7
  module SdrClient
6
8
  # The SDR command-line interface
@@ -31,32 +33,19 @@ module SdrClient
31
33
 
32
34
  desc 'get DRUID', 'Retrieve an object from the SDR'
33
35
  def get(druid)
34
- say SdrClient::Find.run(druid, url: options[:url], logger: Logger.new($stderr))
35
- rescue SdrClient::Credentials::NoCredentialsError
36
- say_error 'Log in first'
37
- exit(1)
36
+ rescue_expected_exceptions do
37
+ say Find.run(druid, url: options[:url], logger: Logger.new($stderr))
38
+ end
38
39
  end
39
40
 
40
- desc 'login', 'Prompt for email & password and create a login token (saved in ~/.sdr/token)'
41
+ desc 'login', 'Open authentication proxy UI, or prompt for username and password, and then prompt for token (saved in ~/.sdr/credentials)'
41
42
  def login
42
- status = SdrClient::Login.run(
43
- url: options[:url],
44
- login_service: lambda do
45
- {
46
- email: ask('Email:'),
47
- password: ask('Password:', echo: false)
48
- }
49
- end
50
- )
51
- return puts unless status.failure?
52
-
53
- say_error status.failure
54
- exit(1)
43
+ authentication_proxy_url ? login_via_proxy : login_via_credentials
55
44
  end
56
45
 
57
46
  desc 'version', 'Display the SDR CLI version'
58
47
  def version
59
- say SdrClient::VERSION
48
+ say VERSION
60
49
  end
61
50
 
62
51
  desc 'update DRUID', 'Update an object in the SDR'
@@ -74,12 +63,11 @@ module SdrClient
74
63
  option :cocina_pipe, type: :boolean, default: false, desc: 'Indicate Cocina JSON is being piped in'
75
64
  option :basepath, default: Dir.getwd, desc: 'Base path for the files'
76
65
  def update(druid)
77
- validate_druid!(druid)
78
- job_id = SdrClient::Update.run(druid, **options)
79
- poll_for_job_complete(job_id: job_id, url: options[:url])
80
- rescue SdrClient::Credentials::NoCredentialsError
81
- say_error 'Log in first'
82
- exit(1)
66
+ rescue_expected_exceptions do
67
+ validate_druid!(druid)
68
+ job_id = Update.run(druid, **options)
69
+ poll_for_job_complete(job_id: job_id, url: options[:url])
70
+ end
83
71
  end
84
72
 
85
73
  desc 'deposit OPTIONAL_FILES', 'Deposit (accession) an object into the SDR'
@@ -122,16 +110,63 @@ module SdrClient
122
110
 
123
111
  private
124
112
 
125
- def register_or_deposit(files:, accession:)
126
- opts = munge_options(options, files)
127
- skip_polling = opts.delete(:skip_polling)
128
- job_id = SdrClient::Deposit.run(accession: accession, **opts)
129
- return if skip_polling
130
-
131
- poll_for_job_complete(job_id: job_id, url: opts[:url])
132
- rescue SdrClient::Credentials::NoCredentialsError
133
- say_error 'Log in first'
113
+ def rescue_expected_exceptions
114
+ yield
115
+ rescue UnexpectedResponse::TokenExpired
116
+ say_error 'Token has expired! Please log in again.'
134
117
  exit(1)
118
+ rescue Credentials::NoCredentialsError
119
+ say_error 'No token found! Please log in first.'
120
+ exit(1)
121
+ end
122
+
123
+ def login_via_proxy
124
+ say 'Opened the configured authentication proxy in your browser. Once there, generate a new token and copy the entire value.'
125
+ Launchy.open(authentication_proxy_url)
126
+ # Some CLI environments will pop up a message about opening the URL in
127
+ # an existing browse. Since this is OS-dependency, and not something
128
+ # we can control via Launchy, just wait a bit before rendering the
129
+ # `ask` prompt so it's clearer to the user what's happening
130
+ sleep 0.5
131
+ token_string = ask('Paste token here:')
132
+ Credentials.write(token_string)
133
+ expiry = JSON.parse(token_string)['exp']
134
+ say "You are now authenticated for #{options[:url]} until #{expiry}"
135
+ rescue StandardError => e
136
+ say_error "Error logging in via proxy: #{e}"
137
+ exit(1)
138
+ end
139
+
140
+ def login_via_credentials
141
+ status = Login.run(
142
+ url: options[:url],
143
+ login_service: lambda do
144
+ {
145
+ email: ask('Email:'),
146
+ password: ask('Password:', echo: false)
147
+ }
148
+ end
149
+ )
150
+
151
+ return puts unless status.failure?
152
+
153
+ say_error status.failure
154
+ exit(1)
155
+ end
156
+
157
+ def authentication_proxy_url
158
+ @authentication_proxy_url ||= Settings.authentication_proxy_url[options[:url]]
159
+ end
160
+
161
+ def register_or_deposit(files:, accession:)
162
+ rescue_expected_exceptions do
163
+ opts = munge_options(options, files)
164
+ skip_polling = opts.delete(:skip_polling)
165
+ job_id = Deposit.run(accession: accession, **opts)
166
+ return if skip_polling
167
+
168
+ poll_for_job_complete(job_id: job_id, url: opts[:url])
169
+ end
135
170
  end
136
171
 
137
172
  def munge_options(options, files)
@@ -141,9 +176,9 @@ module SdrClient
141
176
  opts[:files_metadata] = JSON.parse(options[:files_metadata]) if options[:files_metadata]
142
177
  if options[:grouping_strategy]
143
178
  opts[:grouping_strategy] = if options[:grouping_strategy] == 'filename'
144
- SdrClient::Deposit::MatchingFileGroupingStrategy
179
+ Deposit::MatchingFileGroupingStrategy
145
180
  else
146
- SdrClient::Deposit::SingleFileGroupingStrategy
181
+ Deposit::SingleFileGroupingStrategy
147
182
  end
148
183
  end
149
184
  end
@@ -161,7 +196,7 @@ module SdrClient
161
196
  say('SDR is processing your request.', nil, false)
162
197
  result = nil
163
198
  1.upto(60) do
164
- result = SdrClient::BackgroundJobResults.show(url: url, job_id: job_id)
199
+ result = BackgroundJobResults.show(url: url, job_id: job_id)
165
200
  break unless %w[pending processing].include?(result['status'])
166
201
 
167
202
  # the extra args to `say` prevent appending a newline
@@ -101,7 +101,6 @@ require 'sdr_client/deposit/request'
101
101
  require 'sdr_client/deposit/metadata_builder'
102
102
  require 'sdr_client/deposit/model_process'
103
103
  require 'sdr_client/deposit/process'
104
- require 'sdr_client/deposit/unexpected_response'
105
104
  require 'sdr_client/deposit/update_resource'
106
105
  require 'sdr_client/deposit/update_dro_with_file_identifiers'
107
106
  require 'sdr_client/deposit/upload_files'
@@ -7,9 +7,6 @@ module SdrClient
7
7
  module Find
8
8
  DRO_PATH = '/v1/resources/%<id>s'
9
9
 
10
- # Raised when find returns an unsuccessful response
11
- class Failed < StandardError; end
12
-
13
10
  # @raise [Failed] if the find operation fails
14
11
  # @return [String] JSON for the given Cocina object or an error
15
12
  def self.run(druid, url:, logger: Logger.new($stdout))
@@ -17,12 +14,10 @@ module SdrClient
17
14
  path = format(DRO_PATH, id: druid)
18
15
  logger.info("Retrieving metadata from: #{path}")
19
16
  response = connection.get(path)
20
- unless response.success?
21
- error_message = "There was an HTTP #{response.status} error making the request: #{response.body}"
22
- logger.error(error_message)
23
- raise Failed, error_message
24
- end
25
- response.body
17
+ return response.body if response.success?
18
+
19
+ logger.error("There was an HTTP #{response.status} error making the request: #{response.body}")
20
+ UnexpectedResponse.call(response)
26
21
  end
27
22
  end
28
23
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SdrClient
4
+ # Handles unexpected responses
5
+ class UnexpectedResponse
6
+ # Raised when there is a request error (e.g.: a cocina-models version mismatch)
7
+ class BadRequest < StandardError; end
8
+ # Raised when there is a problem with the credentials
9
+ class Unauthorized < StandardError; end
10
+ # Raised when there is an expired token
11
+ class TokenExpired < StandardError; end
12
+
13
+ # @param [Faraday::Response] response
14
+ def self.call(response)
15
+ case response.status
16
+ when 400
17
+ raise BadRequest, "There was an error with your request: #{response.body}"
18
+ when 401
19
+ raise TokenExpired, 'Your token has expired' if response.body.match?('Signature has expired')
20
+
21
+ raise Unauthorized, 'There was an error with your credentials.'
22
+ else
23
+ raise "unexpected response: #{response.status} #{response.body}"
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SdrClient
4
- VERSION = '1.0.0'
4
+ VERSION = '2.0.1'
5
5
  end
data/lib/sdr_client.rb CHANGED
@@ -9,13 +9,13 @@ require 'active_support/core_ext/file/atomic'
9
9
  require 'cocina/models'
10
10
 
11
11
  require 'sdr_client/version'
12
+ require 'sdr_client/unexpected_response'
12
13
  require 'sdr_client/deposit'
13
14
  require 'sdr_client/update'
14
15
  require 'sdr_client/credentials'
15
16
  require 'sdr_client/find'
16
17
  require 'sdr_client/login'
17
18
  require 'sdr_client/login_prompt'
18
- require 'sdr_client/cli'
19
19
  require 'sdr_client/connection'
20
20
  require 'sdr_client/background_job_results'
21
21
 
data/sdr-client.gemspec CHANGED
@@ -29,8 +29,10 @@ Gem::Specification.new do |spec|
29
29
 
30
30
  spec.add_dependency 'activesupport'
31
31
  spec.add_dependency 'cocina-models', '~> 0.86.0'
32
+ spec.add_dependency 'config'
32
33
  spec.add_dependency 'dry-monads'
33
34
  spec.add_dependency 'faraday', '>= 0.16'
35
+ spec.add_dependency 'launchy'
34
36
 
35
37
  spec.add_development_dependency 'bundler', '~> 2.0'
36
38
  spec.add_development_dependency 'rake', '~> 13.0'
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: 1.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-16 00:00:00.000000000 Z
11
+ date: 2022-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.86.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: config
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: dry-monads
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,20 @@ dependencies:
66
80
  - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0.16'
83
+ - !ruby/object:Gem::Dependency
84
+ name: launchy
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: bundler
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -215,12 +243,14 @@ files:
215
243
  - Rakefile
216
244
  - bin/console
217
245
  - bin/setup
246
+ - config/settings.yml
218
247
  - exe/remove_w3cdtf_encoding_from_event_dates
219
248
  - exe/sdr
220
249
  - lib/sdr-client.rb
221
250
  - lib/sdr_client.rb
222
251
  - lib/sdr_client/background_job_results.rb
223
252
  - lib/sdr_client/cli.rb
253
+ - lib/sdr_client/cli/config.rb
224
254
  - lib/sdr_client/connection.rb
225
255
  - lib/sdr_client/credentials.rb
226
256
  - lib/sdr_client/deposit.rb
@@ -241,7 +271,6 @@ files:
241
271
  - lib/sdr_client/deposit/process.rb
242
272
  - lib/sdr_client/deposit/request.rb
243
273
  - lib/sdr_client/deposit/single_file_grouping_strategy.rb
244
- - lib/sdr_client/deposit/unexpected_response.rb
245
274
  - lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
246
275
  - lib/sdr_client/deposit/update_resource.rb
247
276
  - lib/sdr_client/deposit/upload_files.rb
@@ -249,6 +278,7 @@ files:
249
278
  - lib/sdr_client/find.rb
250
279
  - lib/sdr_client/login.rb
251
280
  - lib/sdr_client/login_prompt.rb
281
+ - lib/sdr_client/unexpected_response.rb
252
282
  - lib/sdr_client/update.rb
253
283
  - lib/sdr_client/version.rb
254
284
  - sdr-client.gemspec
@@ -259,7 +289,7 @@ metadata:
259
289
  source_code_uri: https://github.com/sul-dlss/sdr-client
260
290
  changelog_uri: https://github.com/sul-dlss/sdr-client/releases
261
291
  rubygems_mfa_required: 'true'
262
- post_install_message:
292
+ post_install_message:
263
293
  rdoc_options: []
264
294
  require_paths:
265
295
  - lib
@@ -274,8 +304,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
274
304
  - !ruby/object:Gem::Version
275
305
  version: '0'
276
306
  requirements: []
277
- rubygems_version: 3.3.7
278
- signing_key:
307
+ rubygems_version: 3.2.32
308
+ signing_key:
279
309
  specification_version: 4
280
310
  summary: The CLI for https://github.com/sul-dlss/sdr-api
281
311
  test_files: []
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SdrClient
4
- module Deposit
5
- # Handles unexpected responses when manipulating resources
6
- class UnexpectedResponse
7
- # Raised when there is a request error (e.g.: a cocina-models version mismatch)
8
- class BadRequest < StandardError; end
9
- # Raised when there is a problem with the credentials
10
- class Unauthorized < StandardError; end
11
-
12
- # @param [Faraday::Response] response
13
- def self.call(response)
14
- case response.status
15
- when 400
16
- raise BadRequest, "There was an error with your request: #{response.body}"
17
- when 401
18
- raise Unauthorized, 'There was an error with your credentials. Perhaps they have expired?'
19
- else
20
- raise "unexpected response: #{response.status} #{response.body}"
21
- end
22
- end
23
- end
24
- end
25
- end