sdr-client 0.3.1 → 0.4.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: 4c634551367640a9eb3647e55fcac169a61b40af1a111582d3e857bc2cc1f020
4
- data.tar.gz: 75f3a024adf97dad2cf85a8e8b117a232c71b2f644655b98752c1320af005e17
3
+ metadata.gz: b1d76c1422877b6b5f25f0a1cb46641e32771496771576f8f7c8fd2697c14b0e
4
+ data.tar.gz: eb116e73a114a3966254a0996c5d843fc960e1454146214ca68fae11eff89bda
5
5
  SHA512:
6
- metadata.gz: 04a14d2edbb8334fbcc13b7ae131d7bf1697869c580395c2ea8c2971c18b911d55b7b0128e0cdff25b7a5844333f11eb2af23bc435ab7c6e692e4951092e22ed
7
- data.tar.gz: 6c3369f015d8e3201ba1f58664c4d9b15208064eb5fdd24deca2de26ae7d4575889d22f7aa25eacb2e1232cfd2068d288771c6ba0c04737b7e5fc6c7508d2ba8
6
+ metadata.gz: acf219c807f4f22f87437f779cf4d3ab2bb8091bc810a616146a302a9e2bab4b5be99685c91ea072056344a59b5b0f37e9ed5008105d836078d1b70032720c75
7
+ data.tar.gz: b6ec07336e2014a6fbf02470c08649c426384a51c40ee32a164f29c96ab75cd2057615ee5ee8081f7a70f406f794fed6c100fb93aba7848d629e8933fa91f589
data/README.md CHANGED
@@ -8,6 +8,10 @@
8
8
  This is a CLI for interacting with the Stanford Digital Repository API.
9
9
  The code for the SDR API server is at https://github.com/sul-dlss/sdr-api
10
10
 
11
+ ## Install
12
+
13
+ `gem install sdr-client`
14
+
11
15
  ## Usage
12
16
 
13
17
  Log in:
@@ -23,6 +23,7 @@ module SdrClient
23
23
  end
24
24
  end
25
25
  require 'json'
26
+ require 'sdr_client/deposit/default_file_set_builder'
26
27
  require 'sdr_client/deposit/files/direct_upload_request'
27
28
  require 'sdr_client/deposit/files/direct_upload_response'
28
29
  require 'sdr_client/deposit/file'
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SdrClient
4
+ module Deposit
5
+ # This strategy is for building one file set per uploaded file
6
+ class DefaultFileSetBuilder
7
+ # @return [Request] request The initial request
8
+ # @param [Array<SdrClient::Deposit::Files::DirectUploadResponse>] uploads the uploaded files to attach.
9
+ # @return [Request] a clone of this request with the uploads added
10
+ def self.run(request:, uploads: [])
11
+ file_sets = uploads.each_with_index.map do |upload, i|
12
+ FileSet.new(uploads: [upload], label: "Object #{i + 1}")
13
+ end
14
+ request.with_file_sets(file_sets)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -9,16 +9,19 @@ module SdrClient
9
9
  BLOB_PATH = '/v1/direct_uploads'
10
10
  DRO_PATH = '/v1/resources'
11
11
  # @param [Request] metadata information about the object
12
+ # @param [#build] file_set_builder a strategy for constructing FileSets
12
13
  # @param [String] url the server to send to
13
14
  # @param [String] token the bearer auth token for the server
14
15
  # @param [Array<String>] files a list of file names to upload
15
16
  # @param [Logger] logger the logger to use
16
- def initialize(metadata:, url:, token:, files: [], logger: Logger.new(STDOUT))
17
+ def initialize(metadata:, file_set_builder: DefaultFileSetBuilder, url:,
18
+ token:, files: [], logger: Logger.new(STDOUT))
17
19
  @files = files
18
20
  @url = url
19
21
  @token = token
20
22
  @metadata = metadata
21
23
  @logger = logger
24
+ @file_set_builder = file_set_builder
22
25
  end
23
26
 
24
27
  def run
@@ -26,13 +29,13 @@ module SdrClient
26
29
  file_metadata = collect_file_metadata
27
30
  upload_responses = upload_file_metadata(file_metadata)
28
31
  upload_files(upload_responses)
29
- request = metadata.with_uploads(upload_responses.values)
32
+ request = file_set_builder.run(request: metadata, uploads: upload_responses.values)
30
33
  upload_metadata(request.as_json)
31
34
  end
32
35
 
33
36
  private
34
37
 
35
- attr_reader :metadata, :files, :url, :token, :logger
38
+ attr_reader :metadata, :files, :url, :token, :logger, :file_set_builder
36
39
 
37
40
  def check_files_exist
38
41
  logger.info('checking to see if files exist')
@@ -35,13 +35,8 @@ module SdrClient
35
35
  end
36
36
  end
37
37
 
38
- # @param [Array<SdrClient::Deposit::Files::DirectUploadResponse>] uploads the uploaded files to attach.
39
- # @return [Request] a clone of this request with the uploads added
40
- def with_uploads(uploads)
41
- file_sets = uploads.each_with_index.map do |upload, i|
42
- FileSet.new(uploads: [upload], label: "Object #{i + 1}")
43
- end
44
-
38
+ # @return [Request] a clone of this request with the file_sets added
39
+ def with_file_sets(file_sets)
45
40
  Request.new(label: label,
46
41
  apo: apo,
47
42
  collection: collection,
@@ -51,11 +46,6 @@ module SdrClient
51
46
  file_sets: file_sets)
52
47
  end
53
48
 
54
- # In this case there is a 1-1 mapping between Files and FileSets,
55
- # but this doesn't always have to be the case. We could change this in the
56
- # future so that we have one FileSet that has an Image and its OCR file.
57
- def add_uploads_each_as_resource(uploads); end
58
-
59
49
  private
60
50
 
61
51
  attr_reader :label, :file_sets, :source_id, :catkey, :apo, :collection, :type
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SdrClient
4
- VERSION = '0.3.1'
4
+ VERSION = '0.4.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.3.1
4
+ version: 0.4.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-01-23 00:00:00.000000000 Z
11
+ date: 2020-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-monads
@@ -162,6 +162,7 @@ files:
162
162
  - lib/sdr_client/cli.rb
163
163
  - lib/sdr_client/credentials.rb
164
164
  - lib/sdr_client/deposit.rb
165
+ - lib/sdr_client/deposit/default_file_set_builder.rb
165
166
  - lib/sdr_client/deposit/file.rb
166
167
  - lib/sdr_client/deposit/file_set.rb
167
168
  - lib/sdr_client/deposit/files/direct_upload_request.rb