sdr-client 1.0.0 → 2.0.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: a66643c6ea7e08e14f529c7e5396a5037ab39cae895fa65bb7ddf7a6d98ca93c
4
- data.tar.gz: 7a7986eb90c7de9eb1f4b0335e4bae0981fe2679ac2317de2f66daaee92f141f
3
+ metadata.gz: 1889b3e5a4bda3ce260dd4a0d9671f8ce3ab0db9ae7f05584d18f9f556e7bd0a
4
+ data.tar.gz: aa6ad237bd7febc4c74d40fdff148faa9ede2c0a560b010bce7d42b3cb295589
5
5
  SHA512:
6
- metadata.gz: 8fc2bb28ace65e03d8cf5336b080924a7ed6d2899cf5d2d54459b38b3d2849738cdaf9bee4fb8021a5b174f3062410748e20345cba9e10e42690995d4e0cd9f9
7
- data.tar.gz: 4a3dcc3903a17266469c3ad2ca18c2d3fbb7ff57b1711b5753993a5202361d7cb9b526fbef9806a31daabcebc307cae4ba052b5f185bd6a34bfb75e694fbfd11
6
+ metadata.gz: 9d5f381820d655416d1c8da19db0911af0a016d83fe4970f1a64d03bc8f9f2709f93c05ff0f367ad9bcb1e94f44fed86ef61798312a98660e3bf0e8ca2f1dfbc
7
+ data.tar.gz: 8b5dadcc030463318a87444611294571af60c18bd35d52fe5d0c89ddf7dbd71e4ecf66ec9df3bb21a60a4846cedf3f9e3b6d77835a14a959ec7268d75a17f618
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sdr-client (1.0.0)
4
+ sdr-client (2.0.0)
5
5
  activesupport
6
6
  cocina-models (~> 0.86.0)
7
7
  dry-monads
@@ -37,17 +37,25 @@ GEM
37
37
  zeitwerk (~> 2.1)
38
38
  commonmarker (0.23.6)
39
39
  concurrent-ruby (1.1.10)
40
+ config (4.1.0)
41
+ deep_merge (~> 1.2, >= 1.2.1)
42
+ dry-validation (~> 1.0, >= 1.0.0)
40
43
  crack (0.4.5)
41
44
  rexml
45
+ deep_merge (1.2.2)
42
46
  deprecation (1.1.0)
43
47
  activesupport
44
48
  diff-lcs (1.5.0)
45
49
  docile (1.4.0)
50
+ dry-configurable (1.0.1)
51
+ dry-core (~> 1.0, < 2)
52
+ zeitwerk (~> 2.6)
46
53
  dry-core (1.0.0)
47
54
  concurrent-ruby (~> 1.0)
48
55
  zeitwerk (~> 2.6)
49
56
  dry-inflector (1.0.0)
50
- dry-logic (1.4.0)
57
+ dry-initializer (3.1.1)
58
+ dry-logic (1.5.0)
51
59
  concurrent-ruby (~> 1.0)
52
60
  dry-core (~> 1.0, < 2)
53
61
  zeitwerk (~> 2.6)
@@ -55,6 +63,14 @@ GEM
55
63
  concurrent-ruby (~> 1.0)
56
64
  dry-core (~> 1.0, < 2)
57
65
  zeitwerk (~> 2.6)
66
+ dry-schema (1.13.0)
67
+ concurrent-ruby (~> 1.0)
68
+ dry-configurable (~> 1.0, >= 1.0.1)
69
+ dry-core (~> 1.0, < 2)
70
+ dry-initializer (~> 3.0)
71
+ dry-logic (>= 1.5, < 2)
72
+ dry-types (>= 1.7, < 2)
73
+ zeitwerk (~> 2.6)
58
74
  dry-struct (1.6.0)
59
75
  dry-core (~> 1.0, < 2)
60
76
  dry-types (>= 1.7, < 2)
@@ -66,11 +82,17 @@ GEM
66
82
  dry-inflector (~> 1.0, < 2)
67
83
  dry-logic (>= 1.4, < 2)
68
84
  zeitwerk (~> 2.6)
85
+ dry-validation (1.10.0)
86
+ concurrent-ruby (~> 1.0)
87
+ dry-core (~> 1.0, < 2)
88
+ dry-initializer (~> 3.0)
89
+ dry-schema (>= 1.12, < 2)
90
+ zeitwerk (~> 2.6)
69
91
  edtf (3.1.0)
70
92
  activesupport (>= 3.0, < 8.0)
71
93
  equivalent-xml (0.6.0)
72
94
  nokogiri (>= 1.4.3)
73
- faraday (2.7.0)
95
+ faraday (2.7.1)
74
96
  faraday-net_http (>= 2.0, < 3.1)
75
97
  ruby2_keywords (>= 0.0.4)
76
98
  faraday-net_http (3.0.2)
@@ -78,29 +100,31 @@ GEM
78
100
  i18n (1.12.0)
79
101
  concurrent-ruby (~> 1.0)
80
102
  ice_nine (0.11.2)
81
- json (2.6.2)
103
+ json (2.6.3)
82
104
  jsonpath (1.1.2)
83
105
  multi_json
106
+ launchy (2.5.0)
107
+ addressable (~> 2.7)
84
108
  minitest (5.16.3)
85
109
  multi_json (1.15.0)
86
- nokogiri (1.13.9-x86_64-darwin)
110
+ nokogiri (1.13.10-x86_64-darwin)
87
111
  racc (~> 1.4)
88
- nokogiri (1.13.9-x86_64-linux)
112
+ nokogiri (1.13.10-x86_64-linux)
89
113
  racc (~> 1.4)
90
114
  openapi3_parser (0.9.2)
91
115
  commonmarker (~> 0.17)
92
116
  openapi_parser (0.15.0)
93
117
  optimist (3.0.1)
94
118
  parallel (1.22.1)
95
- parser (3.1.2.1)
119
+ parser (3.1.3.0)
96
120
  ast (~> 2.4.1)
97
121
  patience_diff (1.2.0)
98
122
  optimist (~> 3.0)
99
- public_suffix (5.0.0)
100
- racc (1.6.0)
123
+ public_suffix (5.0.1)
124
+ racc (1.6.1)
101
125
  rainbow (3.1.1)
102
126
  rake (13.0.6)
103
- regexp_parser (2.6.0)
127
+ regexp_parser (2.6.1)
104
128
  rexml (3.2.5)
105
129
  rspec (3.12.0)
106
130
  rspec-core (~> 3.12.0)
@@ -111,7 +135,7 @@ GEM
111
135
  rspec-expectations (3.12.0)
112
136
  diff-lcs (>= 1.2.0, < 2.0)
113
137
  rspec-support (~> 3.12.0)
114
- rspec-mocks (3.12.0)
138
+ rspec-mocks (3.12.1)
115
139
  diff-lcs (>= 1.2.0, < 2.0)
116
140
  rspec-support (~> 3.12.0)
117
141
  rspec-support (3.12.0)
@@ -119,7 +143,7 @@ GEM
119
143
  rspec-core (>= 2, < 4, != 2.12.0)
120
144
  rss (0.2.9)
121
145
  rexml
122
- rubocop (1.39.0)
146
+ rubocop (1.40.0)
123
147
  json (~> 2.3)
124
148
  parallel (~> 1.10)
125
149
  parser (>= 3.1.2.1)
@@ -129,7 +153,7 @@ GEM
129
153
  rubocop-ast (>= 1.23.0, < 2.0)
130
154
  ruby-progressbar (~> 1.7)
131
155
  unicode-display_width (>= 1.4.0, < 3.0)
132
- rubocop-ast (1.23.0)
156
+ rubocop-ast (1.24.0)
133
157
  parser (>= 3.1.1.0)
134
158
  rubocop-rake (0.6.0)
135
159
  rubocop (~> 1.0)
@@ -165,6 +189,8 @@ PLATFORMS
165
189
  DEPENDENCIES
166
190
  bundler (~> 2.0)
167
191
  byebug
192
+ config
193
+ launchy
168
194
  rake (~> 13.0)
169
195
  rspec (~> 3.0)
170
196
  rspec_junit_formatter
@@ -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,30 @@
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('config/settings.yml')
@@ -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.0'
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
@@ -33,6 +33,8 @@ Gem::Specification.new do |spec|
33
33
  spec.add_dependency 'faraday', '>= 0.16'
34
34
 
35
35
  spec.add_development_dependency 'bundler', '~> 2.0'
36
+ spec.add_development_dependency 'config'
37
+ spec.add_development_dependency 'launchy'
36
38
  spec.add_development_dependency 'rake', '~> 13.0'
37
39
  spec.add_development_dependency 'rspec', '~> 3.0'
38
40
  spec.add_development_dependency 'rubocop', '~> 1.24'
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.0
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-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: config
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: launchy
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: rake
85
113
  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