sdr-client 0.1.0 → 0.4.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 +4 -4
- data/.rubocop_todo.yml +11 -12
- data/.travis.yml +3 -0
- data/README.md +14 -1
- data/exe/sdr +40 -2
- data/lib/sdr_client.rb +6 -1
- data/lib/sdr_client/cli.rb +5 -0
- data/lib/sdr_client/credentials.rb +31 -0
- data/lib/sdr_client/deposit.rb +17 -2
- data/lib/sdr_client/deposit/default_file_set_builder.rb +18 -0
- data/lib/sdr_client/deposit/file.rb +33 -0
- data/lib/sdr_client/deposit/file_set.rb +33 -0
- data/lib/sdr_client/deposit/files/direct_upload_request.rb +2 -2
- data/lib/sdr_client/deposit/process.rb +38 -19
- data/lib/sdr_client/deposit/request.rb +49 -28
- data/lib/sdr_client/login.rb +26 -0
- data/lib/sdr_client/login_prompt.rb +19 -0
- data/lib/sdr_client/version.rb +1 -1
- data/sdr-client.gemspec +2 -1
- metadata +27 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1d76c1422877b6b5f25f0a1cb46641e32771496771576f8f7c8fd2697c14b0e
|
4
|
+
data.tar.gz: eb116e73a114a3966254a0996c5d843fc960e1454146214ca68fae11eff89bda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acf219c807f4f22f87437f779cf4d3ab2bb8091bc810a616146a302a9e2bab4b5be99685c91ea072056344a59b5b0f37e9ed5008105d836078d1b70032720c75
|
7
|
+
data.tar.gz: b6ec07336e2014a6fbf02470c08649c426384a51c40ee32a164f29c96ab75cd2057615ee5ee8081f7a70f406f794fed6c100fb93aba7848d629e8933fa91f589
|
data/.rubocop_todo.yml
CHANGED
@@ -1,22 +1,21 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2020-01-
|
3
|
+
# on 2020-01-10 17:16:01 -0600 using RuboCop version 0.79.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
9
|
# Offense count: 1
|
10
|
-
|
11
|
-
|
12
|
-
Layout/ExtraSpacing:
|
13
|
-
Exclude:
|
14
|
-
- 'sdr-client.gemspec'
|
10
|
+
Metrics/AbcSize:
|
11
|
+
Max: 16
|
15
12
|
|
16
13
|
# Offense count: 1
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
15
|
+
Metrics/MethodLength:
|
16
|
+
Max: 13
|
17
|
+
|
18
|
+
# Offense count: 2
|
19
|
+
# Configuration parameters: CountKeywordArgs.
|
20
|
+
Metrics/ParameterLists:
|
21
|
+
Max: 8
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -8,9 +8,22 @@
|
|
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
|
|
17
|
+
Log in:
|
18
|
+
```
|
19
|
+
sdr --service-url http://sdr-api-server:3000 login
|
20
|
+
```
|
21
|
+
|
22
|
+
|
13
23
|
Deposit a new object:
|
14
24
|
```
|
15
|
-
sdr --service-url
|
25
|
+
sdr --service-url https://sdr-api-server:3000 deposit --label 'hey there' \
|
26
|
+
--admin-policy 'druid:bk123gh4567' \
|
27
|
+
--collection 'druid:gh456kw9876' \
|
28
|
+
--source-id 'googlebooks:stanford_12345' file1.png file2.png
|
16
29
|
```
|
data/exe/sdr
CHANGED
@@ -10,7 +10,28 @@ global = OptionParser.new do |opts|
|
|
10
10
|
options[:url] = url
|
11
11
|
end
|
12
12
|
opts.on('-h', '--help', 'Display this screen') do
|
13
|
-
puts
|
13
|
+
puts <<~HELP
|
14
|
+
DESCRIPTION:
|
15
|
+
The SDR Command Line Interface is a tool to interact with the Stanford Digital Repository.
|
16
|
+
|
17
|
+
SYNOPSIS:
|
18
|
+
sdr [options] <command>
|
19
|
+
|
20
|
+
OPTIONS:
|
21
|
+
--service-url (string)
|
22
|
+
Override the command's default URL with the given URL.
|
23
|
+
|
24
|
+
-h, --help
|
25
|
+
Displays this screen
|
26
|
+
|
27
|
+
COMMANDS
|
28
|
+
deposit
|
29
|
+
deposit files to the SDR
|
30
|
+
|
31
|
+
login
|
32
|
+
Will prompt for email & password and exchange it for an login token, which it saves in ~/.sdr/token
|
33
|
+
|
34
|
+
HELP
|
14
35
|
exit
|
15
36
|
end
|
16
37
|
end
|
@@ -23,11 +44,28 @@ subcommands = {
|
|
23
44
|
opts.on('--label LABEL', 'The object label') do |label|
|
24
45
|
options[:label] = label
|
25
46
|
end
|
47
|
+
|
48
|
+
opts.on('--admin-policy ADMIN_POLICY', 'The druid identifier of the admin policy object') do |apo|
|
49
|
+
options[:apo] = apo
|
50
|
+
end
|
51
|
+
opts.on('--collection COLLECTION', 'The druid identifier of the collection object') do |collection|
|
52
|
+
options[:collection] = collection
|
53
|
+
end
|
54
|
+
|
55
|
+
opts.on('--catkey CATKEY', 'The catkey for this item') do |catkey|
|
56
|
+
options[:catkey] = catkey
|
57
|
+
end
|
58
|
+
|
59
|
+
opts.on('--source-id SOURCE_ID', 'The source id for this object') do |source_id|
|
60
|
+
options[:source_id] = source_id
|
61
|
+
end
|
62
|
+
|
26
63
|
opts.on('-h', '--help', 'Display this screen') do
|
27
64
|
puts opts
|
28
65
|
exit
|
29
66
|
end
|
30
|
-
end
|
67
|
+
end,
|
68
|
+
'login' => OptionParser.new
|
31
69
|
}
|
32
70
|
|
33
71
|
unless subcommands.key?(command)
|
data/lib/sdr_client.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'dry/monads'
|
4
|
+
require 'faraday'
|
5
|
+
|
3
6
|
require 'sdr_client/version'
|
4
7
|
require 'sdr_client/deposit'
|
8
|
+
require 'sdr_client/credentials'
|
9
|
+
require 'sdr_client/login'
|
10
|
+
require 'sdr_client/login_prompt'
|
5
11
|
require 'sdr_client/cli'
|
6
|
-
require 'faraday'
|
7
12
|
|
8
13
|
module SdrClient
|
9
14
|
class Error < StandardError; end
|
data/lib/sdr_client/cli.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SdrClient
|
4
|
+
# The stored credentials
|
5
|
+
class Credentials
|
6
|
+
# @param [String] a json string that contains a field 'token'
|
7
|
+
def self.write(body)
|
8
|
+
json = JSON.parse(body)
|
9
|
+
Dir.mkdir(credentials_path, 0o700) unless Dir.exist?(credentials_path)
|
10
|
+
File.open(credentials_file, 'w', 0o600) do |file|
|
11
|
+
file.write(json.fetch('token'))
|
12
|
+
end
|
13
|
+
puts 'Signed in.'
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.read
|
17
|
+
return IO.readlines(credentials_file, chomp: true).first if ::File.exist?(credentials_file)
|
18
|
+
|
19
|
+
puts 'Log in first'
|
20
|
+
exit(1)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.credentials_path
|
24
|
+
@credentials_path ||= File.join(Dir.home, '.sdr')
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.credentials_file
|
28
|
+
File.join(credentials_path, 'credentials')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/sdr_client/deposit.rb
CHANGED
@@ -3,15 +3,30 @@
|
|
3
3
|
module SdrClient
|
4
4
|
# The namespace for the "deposit" command
|
5
5
|
module Deposit
|
6
|
-
def self.run(label
|
6
|
+
def self.run(label: nil,
|
7
7
|
type: 'http://cocina.sul.stanford.edu/models/book.jsonld',
|
8
|
+
apo:,
|
9
|
+
collection:,
|
10
|
+
catkey: nil,
|
11
|
+
source_id:,
|
8
12
|
url:, files: [])
|
9
|
-
|
13
|
+
token = Credentials.read
|
14
|
+
|
15
|
+
metadata = Request.new(label: label,
|
16
|
+
type: type,
|
17
|
+
apo: apo,
|
18
|
+
collection: collection,
|
19
|
+
source_id: source_id,
|
20
|
+
catkey: catkey)
|
21
|
+
Process.new(metadata: metadata, url: url, token: token, files: files).run
|
10
22
|
end
|
11
23
|
end
|
12
24
|
end
|
13
25
|
require 'json'
|
26
|
+
require 'sdr_client/deposit/default_file_set_builder'
|
14
27
|
require 'sdr_client/deposit/files/direct_upload_request'
|
15
28
|
require 'sdr_client/deposit/files/direct_upload_response'
|
29
|
+
require 'sdr_client/deposit/file'
|
30
|
+
require 'sdr_client/deposit/file_set'
|
16
31
|
require 'sdr_client/deposit/request'
|
17
32
|
require 'sdr_client/deposit/process'
|
@@ -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
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SdrClient
|
4
|
+
module Deposit
|
5
|
+
# This represents the File metadata that we send to the server for doing a deposit
|
6
|
+
class File
|
7
|
+
def initialize(external_identifier:, label:, filename:, access: 'dark', preserve: false, shelve: false)
|
8
|
+
@external_identifier = external_identifier
|
9
|
+
@label = label
|
10
|
+
@filename = filename
|
11
|
+
@access = access
|
12
|
+
@preserve = preserve
|
13
|
+
@shelve = shelve
|
14
|
+
end
|
15
|
+
|
16
|
+
def as_json
|
17
|
+
{
|
18
|
+
"type": 'http://cocina.sul.stanford.edu/models/file.jsonld',
|
19
|
+
label: @label,
|
20
|
+
filename: @filename,
|
21
|
+
externalIdentifier: @external_identifier,
|
22
|
+
access: {
|
23
|
+
access: @access
|
24
|
+
},
|
25
|
+
administrative: {
|
26
|
+
sdrPreserve: @preserve,
|
27
|
+
shelve: @shelve
|
28
|
+
}
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SdrClient
|
4
|
+
module Deposit
|
5
|
+
# This represents the FileSet metadata that we send to the server for doing a deposit
|
6
|
+
class FileSet
|
7
|
+
def initialize(uploads: [], files: [], label:)
|
8
|
+
@label = label
|
9
|
+
@files = if !uploads.empty?
|
10
|
+
uploads.map do |upload|
|
11
|
+
File.new(external_identifier: upload.signed_id, label: upload.filename, filename: upload.filename)
|
12
|
+
end
|
13
|
+
else
|
14
|
+
files
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def as_json
|
19
|
+
{
|
20
|
+
"type": 'http://cocina.sul.stanford.edu/models/fileset.jsonld',
|
21
|
+
"label": label,
|
22
|
+
structural: {
|
23
|
+
hasMember: files.map(&:as_json)
|
24
|
+
}
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :files, :label
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -9,9 +9,9 @@ module SdrClient
|
|
9
9
|
def self.from_file(filename)
|
10
10
|
checksum = Digest::MD5.file(filename).base64digest
|
11
11
|
new(checksum: checksum,
|
12
|
-
byte_size: File.size(filename),
|
12
|
+
byte_size: ::File.size(filename),
|
13
13
|
content_type: 'text/html',
|
14
|
-
filename: File.basename(filename))
|
14
|
+
filename: ::File.basename(filename))
|
15
15
|
end
|
16
16
|
|
17
17
|
def as_json
|
@@ -6,14 +6,22 @@ module SdrClient
|
|
6
6
|
module Deposit
|
7
7
|
# The process for doing a deposit
|
8
8
|
class Process
|
9
|
-
BLOB_PATH = '/
|
9
|
+
BLOB_PATH = '/v1/direct_uploads'
|
10
10
|
DRO_PATH = '/v1/resources'
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
# @param [Request] metadata information about the object
|
12
|
+
# @param [#build] file_set_builder a strategy for constructing FileSets
|
13
|
+
# @param [String] url the server to send to
|
14
|
+
# @param [String] token the bearer auth token for the server
|
15
|
+
# @param [Array<String>] files a list of file names to upload
|
16
|
+
# @param [Logger] logger the logger to use
|
17
|
+
def initialize(metadata:, file_set_builder: DefaultFileSetBuilder, url:,
|
18
|
+
token:, files: [], logger: Logger.new(STDOUT))
|
14
19
|
@files = files
|
15
20
|
@url = url
|
21
|
+
@token = token
|
22
|
+
@metadata = metadata
|
16
23
|
@logger = logger
|
24
|
+
@file_set_builder = file_set_builder
|
17
25
|
end
|
18
26
|
|
19
27
|
def run
|
@@ -21,20 +29,18 @@ module SdrClient
|
|
21
29
|
file_metadata = collect_file_metadata
|
22
30
|
upload_responses = upload_file_metadata(file_metadata)
|
23
31
|
upload_files(upload_responses)
|
24
|
-
|
25
|
-
|
26
|
-
uploads: upload_responses.values)
|
27
|
-
upload_metadata(metadata.as_json)
|
32
|
+
request = file_set_builder.run(request: metadata, uploads: upload_responses.values)
|
33
|
+
upload_metadata(request.as_json)
|
28
34
|
end
|
29
35
|
|
30
36
|
private
|
31
37
|
|
32
|
-
attr_reader :
|
38
|
+
attr_reader :metadata, :files, :url, :token, :logger, :file_set_builder
|
33
39
|
|
34
40
|
def check_files_exist
|
35
41
|
logger.info('checking to see if files exist')
|
36
42
|
files.each do |file_name|
|
37
|
-
raise Errno::ENOENT, file_name unless File.exist?(file_name)
|
43
|
+
raise Errno::ENOENT, file_name unless ::File.exist?(file_name)
|
38
44
|
end
|
39
45
|
end
|
40
46
|
|
@@ -51,7 +57,7 @@ module SdrClient
|
|
51
57
|
|
52
58
|
def direct_upload(metadata_json)
|
53
59
|
logger.info("Starting an upload request: #{metadata_json}")
|
54
|
-
response =
|
60
|
+
response = connection.post(BLOB_PATH, metadata_json, 'Content-Type' => 'application/json')
|
55
61
|
raise "unexpected response: #{response.inspect}" unless response.status == 200
|
56
62
|
|
57
63
|
logger.info("Response from server: #{response.body}")
|
@@ -73,11 +79,9 @@ module SdrClient
|
|
73
79
|
|
74
80
|
def upload_file(filename:, url:, content_type:, content_length:)
|
75
81
|
logger.info("Uploading `#{filename}' to #{url}")
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
upload_response = conn.put(url) do |req|
|
80
|
-
req.body = File.open(filename)
|
82
|
+
|
83
|
+
upload_response = connection.put(url) do |req|
|
84
|
+
req.body = ::File.open(filename)
|
81
85
|
req.headers['Content-Type'] = content_type
|
82
86
|
req.headers['Content-Length'] = content_length.to_s
|
83
87
|
end
|
@@ -85,15 +89,30 @@ module SdrClient
|
|
85
89
|
raise "unexpected response: #{upload_response.inspect}" unless upload_response.status == 204
|
86
90
|
end
|
87
91
|
|
92
|
+
# @return [Hash<Symbol,String>] the result of the metadata call
|
88
93
|
def upload_metadata(metadata)
|
89
94
|
logger.info("Starting upload metadata: #{metadata}")
|
90
95
|
request_json = JSON.generate(metadata)
|
91
|
-
response =
|
92
|
-
|
96
|
+
response = connection.post(DRO_PATH, request_json, 'Content-Type' => 'application/json')
|
97
|
+
unexpected_response(response) unless response.status == 201
|
93
98
|
|
94
99
|
logger.info("Response from server: #{response.body}")
|
95
100
|
|
96
|
-
JSON.parse(response.body)
|
101
|
+
{ druid: JSON.parse(response.body)['druid'], background_job: response.headers['Location'] }
|
102
|
+
end
|
103
|
+
|
104
|
+
def unexpected_response(response)
|
105
|
+
raise "unexpected response: #{response.inspect}" unless response.status == 400
|
106
|
+
|
107
|
+
puts "\nThere was an error with your request: #{response.body}"
|
108
|
+
exit(1)
|
109
|
+
end
|
110
|
+
|
111
|
+
def connection
|
112
|
+
@connection ||= Faraday.new(url: url) do |conn|
|
113
|
+
conn.authorization :Bearer, token
|
114
|
+
conn.adapter :net_http
|
115
|
+
end
|
97
116
|
end
|
98
117
|
end
|
99
118
|
end
|
@@ -4,49 +4,70 @@ module SdrClient
|
|
4
4
|
module Deposit
|
5
5
|
# This represents the metadata that we send to the server for doing a deposit
|
6
6
|
class Request
|
7
|
-
CONTEXT = 'http://cocina.sul.stanford.edu/contexts/cocina-base.jsonld'
|
8
|
-
|
9
7
|
# @param [String] label the required object label
|
10
8
|
# @param [String] type (http://cocina.sul.stanford.edu/models/object.jsonld) the required object type.
|
11
|
-
# @param [Array<
|
12
|
-
def initialize(label
|
9
|
+
# @param [Array<FileSet>] file_sets the file sets to attach.
|
10
|
+
def initialize(label: nil,
|
11
|
+
apo:,
|
12
|
+
collection:,
|
13
|
+
source_id:,
|
14
|
+
catkey: nil,
|
13
15
|
type: 'http://cocina.sul.stanford.edu/models/object.jsonld',
|
14
|
-
|
16
|
+
file_sets: [])
|
15
17
|
@label = label
|
16
18
|
@type = type
|
17
|
-
@
|
19
|
+
@source_id = source_id
|
20
|
+
@collection = collection
|
21
|
+
@catkey = catkey
|
22
|
+
@apo = apo
|
23
|
+
@file_sets = file_sets
|
18
24
|
end
|
19
25
|
|
20
26
|
def as_json
|
21
27
|
{
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
access: {},
|
29
|
+
type: type,
|
30
|
+
administrative: administrative,
|
31
|
+
identification: identification,
|
32
|
+
structural: structural
|
33
|
+
}.tap do |json|
|
34
|
+
json[:label] = label if label
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# @return [Request] a clone of this request with the file_sets added
|
39
|
+
def with_file_sets(file_sets)
|
40
|
+
Request.new(label: label,
|
41
|
+
apo: apo,
|
42
|
+
collection: collection,
|
43
|
+
source_id: source_id,
|
44
|
+
catkey: catkey,
|
45
|
+
type: type,
|
46
|
+
file_sets: file_sets)
|
29
47
|
end
|
30
48
|
|
31
49
|
private
|
32
50
|
|
33
|
-
attr_reader :label, :
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
structural: {
|
45
|
-
hasMember: [upload.signed_id]
|
46
|
-
}
|
47
|
-
}
|
51
|
+
attr_reader :label, :file_sets, :source_id, :catkey, :apo, :collection, :type
|
52
|
+
|
53
|
+
def administrative
|
54
|
+
{
|
55
|
+
hasAdminPolicy: apo
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
def identification
|
60
|
+
{ sourceId: source_id }.tap do |json|
|
61
|
+
json[:catkey] = catkey if catkey
|
48
62
|
end
|
49
63
|
end
|
64
|
+
|
65
|
+
def structural
|
66
|
+
{
|
67
|
+
isMemberOf: collection,
|
68
|
+
hasMember: file_sets.map(&:as_json)
|
69
|
+
}
|
70
|
+
end
|
50
71
|
end
|
51
72
|
end
|
52
73
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SdrClient
|
4
|
+
# The namespace for the "login" command
|
5
|
+
module Login
|
6
|
+
LOGIN_PATH = '/v1/auth/login'
|
7
|
+
extend Dry::Monads[:result]
|
8
|
+
|
9
|
+
# @return [Result] the status of the call
|
10
|
+
def self.run(url:, login_service: LoginPrompt)
|
11
|
+
request_json = JSON.generate(login_service.run)
|
12
|
+
response = Faraday.post(url + LOGIN_PATH, request_json, 'Content-Type' => 'application/json')
|
13
|
+
case response.status
|
14
|
+
when 200
|
15
|
+
Credentials.write(response.body)
|
16
|
+
Success()
|
17
|
+
when 400
|
18
|
+
Failure('Email address is not a valid email')
|
19
|
+
when 401
|
20
|
+
Failure('Invalid username or password')
|
21
|
+
else
|
22
|
+
Failure("Status: #{response.status}\n#{response.body}")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'io/console'
|
4
|
+
|
5
|
+
module SdrClient
|
6
|
+
# The namespace for the "login" command
|
7
|
+
module LoginPrompt
|
8
|
+
def self.run
|
9
|
+
print 'Email: '
|
10
|
+
email = gets
|
11
|
+
email.strip!
|
12
|
+
print 'Password: '
|
13
|
+
password = $stdin.noecho(&:gets)
|
14
|
+
password.strip!
|
15
|
+
puts
|
16
|
+
{ email: email, password: password }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/sdr_client/version.rb
CHANGED
data/sdr-client.gemspec
CHANGED
@@ -27,7 +27,8 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ['lib']
|
29
29
|
|
30
|
-
spec.add_dependency '
|
30
|
+
spec.add_dependency 'dry-monads'
|
31
|
+
spec.add_dependency 'faraday', '>= 0.16'
|
31
32
|
|
32
33
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
33
34
|
spec.add_development_dependency 'rake', '~> 13.0'
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sdr-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
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-
|
11
|
+
date: 2020-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dry-monads
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: faraday
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
|
-
- - "
|
31
|
+
- - ">="
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
33
|
+
version: '0.16'
|
20
34
|
type: :runtime
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
|
-
- - "
|
38
|
+
- - ">="
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
40
|
+
version: '0.16'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,11 +160,17 @@ files:
|
|
146
160
|
- exe/sdr
|
147
161
|
- lib/sdr_client.rb
|
148
162
|
- lib/sdr_client/cli.rb
|
163
|
+
- lib/sdr_client/credentials.rb
|
149
164
|
- lib/sdr_client/deposit.rb
|
165
|
+
- lib/sdr_client/deposit/default_file_set_builder.rb
|
166
|
+
- lib/sdr_client/deposit/file.rb
|
167
|
+
- lib/sdr_client/deposit/file_set.rb
|
150
168
|
- lib/sdr_client/deposit/files/direct_upload_request.rb
|
151
169
|
- lib/sdr_client/deposit/files/direct_upload_response.rb
|
152
170
|
- lib/sdr_client/deposit/process.rb
|
153
171
|
- lib/sdr_client/deposit/request.rb
|
172
|
+
- lib/sdr_client/login.rb
|
173
|
+
- lib/sdr_client/login_prompt.rb
|
154
174
|
- lib/sdr_client/version.rb
|
155
175
|
- sdr-client.gemspec
|
156
176
|
homepage: https://github.com/sul-dlss/sdr-client
|
@@ -174,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
194
|
- !ruby/object:Gem::Version
|
175
195
|
version: '0'
|
176
196
|
requirements: []
|
177
|
-
rubygems_version: 3.0.
|
197
|
+
rubygems_version: 3.0.3
|
178
198
|
signing_key:
|
179
199
|
specification_version: 4
|
180
200
|
summary: The CLI for https://github.com/sul-dlss/sdr-api
|