sdr-client 0.60.0 → 0.63.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: 827537801986b42218654f8edb47fe460c1bb9cf802ed11b1f9bd22fe6c419f0
4
- data.tar.gz: c60c836e2822365cead36f7dfec7984bbe903b331b7eccf1483810a1598e8188
3
+ metadata.gz: 78ea65d3c9a57d94b5c1e0ec9570d8d46de57b6b96a241075bad23fe2d5f6951
4
+ data.tar.gz: 19f5e7b0f327b74654f6affd1aa2d1af63c3638574aa8b7c2aecd66d9596e5db
5
5
  SHA512:
6
- metadata.gz: 818ea7f4c057215f2160375043cf58569256448159eda5d71863558cd9d55fdbe3cab21ac729769940251a582e31878ce1d5f3a2f3d2a130902f57718178c453
7
- data.tar.gz: 17aafa6c32f3f95792f0cfa08c31ffb5acddd0158b1fa36c7c1bfbefd97b097e144d8faab4e899ee0cd6bdeaf07d03a85d84442c48f6a4ca4e6a6d65b29caf80
6
+ metadata.gz: 57d3cfa7e333339a774fdba3085cbf7323d6d9fca9804f74382198cbaac9d2210de654345baddfccdfc6b412a9ab619c8c800217da30e849b551912cacd25269
7
+ data.tar.gz: d04753f61d433a8c5f80317e1a8e7ebda1c70f1b361096d07fdc934950819316918165e5f466b53724a29a062cdb48882f4263d0d42b066cca20a0aa47b8949f
data/.circleci/config.yml CHANGED
@@ -3,7 +3,7 @@ version: 2.1
3
3
  jobs:
4
4
  build:
5
5
  docker:
6
- - image: circleci/ruby:2.7.1
6
+ - image: cimg/ruby:3.0
7
7
  environment:
8
8
  CC_TEST_REPORTER_ID: 859fcfe88b00c026d15dce30e838e2299face8088b49fe62bc3a02d1507ce3d5
9
9
  RAILS_ENV: test
@@ -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: 360)
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.60.0'
4
+ VERSION = '0.63.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: 0.60.0
4
+ version: 0.63.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-08-17 00:00:00.000000000 Z
11
+ date: 2022-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -239,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
239
  - !ruby/object:Gem::Version
240
240
  version: '0'
241
241
  requirements: []
242
- rubygems_version: 3.1.4
242
+ rubygems_version: 3.2.32
243
243
  signing_key:
244
244
  specification_version: 4
245
245
  summary: The CLI for https://github.com/sul-dlss/sdr-api