sdr-client 0.21.0 → 0.22.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: 8dab3e033cd3f0fd0eae7045c3565f7c24300d99ebcd7141777eb0d005847497
4
- data.tar.gz: 25a76561f9aafdcc4a575030ca9bb750e8cdf036b60c14cc92f413bbde4668d2
3
+ metadata.gz: 52457756d6413fcbb3d78c6778e705dd000f73d4bfd9be51b4455c91f861f2cf
4
+ data.tar.gz: 2e3fbb925f332ddbf6f70a011f708ed659bb768bf3cea618e3b40cea70b7e1a8
5
5
  SHA512:
6
- metadata.gz: fa6080f541ce480fc8ca31f5f063404090235e8edce6849aa10c4f50f1a00ef83a166ea1c97ad579e094fbf9b5d8f24df73debc68ce567e1a7886dc7a491b643
7
- data.tar.gz: a915029ed2f58221fe4c2418e8fef194f11eb6bde24af289dc9f52da438841a4bab90fec7a95a94eeaa22334e2e72897a6047f01c5909ed995d371473b1c0295
6
+ metadata.gz: cdaa5ce7b1c83361d33911f02191d4a34c97c24113ffc01e4594a2300b966ef7b0ff399ea56ee033650be0eb808dd3a363dbf04357c2e124ebfe378d78a69459
7
+ data.tar.gz: 238c7ff0047034134d1a3c4421bed157e09b97692ec6d57226edfc2e4e5ef0a7be3a88a39b9c10f816ae6e53dc7f44d10dea7d38a1f7424bb9a6a5c9b3ea7fd2
data/README.md CHANGED
@@ -21,8 +21,15 @@ Log in:
21
21
  sdr --service-url http://sdr-api-server:3000 login
22
22
  ```
23
23
 
24
+ Register a new object:
25
+ ```
26
+ sdr --service-url https://sdr-api-server:3000 register --label 'hey there' \
27
+ --admin-policy 'druid:bk123gh4567' \
28
+ --collection 'druid:gh456kw9876' \
29
+ --source-id 'googlebooks:stanford_12345' file1.png file2.png
30
+ ```
24
31
 
25
- Deposit a new object:
32
+ Deposit (register + accession) a new object:
26
33
  ```
27
34
  sdr --service-url https://sdr-api-server:3000 deposit --label 'hey there' \
28
35
  --admin-policy 'druid:bk123gh4567' \
data/exe/sdr CHANGED
@@ -27,7 +27,10 @@ global = OptionParser.new do |opts|
27
27
 
28
28
  COMMANDS
29
29
  deposit
30
- deposit files to the SDR
30
+ accession object into the SDR
31
+
32
+ register
33
+ create a draft object in SDR
31
34
 
32
35
  login
33
36
  Will prompt for email & password and exchange it for an login token, which it saves in ~/.sdr/token
@@ -40,77 +43,80 @@ end
40
43
  global.order!
41
44
  command = ARGV.shift
42
45
 
43
- subcommands = {
44
- 'deposit' => OptionParser.new do |opts|
45
- opts.on('--label LABEL', 'The object label') do |label|
46
- options[:label] = label
47
- end
46
+ deposit_options = OptionParser.new do |opts|
47
+ opts.on('--label LABEL', 'The object label') do |label|
48
+ options[:label] = label
49
+ end
48
50
 
49
- opts.on('--admin-policy ADMIN_POLICY', 'The druid identifier of the admin policy object') do |apo|
50
- options[:apo] = apo
51
- end
51
+ opts.on('--admin-policy ADMIN_POLICY', 'The druid identifier of the admin policy object') do |apo|
52
+ options[:apo] = apo
53
+ end
52
54
 
53
- opts.on('--type TYPE', 'The object type to create. ' \
54
- 'One of: "image", "book", "document", "map", "manuscript", "media", ' \
55
- '"three_dimensional", "collection", or "admin_policy"') do |type|
56
- if %w[image book document map manuscript media three_dimensional collection admin_policy].include?(type)
57
- options[:type] = "http://cocina.sul.stanford.edu/models/#{type}.jsonld"
58
- end
55
+ opts.on('--type TYPE', 'The object type to create. ' \
56
+ 'One of: "image", "book", "document", "map", "manuscript", "media", ' \
57
+ '"three_dimensional", "collection", or "admin_policy"') do |type|
58
+ if %w[image book document map manuscript media three_dimensional collection admin_policy].include?(type)
59
+ options[:type] = "http://cocina.sul.stanford.edu/models/#{type}.jsonld"
59
60
  end
61
+ end
60
62
 
61
- opts.on('--collection COLLECTION', 'The druid identifier of the collection object') do |collection|
62
- options[:collection] = collection
63
- end
63
+ opts.on('--collection COLLECTION', 'The druid identifier of the collection object') do |collection|
64
+ options[:collection] = collection
65
+ end
64
66
 
65
- opts.on('--catkey CATKEY', 'The catkey for this item') do |catkey|
66
- options[:catkey] = catkey
67
- end
67
+ opts.on('--catkey CATKEY', 'The catkey for this item') do |catkey|
68
+ options[:catkey] = catkey
69
+ end
68
70
 
69
- opts.on('--source-id SOURCE_ID', 'The source id for this object') do |source_id|
70
- options[:source_id] = source_id
71
- end
71
+ opts.on('--source-id SOURCE_ID', 'The source id for this object') do |source_id|
72
+ options[:source_id] = source_id
73
+ end
72
74
 
73
- opts.on('--copyright COPYRIGHT', 'The copyright statement') do |copyright|
74
- options[:copyright] = copyright
75
- end
75
+ opts.on('--copyright COPYRIGHT', 'The copyright statement') do |copyright|
76
+ options[:copyright] = copyright
77
+ end
76
78
 
77
- opts.on('--use-statement STATEMENT', 'The use and reproduction statement') do |use_statement|
78
- options[:use_statement] = use_statement
79
- end
79
+ opts.on('--use-statement STATEMENT', 'The use and reproduction statement') do |use_statement|
80
+ options[:use_statement] = use_statement
81
+ end
80
82
 
81
- opts.on('--viewing-direction DIRECTION', 'The viewing direction (if a book). ' \
82
- 'Either "left-to-right" or "right-to-left"') do |viewing_direction|
83
- options[:viewing_direction] = viewing_direction if %w[left-to-right right-to-left].include?(viewing_direction)
84
- end
83
+ opts.on('--viewing-direction DIRECTION', 'The viewing direction (if a book). ' \
84
+ 'Either "left-to-right" or "right-to-left"') do |viewing_direction|
85
+ options[:viewing_direction] = viewing_direction if %w[left-to-right right-to-left].include?(viewing_direction)
86
+ end
85
87
 
86
- opts.on('--access LEVEL', 'The access level for this object. ' \
87
- 'Either "world", "stanford", "location-based", "citation-only" or "dark"') do |level|
88
- options[:access] = level if %w[world stanford location-based citation-only dark].include?(level)
89
- end
88
+ opts.on('--access LEVEL', 'The access level for this object. ' \
89
+ 'Either "world", "stanford", "location-based", "citation-only" or "dark"') do |level|
90
+ options[:access] = level if %w[world stanford location-based citation-only dark].include?(level)
91
+ end
90
92
 
91
- opts.on('--files-metadata FILES_METADATA', 'A JSON object representing per-file metadata') do |files_metadata|
92
- options[:files_metadata] = JSON.parse(files_metadata)
93
- end
93
+ opts.on('--files-metadata FILES_METADATA', 'A JSON object representing per-file metadata') do |files_metadata|
94
+ options[:files_metadata] = JSON.parse(files_metadata)
95
+ end
94
96
 
95
- opts.on('--strategy STRATEGY',
96
- 'The strategy to use for distributing files into filesets. Either "default" or "filename"') do |strategy|
97
- strategy_class = case strategy
98
- when 'filename'
99
- SdrClient::Deposit::MatchingFileGroupingStrategy
100
- when 'default'
101
- SdrClient::Deposit::SingleFileGroupingStrategy
102
- else
103
- warn "Unknown strategy #{strategy}"
104
- exit(1)
105
- end
106
- options[:grouping_strategy] = strategy_class
107
- end
97
+ opts.on('--strategy STRATEGY',
98
+ 'The strategy to use for distributing files into filesets. Either "default" or "filename"') do |strategy|
99
+ strategy_class = case strategy
100
+ when 'filename'
101
+ SdrClient::Deposit::MatchingFileGroupingStrategy
102
+ when 'default'
103
+ SdrClient::Deposit::SingleFileGroupingStrategy
104
+ else
105
+ warn "Unknown strategy #{strategy}"
106
+ exit(1)
107
+ end
108
+ options[:grouping_strategy] = strategy_class
109
+ end
108
110
 
109
- opts.on('-h', '--help', 'Display this screen') do
110
- puts opts
111
- exit
112
- end
113
- end,
111
+ opts.on('-h', '--help', 'Display this screen') do
112
+ puts opts
113
+ exit
114
+ end
115
+ end
116
+
117
+ subcommands = {
118
+ 'deposit' => deposit_options,
119
+ 'register' => deposit_options,
114
120
  'login' => OptionParser.new
115
121
  }
116
122
 
@@ -6,7 +6,9 @@ module SdrClient
6
6
  def self.start(command, options)
7
7
  case command
8
8
  when 'deposit'
9
- SdrClient::Deposit.run(options)
9
+ SdrClient::Deposit.run(accession: true, **options)
10
+ when 'register'
11
+ SdrClient::Deposit.run(accession: false, **options)
10
12
  when 'login'
11
13
  status = SdrClient::Login.run(options)
12
14
  puts status.value if status.failure?
@@ -23,6 +23,7 @@ module SdrClient
23
23
  url:,
24
24
  files: [],
25
25
  files_metadata: {},
26
+ accession: false,
26
27
  grouping_strategy: SingleFileGroupingStrategy,
27
28
  logger: Logger.new(STDOUT))
28
29
  augmented_metadata = FileMetadataBuilder.build(files: files, files_metadata: files_metadata)
@@ -41,7 +42,9 @@ module SdrClient
41
42
  files_metadata: augmented_metadata)
42
43
  connection = Connection.new(url: url)
43
44
  Process.new(metadata: metadata, connection: connection, files: files,
44
- grouping_strategy: grouping_strategy, logger: logger).run
45
+ grouping_strategy: grouping_strategy,
46
+ accession: accession,
47
+ logger: logger).run
45
48
  end
46
49
  # rubocop:enable Metrics/MethodLength
47
50
  # rubocop:enable Metrics/ParameterLists
@@ -11,15 +11,20 @@ module SdrClient
11
11
  # @param [Class] grouping_strategy class whose run method groups an array of uploads
12
12
  # @param [String] connection the server connection to use
13
13
  # @param [Array<String>] files a list of file names to upload
14
+ # @param [Boolean] accession should the accessionWF be started
14
15
  # @param [Logger] logger the logger to use
16
+ #
17
+ # rubocop:disable Metrics/ParameterLists
15
18
  def initialize(metadata:, grouping_strategy: SingleFileGroupingStrategy,
16
- connection:, files: [], logger: Logger.new(STDOUT))
19
+ connection:, files: [], accession:, logger: Logger.new(STDOUT))
17
20
  @files = files
18
21
  @connection = connection
19
22
  @metadata = metadata
20
23
  @logger = logger
21
24
  @grouping_strategy = grouping_strategy
25
+ @accession = accession
22
26
  end
27
+ # rubocop:enable Metrics/ParameterLists
23
28
 
24
29
  # rubocop:disable Metrics/AbcSize
25
30
  def run
@@ -48,11 +53,15 @@ module SdrClient
48
53
  end
49
54
  end
50
55
 
56
+ def accession?
57
+ @accession
58
+ end
59
+
60
+ # @param [Hash<Symbol,String>] the result of the metadata call
61
+ # @param [Boolean] accession should the accessionWF be started
51
62
  # @return [Hash<Symbol,String>] the result of the metadata call
52
63
  def upload_metadata(metadata)
53
- logger.info("Starting upload metadata: #{metadata}")
54
- request_json = JSON.generate(metadata)
55
- response = connection.post(DRO_PATH, request_json, 'Content-Type' => 'application/json')
64
+ response = metadata_request(metadata)
56
65
  unexpected_response(response) unless response.status == 201
57
66
 
58
67
  logger.info("Response from server: #{response.body}")
@@ -60,6 +69,18 @@ module SdrClient
60
69
  { druid: JSON.parse(response.body)['druid'], background_job: response.headers['Location'] }
61
70
  end
62
71
 
72
+ def metadata_request(metadata)
73
+ logger.debug("Starting upload metadata: #{metadata}")
74
+
75
+ connection.post(path, JSON.generate(metadata), 'Content-Type' => 'application/json')
76
+ end
77
+
78
+ def path
79
+ path = DRO_PATH
80
+ path += '?accession=true' if accession?
81
+ path
82
+ end
83
+
63
84
  def unexpected_response(response)
64
85
  raise "There was an error with your request: #{response.body}" if response.status == 400
65
86
  raise 'There was an error with your credentials. Perhaps they have expired?' if response.status == 401
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SdrClient
4
- VERSION = '0.21.0'
4
+ VERSION = '0.22.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.21.0
4
+ version: 0.22.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-03-31 00:00:00.000000000 Z
11
+ date: 2020-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -233,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
233
  - !ruby/object:Gem::Version
234
234
  version: '0'
235
235
  requirements: []
236
- rubygems_version: 3.0.3
236
+ rubygems_version: 3.1.2
237
237
  signing_key:
238
238
  specification_version: 4
239
239
  summary: The CLI for https://github.com/sul-dlss/sdr-api