sdr-client 0.59.0 → 0.62.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: dc628ea7480d2ef9102b3fa37f37fe23b0fa9ee11d7a883251b465b3f7518112
4
- data.tar.gz: 8d0e09c1a92f0ee87be08efbbd359fd4499f671a0a3de9c7edde4afeaca70942
3
+ metadata.gz: f26953315bf59c1c2485836f1b5485877bb58faa0375eca118016a3e1e3f5932
4
+ data.tar.gz: 9a00c929a3aa2da9a1698c97694dcd72d789289a83e4d6d9f330d404ad679d24
5
5
  SHA512:
6
- metadata.gz: 560557769b5867a0dbcb5c5f7ba9f5bb4ccb3b6e93637fc35df4e5a8f389dc9d4ab06bdacbb220d06d5a4f0af30761836740febe7be516a72355854fd834f581
7
- data.tar.gz: 38a5f18f6f4bb293731058f08407dc42790ab2932c0d8ff0d9bcdaeedfb79cb880ae065756953411a2f9a7839539310fdb40982ac212a643fc0c08d789b38f46
6
+ metadata.gz: f7a6daaa1c032403ba01e9ce45660fc8e71107d37fac3995af8ed73a9a1ff53e6e75a513326fc20c14e94129ec7cf4d7f711e1961ddfb82044da293fe508d46e
7
+ data.tar.gz: 9943f57b33e782840746d6208479aa4732d15d8dedafcd2a44bc58c153a31485bcf4663670e41d011592e727d7ba9b53732f1e4879e74a5895cdc002f41a0ab8
@@ -5,14 +5,16 @@ module SdrClient
5
5
  class Connection
6
6
  include Dry::Monads[:result]
7
7
 
8
- def initialize(url:, token: Credentials.read)
8
+ # @param [Integer] read_timeout the value in seconds to set the read timeout
9
+ def initialize(url:, token: Credentials.read, read_timeout: 180)
9
10
  @url = url
10
11
  @token = token
12
+ @request_options = { read_timeout: read_timeout }
11
13
  end
12
14
 
13
15
  def connection
14
- @connection ||= Faraday.new(url: url) do |conn|
15
- conn.authorization :Bearer, token
16
+ @connection ||= Faraday.new(url: url, request: request_options) do |conn|
17
+ conn.request :authorization, :Bearer, token
16
18
  conn.adapter :net_http
17
19
  end
18
20
  end
@@ -36,6 +38,6 @@ module SdrClient
36
38
 
37
39
  private
38
40
 
39
- attr_reader :url, :token
41
+ attr_reader :url, :token, :request_options
40
42
  end
41
43
  end
@@ -4,12 +4,21 @@ module SdrClient
4
4
  module Deposit
5
5
  # Handles unexpected responses when manipulating resources
6
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
+
7
12
  # @param [Faraday::Response] response
8
13
  def self.call(response)
9
- raise "There was an error with your request: #{response.body}" if response.status == 400
10
- raise 'There was an error with your credentials. Perhaps they have expired?' if response.status == 401
11
-
12
- raise "unexpected response: #{response.status} #{response.body}"
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
13
22
  end
14
23
  end
15
24
  end
@@ -38,6 +38,8 @@ module SdrClient
38
38
  Hash[file_metadata.map { |filename, metadata| [filename, direct_upload(metadata.to_json)] }]
39
39
  end
40
40
 
41
+ # This creates a signed token that we can use to upload the file. This token has an expiration set in sdr-api,
42
+ # so we have to use it before it expires.
41
43
  def direct_upload(metadata_json)
42
44
  logger.info("Starting an upload request: #{metadata_json}")
43
45
  response = connection.post(BLOB_PATH, metadata_json, 'Content-Type' => 'application/json')
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SdrClient
4
- VERSION = '0.59.0'
4
+ VERSION = '0.62.0'
5
5
  end
data/sdr-client.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.require_paths = ['lib']
29
29
 
30
30
  spec.add_dependency 'activesupport'
31
- spec.add_dependency 'cocina-models', '~> 0.61.0'
31
+ spec.add_dependency 'cocina-models', '~> 0.62.0'
32
32
  spec.add_dependency 'dry-monads'
33
33
  spec.add_dependency 'faraday', '>= 0.16'
34
34
 
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: 0.59.0
4
+ version: 0.62.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: 2021-07-14 00:00:00.000000000 Z
11
+ date: 2022-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.61.0
33
+ version: 0.62.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.61.0
40
+ version: 0.62.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: dry-monads
43
43
  requirement: !ruby/object:Gem::Requirement