sdr-client 0.36.0 → 0.40.1

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: 7652ddb5f3116fb2ecefabb265718c0bd2e69d536955a22ebb7139cc287a38a1
4
- data.tar.gz: cbb4118974499de9f6c7ad10df1433c4aee712b309ee1c8064cd14602cf08808
3
+ metadata.gz: 70177617818debc05fccd927736a3191a8071db8730835773699b6d8c0c61967
4
+ data.tar.gz: 4b6c4969ac82a9ba23ae8b694126db89bf9ad9fa8b2e3fd3f3848b03c6c5b5d7
5
5
  SHA512:
6
- metadata.gz: d47cc4fbbf26c51df56ba79c4cf97ea3c1add9b8aa2c8f5e78a8bf51f639a15a7bbcbc912f058a2b43d29ced7981623c4f26aafc9b66b5837ae3c17796325f99
7
- data.tar.gz: 107a93bbaf7fde4915bcfb2939853946aff4c0d5fbc3bfede4aeea1971cab270969a3b6406df66b9a44dced0cee70e6627e619aefff3d0803242b7c033ea13f0
6
+ metadata.gz: 0c707edfee7b9c6116853675ebb8ff760888d67488456c7ab7e39d276c03c981a0c7f8dbfeab612130e342aae49f5d3b0b456f877ad4b737af7da1402f274878
7
+ data.tar.gz: 424fede8c7ec5ce782af2e9603c9c79cb53148de9eee6c626b7f361a09583ba07344d25d81add9d568a165d6eb985a64610a32f4c4f48677f3c4004d120a8a67
data/README.md CHANGED
@@ -45,3 +45,9 @@ sdr --service-url https://sdr-api-server:3000 deposit --label 'hey there' \
45
45
  --collection 'druid:gh456kw9876' \
46
46
  --source-id 'googlebooks:stanford_12345' image42.jp2 ocr.html
47
47
  ```
48
+
49
+ View the object:
50
+ ```
51
+ sdr --service-url https://sdr-api-server:3000 get druid:bw581ng3176
52
+ {"type":"http://cocina.sul.stanford.edu/models/document.jsonld","externalIdentifier":"druid:bw581ng3176","label":"Something something better title","version":1,"access":{"access":"stanford","copyright":"This work is copyrighted by the creator.","download":"stanford","useAndReproductionStatement":"This document is available only to the Stanford faculty, staff and student community."},"administrative":{"hasAdminPolicy":"druid:zx485kb6348"},"description":{"title":[{"value":"Something something better title"}],"contributor":[{"name":[{"value":"Hodge, Amy"}],"type":"person","role":[{"value":"Author"},{"value":"author","uri":"http://id.loc.gov/vocabulary/relators/aut","source":{"code":"marcrelator","uri":"http://id.loc.gov/vocabulary/relators/"}},{"value":"Creator"}]}],"form":[{"structuredValue":[{"value":"Text","type":"type"},{"value":"Report","type":"subtype"}],"type":"resource type","source":{"value":"Stanford self-deposit resource types"}},{"value":"reports","type":"genre","uri":"http://vocab.getty.edu/aat/300027267","source":{"code":"aat"}},{"value":"text","type":"resource type","source":{"value":"MODS resource types"}}],"note":[{"value":";alkdfjlsadkjf;l","type":"summary"},{"value":"amyhodge@stanford.edu","type":"contact","displayLabel":"Contact"}],"subject":[{"value":"lkfj","type":"topic"},{"value":";kfj","type":"topic"},{"value":"fjwelkb","type":"topic"}]},"identification":{"sourceId":"hydrus:20"},"structural":{"contains":[{"type":"http://cocina.sul.stanford.edu/models/fileset.jsonld","externalIdentifier":"bw581ng3176_1","label":"Test file","version":1,"structural":{"contains":[{"type":"http://cocina.sul.stanford.edu/models/file.jsonld","externalIdentifier":"druid:bw581ng3176/test.txt","label":"test.txt","filename":"test.txt","size":11,"version":1,"hasMimeType":"text/plain","hasMessageDigests":[{"type":"sha1","digest":"5d39343e4bb48abd97f759828282f5ebbac56c5e"},{"type":"md5","digest":"63b8812b0c05722a9d6c51cbd2bfb54b"}],"access":{"access":"world","download":"world"},"administrative":{"sdrPreserve":true,"shelve":true}}]}}]}}
53
+ ```
data/exe/sdr CHANGED
@@ -19,6 +19,9 @@ end
19
19
  global.order!
20
20
  command = ARGV.shift
21
21
 
22
+ retrieve_options = OptionParser.new do |opts|
23
+ end
24
+
22
25
  deposit_options = OptionParser.new do |opts|
23
26
  opts.banner = "Usage: sdr #{command} [options]"
24
27
  opts.on('--label LABEL', 'The object label') do |label|
@@ -94,6 +97,7 @@ end
94
97
  SdrClient::CLI.help unless command
95
98
 
96
99
  subcommands = {
100
+ 'get' => retrieve_options,
97
101
  'deposit' => deposit_options,
98
102
  'register' => deposit_options,
99
103
  'login' => OptionParser.new
@@ -106,11 +110,10 @@ end
106
110
 
107
111
  subcommands[command].order!
108
112
 
109
- options[:files] = ARGV unless ARGV.empty?
110
113
  options[:url] ||= 'https://sdr-api-prod.stanford.edu'
111
114
 
112
115
  begin
113
- SdrClient::CLI.start(command, options)
116
+ SdrClient::CLI.start(command, options, ARGV)
114
117
  rescue StandardError => e
115
118
  warn "There was a problem making your request:\n\n"
116
119
  warn e.message
@@ -11,6 +11,7 @@ require 'cocina/models'
11
11
  require 'sdr_client/version'
12
12
  require 'sdr_client/deposit'
13
13
  require 'sdr_client/credentials'
14
+ require 'sdr_client/find'
14
15
  require 'sdr_client/login'
15
16
  require 'sdr_client/login_prompt'
16
17
  require 'sdr_client/cli'
@@ -23,6 +23,9 @@ module SdrClient
23
23
 
24
24
 
25
25
  COMMANDS:
26
+ get
27
+ Retrieve an object from the SDR
28
+
26
29
  deposit
27
30
  Accession an object into the SDR
28
31
 
@@ -34,12 +37,12 @@ module SdrClient
34
37
 
35
38
  HELP
36
39
 
37
- def self.start(command, options)
40
+ def self.start(command, options, arguments = [])
38
41
  case command
42
+ when 'get'
43
+ puts SdrClient::Find.run(arguments.first, **options)
39
44
  when 'deposit', 'register'
40
- display_errors(validate_deposit_options(options))
41
- job_id = SdrClient::Deposit.run(accession: command == 'deposit', **options)
42
- poll_for_job_complete(job_id: job_id, url: options[:url]) # TODO: add an option that skips this
45
+ deposit(command, options, arguments)
43
46
  when 'login'
44
47
  status = SdrClient::Login.run(options)
45
48
  puts status.failure if status.failure?
@@ -51,6 +54,13 @@ module SdrClient
51
54
  exit(1)
52
55
  end
53
56
 
57
+ def self.deposit(command, options, arguments)
58
+ options[:files] = arguments if arguments.present?
59
+ display_errors(validate_deposit_options(options))
60
+ job_id = SdrClient::Deposit.run(accession: command == 'deposit', **options)
61
+ poll_for_job_complete(job_id: job_id, url: options[:url]) # TODO: add an option that skips this
62
+ end
63
+
54
64
  def self.display_errors(errors)
55
65
  return if errors.empty?
56
66
 
@@ -32,7 +32,7 @@ module SdrClient
32
32
  end
33
33
  end
34
34
 
35
- delegate :put, :post, to: :connection
35
+ delegate :put, :post, :get, to: :connection
36
36
 
37
37
  private
38
38
 
@@ -68,6 +68,7 @@ module SdrClient
68
68
  end
69
69
  end
70
70
  require 'json'
71
+ require 'sdr_client/deposit/create_resource'
71
72
  require 'sdr_client/deposit/single_file_grouping_strategy'
72
73
  require 'sdr_client/deposit/matching_file_grouping_strategy'
73
74
  require 'sdr_client/deposit/files/direct_upload_request'
@@ -79,7 +80,8 @@ require 'sdr_client/deposit/request'
79
80
  require 'sdr_client/deposit/metadata_builder'
80
81
  require 'sdr_client/deposit/model_process'
81
82
  require 'sdr_client/deposit/process'
83
+ require 'sdr_client/deposit/unexpected_response'
84
+ require 'sdr_client/deposit/update_resource'
82
85
  require 'sdr_client/deposit/update_dro_with_file_identifiers'
83
86
  require 'sdr_client/deposit/upload_files'
84
87
  require 'sdr_client/deposit/upload_files_metadata_builder'
85
- require 'sdr_client/deposit/upload_resource'
@@ -2,8 +2,8 @@
2
2
 
3
3
  module SdrClient
4
4
  module Deposit
5
- # Uploads a resource (metadata) to the server
6
- class UploadResource
5
+ # Creates a resource (metadata) in SDR
6
+ class CreateResource
7
7
  DRO_PATH = '/v1/resources'
8
8
 
9
9
  def self.run(accession:, metadata:, logger:, connection:)
@@ -11,7 +11,7 @@ module SdrClient
11
11
  end
12
12
 
13
13
  # @param [Boolean] accession should the accessionWF be started
14
- # @param [String] metadata
14
+ # @param [Cocina::Models::RequestDRO, Cocina::Models::RequestCollection] metadata
15
15
  # @param [Hash<Symbol,String>] the result of the metadata call
16
16
  def initialize(accession:, metadata:, logger:, connection:)
17
17
  @accession = accession
@@ -24,7 +24,7 @@ module SdrClient
24
24
  # @return [String] job id for the background job result
25
25
  def run
26
26
  response = metadata_request
27
- unexpected_response(response) unless response.status == 201
27
+ UnexpectedResponse.call(response) unless response.status == 201
28
28
 
29
29
  logger.info("Response from server: #{response.body}")
30
30
 
@@ -36,16 +36,10 @@ module SdrClient
36
36
  attr_reader :metadata, :logger, :connection
37
37
 
38
38
  def metadata_request
39
- logger.debug("Starting upload metadata: #{metadata}")
39
+ json = metadata.to_json
40
+ logger.debug("Starting upload metadata: #{json}")
40
41
 
41
- connection.post(path, metadata, 'Content-Type' => 'application/json')
42
- end
43
-
44
- def unexpected_response(response)
45
- raise "There was an error with your request: #{response.body}" if response.status == 400
46
- raise 'There was an error with your credentials. Perhaps they have expired?' if response.status == 401
47
-
48
- raise "unexpected response: #{response.status} #{response.body}"
42
+ connection.post(path, json, 'Content-Type' => 'application/json')
49
43
  end
50
44
 
51
45
  def accession?
@@ -5,7 +5,7 @@ module SdrClient
5
5
  module Files
6
6
  DirectUploadResponse = Struct.new(:id, :key, :checksum, :byte_size, :content_type,
7
7
  :filename, :metadata, :created_at, :direct_upload,
8
- :signed_id, keyword_init: true)
8
+ :signed_id, :service_name, keyword_init: true)
9
9
  end
10
10
  end
11
11
  end
@@ -29,8 +29,8 @@ module SdrClient
29
29
  logger: logger,
30
30
  connection: connection)
31
31
  new_request_dro = UpdateDroWithFileIdentifiers.update(request_dro: request_dro, upload_responses: upload_responses)
32
- UploadResource.run(accession: @accession,
33
- metadata: new_request_dro.to_json,
32
+ CreateResource.run(accession: @accession,
33
+ metadata: new_request_dro,
34
34
  logger: logger,
35
35
  connection: connection)
36
36
  end
@@ -39,8 +39,8 @@ module SdrClient
39
39
  logger: logger)
40
40
  request = metadata_builder.with_uploads(upload_responses)
41
41
  model = Cocina::Models.build_request(request.as_json.with_indifferent_access)
42
- UploadResource.run(accession: @accession,
43
- metadata: JSON.generate(model.to_h),
42
+ CreateResource.run(accession: @accession,
43
+ metadata: model,
44
44
  logger: logger,
45
45
  connection: connection)
46
46
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SdrClient
4
+ module Deposit
5
+ # Handles unexpected responses when manipulating resources
6
+ class UnexpectedResponse
7
+ # @param [Faraday::Response] response
8
+ 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}"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SdrClient
4
+ module Deposit
5
+ # Updates a resource (metadata) in SDR
6
+ class UpdateResource
7
+ DRO_PATH = '/v1/resources/%<id>s'
8
+
9
+ def self.run(metadata:, logger:, connection:)
10
+ new(metadata: metadata, logger: logger, connection: connection).run
11
+ end
12
+
13
+ # @param [Cocina::Models::DRO] metadata
14
+ # @param [Hash<Symbol,String>] the result of the metadata call
15
+ def initialize(metadata:, logger:, connection:)
16
+ @metadata = metadata
17
+ @logger = logger
18
+ @connection = connection
19
+ end
20
+
21
+ # @param [Hash<Symbol,String>] the result of the metadata call
22
+ # @return [String] job id for the background job result
23
+ def run
24
+ response = metadata_request
25
+ UnexpectedResponse.call(response) unless response.status == 202
26
+
27
+ logger.info("Response from server: #{response.body}")
28
+
29
+ JSON.parse(response.body)['jobId']
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :metadata, :logger, :connection
35
+
36
+ def metadata_request
37
+ json = metadata.to_json
38
+ logger.debug("Starting upload metadata: #{json}")
39
+
40
+ connection.put(path(metadata), json, 'Content-Type' => 'application/json')
41
+ end
42
+
43
+ def path(metadata)
44
+ format(DRO_PATH, id: metadata.externalIdentifier)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+
5
+ module SdrClient
6
+ # The namespace for the "get" command
7
+ module Find
8
+ DRO_PATH = '/v1/resources/%<id>s'
9
+ # @return [String] job id for the background job result
10
+ def self.run(druid, url:, logger: Logger.new(STDOUT))
11
+ connection = Connection.new(url: url)
12
+ path = format(DRO_PATH, id: druid)
13
+ logger.info("Retrieving metadata from: #{path}")
14
+ response = connection.get(path)
15
+ response.body
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SdrClient
4
- VERSION = '0.36.0'
4
+ VERSION = '0.40.1'
5
5
  end
@@ -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.42.1'
31
+ spec.add_dependency 'cocina-models', '~> 0.44.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.36.0
4
+ version: 0.40.1
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-11-04 00:00:00.000000000 Z
11
+ date: 2021-01-08 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.42.1
33
+ version: 0.44.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.42.1
40
+ version: 0.44.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: dry-monads
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -193,6 +193,7 @@ files:
193
193
  - lib/sdr_client/connection.rb
194
194
  - lib/sdr_client/credentials.rb
195
195
  - lib/sdr_client/deposit.rb
196
+ - lib/sdr_client/deposit/create_resource.rb
196
197
  - lib/sdr_client/deposit/file.rb
197
198
  - lib/sdr_client/deposit/file_metadata_builder.rb
198
199
  - lib/sdr_client/deposit/file_metadata_builder_operations/md5.rb
@@ -207,10 +208,12 @@ files:
207
208
  - lib/sdr_client/deposit/process.rb
208
209
  - lib/sdr_client/deposit/request.rb
209
210
  - lib/sdr_client/deposit/single_file_grouping_strategy.rb
211
+ - lib/sdr_client/deposit/unexpected_response.rb
210
212
  - lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
213
+ - lib/sdr_client/deposit/update_resource.rb
211
214
  - lib/sdr_client/deposit/upload_files.rb
212
215
  - lib/sdr_client/deposit/upload_files_metadata_builder.rb
213
- - lib/sdr_client/deposit/upload_resource.rb
216
+ - lib/sdr_client/find.rb
214
217
  - lib/sdr_client/login.rb
215
218
  - lib/sdr_client/login_prompt.rb
216
219
  - lib/sdr_client/version.rb
@@ -236,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
236
239
  - !ruby/object:Gem::Version
237
240
  version: '0'
238
241
  requirements: []
239
- rubygems_version: 3.1.4
242
+ rubygems_version: 3.1.2
240
243
  signing_key:
241
244
  specification_version: 4
242
245
  summary: The CLI for https://github.com/sul-dlss/sdr-api