sdr-client 0.9.0 → 0.10.0

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: '0578c4fbb93d5b8118a9d55f9751f1b50b633d15405411a31b8a4376b3d2f297'
4
- data.tar.gz: 0bc45cbbe780f1e386685bca4cd500ca8ed8b227ddd0377c290c36b918a5dd96
3
+ metadata.gz: fcebebb756bf3279381b14725819fe9580fe0e3526b6a6f57994dd1ad59e8c27
4
+ data.tar.gz: bec945fdf457d1d721a7fc3f708e3359a2bf50baa9cab69ebac036ca7328a495
5
5
  SHA512:
6
- metadata.gz: 8cc065044b53e035c4eb73901ab635684c8b956ec280713ad50293e410a6525c5d15d274acaf7cf266f3a7f31a77309c85a9067449f03885ca1abde0b0e4d53a
7
- data.tar.gz: 7a03cfd0cbf6a48e2fea9c71fb587c74e58b624a6ce1a299c55534c7fce9043d0a4dd0c4682f914ad54b4074bf4fda4ee95e3c70ac3d17d77d0b0a6c9a786bf0
6
+ metadata.gz: a6873936d630a75a1f0c1459aee9d96af00a7c2ffad15cd333ae996868bfd29f5c3e2b896ea3e53e54c4bbb1a2694525f35bedf08543059453478691c42a7078
7
+ data.tar.gz: d4dc87b636430d81d6db9fcc5aa63530f4e0b87284fcc92293f8dafa0dce3477b75d8177f62c6c0bd292bbdb870ba7fd0a7a3328a9127dab2f963df419bf1600
@@ -62,10 +62,10 @@ module SdrClient
62
62
  end
63
63
 
64
64
  def unexpected_response(response)
65
- raise "unexpected response: #{response.inspect}" unless response.status == 400
65
+ raise "There was an error with your request: #{response.body}" if response.status == 400
66
+ raise 'There was an error with your credentials. Perhaps they have expired?' if response.status == 401
66
67
 
67
- puts "\nThere was an error with your request: #{response.body}"
68
- exit(1)
68
+ raise "unexpected response: #{response.inspect}"
69
69
  end
70
70
 
71
71
  def connection
@@ -5,6 +5,7 @@ module SdrClient
5
5
  # This represents the metadata that we send to the server for doing a deposit
6
6
  class Request
7
7
  # @param [String] label the required object label
8
+ # @param [Time|nil] embargo_release_date when the item should be released from embargo or nil if no embargo
8
9
  # @param [String] type (http://cocina.sul.stanford.edu/models/object.jsonld) the required object type.
9
10
  # @param [Array<FileSet>] file_sets the file sets to attach.
10
11
  # @param [Hash<String, Hash<String, String>>] files_metadata file name, hash of additional file metadata
@@ -15,6 +16,7 @@ module SdrClient
15
16
  collection:,
16
17
  source_id:,
17
18
  catkey: nil,
19
+ embargo_release_date: nil,
18
20
  type: 'http://cocina.sul.stanford.edu/models/object.jsonld',
19
21
  file_sets: [],
20
22
  files_metadata: {})
@@ -23,6 +25,7 @@ module SdrClient
23
25
  @source_id = source_id
24
26
  @collection = collection
25
27
  @catkey = catkey
28
+ @embargo_release_date = embargo_release_date
26
29
  @apo = apo
27
30
  @file_sets = file_sets
28
31
  @files_metadata = files_metadata
@@ -31,7 +34,7 @@ module SdrClient
31
34
 
32
35
  def as_json
33
36
  {
34
- access: {},
37
+ access: access,
35
38
  type: type,
36
39
  administrative: administrative,
37
40
  identification: identification,
@@ -48,6 +51,7 @@ module SdrClient
48
51
  collection: collection,
49
52
  source_id: source_id,
50
53
  catkey: catkey,
54
+ embargo_release_date: embargo_release_date,
51
55
  type: type,
52
56
  file_sets: file_sets,
53
57
  files_metadata: files_metadata)
@@ -62,7 +66,7 @@ module SdrClient
62
66
  private
63
67
 
64
68
  attr_reader :label, :file_sets, :source_id, :catkey, :apo, :collection,
65
- :type, :files_metadata
69
+ :type, :files_metadata, :embargo_release_date
66
70
 
67
71
  def administrative
68
72
  {
@@ -82,6 +86,12 @@ module SdrClient
82
86
  contains: file_sets.map(&:as_json)
83
87
  }
84
88
  end
89
+
90
+ def access
91
+ {}.tap do |json|
92
+ json[:embargoReleaseDate] = embargo_release_date.strftime('%FT%T%:z') if embargo_release_date
93
+ end
94
+ end
85
95
  end
86
96
  end
87
97
  end
@@ -47,13 +47,19 @@ module SdrClient
47
47
  def direct_upload(metadata_json)
48
48
  logger.info("Starting an upload request: #{metadata_json}")
49
49
  response = connection.post(BLOB_PATH, metadata_json, 'Content-Type' => 'application/json')
50
- raise "unexpected response: #{response.inspect}" unless response.status == 200
50
+ unexpected_response(response) unless response.status == 200
51
51
 
52
52
  logger.info("Response from server: #{response.body}")
53
53
 
54
54
  Files::DirectUploadResponse.new(JSON.parse(response.body))
55
55
  end
56
56
 
57
+ def unexpected_response(response)
58
+ raise 'There was an error with your credentials. Perhaps they have expired?' if response.status == 401
59
+
60
+ raise "unexpected response: #{response.inspect}"
61
+ end
62
+
57
63
  # @param [Hash<String,Files::DirectUploadResponse>] upload_responses the filenames and their upload response
58
64
  def upload_files(upload_responses)
59
65
  upload_responses.each do |filename, response|
@@ -11,6 +11,7 @@ module SdrClient
11
11
  apo:,
12
12
  collection:,
13
13
  catkey: nil,
14
+ embargo_release_date: nil,
14
15
  source_id:,
15
16
  url:,
16
17
  files: [],
@@ -25,6 +26,7 @@ module SdrClient
25
26
  collection: collection,
26
27
  source_id: source_id,
27
28
  catkey: catkey,
29
+ embargo_release_date: embargo_release_date,
28
30
  files_metadata: files_metadata)
29
31
  Process.new(metadata: metadata, url: url, token: token, files: files,
30
32
  grouping_strategy: grouping_strategy, logger: logger).run
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SdrClient
4
- VERSION = '0.9.0'
4
+ VERSION = '0.10.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.9.0
4
+ version: 0.10.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: 2020-02-07 00:00:00.000000000 Z
11
+ date: 2020-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-monads
@@ -198,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
198
  - !ruby/object:Gem::Version
199
199
  version: '0'
200
200
  requirements: []
201
- rubygems_version: 3.0.3
201
+ rubygems_version: 3.1.2
202
202
  signing_key:
203
203
  specification_version: 4
204
204
  summary: The CLI for https://github.com/sul-dlss/sdr-api