scholarsphere-client 0.2.1 → 0.3.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/.circleci/config.yml +1 -1
- data/Gemfile.lock +46 -40
- data/README.md +55 -36
- data/bin/clean-vcr-files +8 -0
- data/lib/scholarsphere/client/upload.rb +6 -4
- data/lib/scholarsphere/client/version.rb +1 -1
- data/lib/scholarsphere/s3/uploaded_file.rb +1 -1
- data/lib/scholarsphere/s3/uploader.rb +10 -3
- data/sample.rb +37 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c6aea3fb4a9f848569bdfddfe98dfb9d1111d539f6b8fc9ed1a27d3a027ab71d
|
|
4
|
+
data.tar.gz: 5f0175bdad9582f9217c2e77efe82915be37db174380225d731991e90d85c49d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7d5c5f6c156b02d445f9d44a6d15456662e7d369df8442ee5e44364b65c62705d0f509584eb4891c1e799373dc44a452bb8af72b9fb2ed8d40a4c0edc7e65e21
|
|
7
|
+
data.tar.gz: f9327df0e587fa081a5cef599f930ad6746cb6fad76a1200df0795dcee76afd32ec331be6ff166ccb36c5821694680af5634aa606d4add456ca5ae85140abfff
|
data/.circleci/config.yml
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
scholarsphere-client (0.
|
|
4
|
+
scholarsphere-client (0.3.0)
|
|
5
5
|
aws-sdk-s3 (~> 1.49)
|
|
6
6
|
faraday (> 0.12)
|
|
7
7
|
marcel (~> 0.3)
|
|
@@ -9,13 +9,13 @@ PATH
|
|
|
9
9
|
GEM
|
|
10
10
|
remote: https://rubygems.org/
|
|
11
11
|
specs:
|
|
12
|
-
actionview (6.1.
|
|
13
|
-
activesupport (= 6.1.
|
|
12
|
+
actionview (6.1.3)
|
|
13
|
+
activesupport (= 6.1.3)
|
|
14
14
|
builder (~> 3.1)
|
|
15
15
|
erubi (~> 1.4)
|
|
16
16
|
rails-dom-testing (~> 2.0)
|
|
17
17
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
18
|
-
activesupport (6.1.
|
|
18
|
+
activesupport (6.1.3)
|
|
19
19
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
20
20
|
i18n (>= 1.6, < 2)
|
|
21
21
|
minitest (>= 5.1)
|
|
@@ -23,24 +23,24 @@ GEM
|
|
|
23
23
|
zeitwerk (~> 2.3)
|
|
24
24
|
addressable (2.7.0)
|
|
25
25
|
public_suffix (>= 2.0.2, < 5.0)
|
|
26
|
-
ast (2.4.
|
|
27
|
-
aws-eventstream (1.1.
|
|
28
|
-
aws-partitions (1.
|
|
29
|
-
aws-sdk-core (3.
|
|
26
|
+
ast (2.4.2)
|
|
27
|
+
aws-eventstream (1.1.1)
|
|
28
|
+
aws-partitions (1.435.0)
|
|
29
|
+
aws-sdk-core (3.113.0)
|
|
30
30
|
aws-eventstream (~> 1, >= 1.0.2)
|
|
31
31
|
aws-partitions (~> 1, >= 1.239.0)
|
|
32
32
|
aws-sigv4 (~> 1.1)
|
|
33
33
|
jmespath (~> 1.0)
|
|
34
|
-
aws-sdk-kms (1.
|
|
35
|
-
aws-sdk-core (~> 3, >= 3.
|
|
34
|
+
aws-sdk-kms (1.43.0)
|
|
35
|
+
aws-sdk-core (~> 3, >= 3.112.0)
|
|
36
36
|
aws-sigv4 (~> 1.1)
|
|
37
|
-
aws-sdk-s3 (1.
|
|
38
|
-
aws-sdk-core (~> 3, >= 3.
|
|
37
|
+
aws-sdk-s3 (1.93.0)
|
|
38
|
+
aws-sdk-core (~> 3, >= 3.112.0)
|
|
39
39
|
aws-sdk-kms (~> 1)
|
|
40
40
|
aws-sigv4 (~> 1.1)
|
|
41
|
-
aws-sigv4 (1.
|
|
42
|
-
aws-eventstream (~> 1
|
|
43
|
-
better_html (1.0.
|
|
41
|
+
aws-sigv4 (1.2.3)
|
|
42
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
|
43
|
+
better_html (1.0.16)
|
|
44
44
|
actionview (>= 4.0)
|
|
45
45
|
activesupport (>= 4.0)
|
|
46
46
|
ast (~> 2.0)
|
|
@@ -52,11 +52,11 @@ GEM
|
|
|
52
52
|
byebug (11.1.3)
|
|
53
53
|
coderay (1.1.3)
|
|
54
54
|
colorize (0.8.1)
|
|
55
|
-
concurrent-ruby (1.1.
|
|
55
|
+
concurrent-ruby (1.1.8)
|
|
56
56
|
crack (0.4.5)
|
|
57
57
|
rexml
|
|
58
58
|
crass (1.0.6)
|
|
59
|
-
diff-lcs (1.
|
|
59
|
+
diff-lcs (1.4.4)
|
|
60
60
|
docile (1.3.5)
|
|
61
61
|
erb_lint (0.0.37)
|
|
62
62
|
activesupport
|
|
@@ -67,24 +67,29 @@ GEM
|
|
|
67
67
|
rubocop
|
|
68
68
|
smart_properties
|
|
69
69
|
erubi (1.10.0)
|
|
70
|
-
faraday (1.0
|
|
70
|
+
faraday (1.3.0)
|
|
71
|
+
faraday-net_http (~> 1.0)
|
|
71
72
|
multipart-post (>= 1.2, < 3)
|
|
72
|
-
|
|
73
|
+
ruby2_keywords
|
|
74
|
+
faraday-net_http (1.0.1)
|
|
75
|
+
ffi (1.15.0)
|
|
73
76
|
hashdiff (1.0.1)
|
|
74
77
|
html_tokenizer (0.0.7)
|
|
75
|
-
i18n (1.8.
|
|
78
|
+
i18n (1.8.9)
|
|
76
79
|
concurrent-ruby (~> 1.0)
|
|
77
80
|
jmespath (1.4.0)
|
|
78
81
|
json (2.5.1)
|
|
79
|
-
loofah (2.
|
|
82
|
+
loofah (2.9.0)
|
|
80
83
|
crass (~> 1.0.2)
|
|
81
84
|
nokogiri (>= 1.5.9)
|
|
82
85
|
marcel (0.3.3)
|
|
83
86
|
mimemagic (~> 0.3.2)
|
|
84
87
|
method_source (1.0.0)
|
|
85
|
-
mimemagic (0.3.
|
|
88
|
+
mimemagic (0.3.9)
|
|
89
|
+
nokogiri (~> 1)
|
|
90
|
+
rake
|
|
86
91
|
mini_portile2 (2.5.0)
|
|
87
|
-
minitest (5.14.
|
|
92
|
+
minitest (5.14.4)
|
|
88
93
|
multipart-post (2.1.1)
|
|
89
94
|
niftany (0.8.0)
|
|
90
95
|
colorize (~> 0.8.1)
|
|
@@ -94,7 +99,7 @@ GEM
|
|
|
94
99
|
rubocop-rails (~> 2.3)
|
|
95
100
|
rubocop-rspec (~> 1.3)
|
|
96
101
|
scss_lint (~> 0.55)
|
|
97
|
-
nokogiri (1.11.
|
|
102
|
+
nokogiri (1.11.2)
|
|
98
103
|
mini_portile2 (~> 2.5.0)
|
|
99
104
|
racc (~> 1.4)
|
|
100
105
|
parallel (1.20.1)
|
|
@@ -115,28 +120,28 @@ GEM
|
|
|
115
120
|
rails-html-sanitizer (1.3.0)
|
|
116
121
|
loofah (~> 2.3)
|
|
117
122
|
rainbow (3.0.0)
|
|
118
|
-
rake (13.0.
|
|
123
|
+
rake (13.0.3)
|
|
119
124
|
rb-fsevent (0.10.4)
|
|
120
125
|
rb-inotify (0.10.1)
|
|
121
126
|
ffi (~> 1.0)
|
|
122
|
-
regexp_parser (2.
|
|
127
|
+
regexp_parser (2.1.1)
|
|
123
128
|
rexml (3.2.4)
|
|
124
|
-
rspec (3.
|
|
125
|
-
rspec-core (~> 3.
|
|
126
|
-
rspec-expectations (~> 3.
|
|
127
|
-
rspec-mocks (~> 3.
|
|
128
|
-
rspec-core (3.
|
|
129
|
-
rspec-support (~> 3.
|
|
130
|
-
rspec-expectations (3.
|
|
129
|
+
rspec (3.10.0)
|
|
130
|
+
rspec-core (~> 3.10.0)
|
|
131
|
+
rspec-expectations (~> 3.10.0)
|
|
132
|
+
rspec-mocks (~> 3.10.0)
|
|
133
|
+
rspec-core (3.10.1)
|
|
134
|
+
rspec-support (~> 3.10.0)
|
|
135
|
+
rspec-expectations (3.10.1)
|
|
131
136
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
132
|
-
rspec-support (~> 3.
|
|
137
|
+
rspec-support (~> 3.10.0)
|
|
133
138
|
rspec-its (1.3.0)
|
|
134
139
|
rspec-core (>= 3.0.0)
|
|
135
140
|
rspec-expectations (>= 3.0.0)
|
|
136
|
-
rspec-mocks (3.
|
|
141
|
+
rspec-mocks (3.10.2)
|
|
137
142
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
138
|
-
rspec-support (~> 3.
|
|
139
|
-
rspec-support (3.
|
|
143
|
+
rspec-support (~> 3.10.0)
|
|
144
|
+
rspec-support (3.10.2)
|
|
140
145
|
rubocop (0.93.1)
|
|
141
146
|
parallel (~> 1.10)
|
|
142
147
|
parser (>= 2.7.1.5)
|
|
@@ -146,9 +151,9 @@ GEM
|
|
|
146
151
|
rubocop-ast (>= 0.6.0)
|
|
147
152
|
ruby-progressbar (~> 1.7)
|
|
148
153
|
unicode-display_width (>= 1.4.0, < 2.0)
|
|
149
|
-
rubocop-ast (1.4.
|
|
154
|
+
rubocop-ast (1.4.1)
|
|
150
155
|
parser (>= 2.7.1.5)
|
|
151
|
-
rubocop-performance (1.
|
|
156
|
+
rubocop-performance (1.10.2)
|
|
152
157
|
rubocop (>= 0.90.0, < 2.0)
|
|
153
158
|
rubocop-ast (>= 0.4.0)
|
|
154
159
|
rubocop-rails (2.9.1)
|
|
@@ -159,6 +164,7 @@ GEM
|
|
|
159
164
|
rubocop (~> 0.87)
|
|
160
165
|
rubocop-ast (>= 0.7.1)
|
|
161
166
|
ruby-progressbar (1.11.0)
|
|
167
|
+
ruby2_keywords (0.0.4)
|
|
162
168
|
sass (3.7.4)
|
|
163
169
|
sass-listen (~> 4.0.0)
|
|
164
170
|
sass-listen (4.0.0)
|
|
@@ -176,7 +182,7 @@ GEM
|
|
|
176
182
|
concurrent-ruby (~> 1.0)
|
|
177
183
|
unicode-display_width (1.7.0)
|
|
178
184
|
vcr (6.0.0)
|
|
179
|
-
webmock (3.
|
|
185
|
+
webmock (3.12.2)
|
|
180
186
|
addressable (>= 2.3.6)
|
|
181
187
|
crack (>= 0.3.2)
|
|
182
188
|
hashdiff (>= 0.4.0, < 2.0.0)
|
data/README.md
CHANGED
|
@@ -6,9 +6,7 @@ Ruby client to update and create content in the Scholarsphere repository.
|
|
|
6
6
|
|
|
7
7
|
Add this line to your application's Gemfile:
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
gem 'scholarsphere-client'
|
|
11
|
-
```
|
|
9
|
+
gem 'scholarsphere-client'
|
|
12
10
|
|
|
13
11
|
And then execute:
|
|
14
12
|
|
|
@@ -33,42 +31,43 @@ If you are using a testing instance, you'll need to disable ssl verification:
|
|
|
33
31
|
|
|
34
32
|
### Ingesting
|
|
35
33
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
metadata = {
|
|
39
|
-
title: "My Awesome Work",
|
|
40
|
-
creators_attributes: [
|
|
41
|
-
{
|
|
42
|
-
display_name: 'Dr. Pat Researcher',
|
|
43
|
-
actor_attributes: {
|
|
44
|
-
psu_id: 'pxr123',
|
|
45
|
-
surname: 'Researcher',
|
|
46
|
-
given_name: 'Pat',
|
|
47
|
-
email: 'pxr123@psu.edu'
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
]
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
files = [ File.new('path/to/file') ]
|
|
34
|
+
See the `sample.rb` file for an executable example.
|
|
54
35
|
|
|
55
|
-
|
|
56
|
-
psu_id: 'pxr123',
|
|
57
|
-
surname: 'Researcher',
|
|
58
|
-
given_name: 'Pat',
|
|
59
|
-
email: 'pxr123@psu.edu'
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
ingest = Scholarsphere::Client::Ingest.new(
|
|
63
|
-
metadata: metadata,
|
|
64
|
-
files: files,
|
|
65
|
-
depositor: depositor
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
response = ingest.publish
|
|
36
|
+
To publish a work:
|
|
69
37
|
|
|
70
|
-
|
|
38
|
+
``` ruby
|
|
39
|
+
metadata = {
|
|
40
|
+
work_type: 'dataset',
|
|
41
|
+
visibility: 'open',
|
|
42
|
+
rights: 'https://creativecommons.org/licenses/by/4.0/',
|
|
43
|
+
title: 'Sample Title',
|
|
44
|
+
description: "This is a sample work",
|
|
45
|
+
published_date: '2010-01-01',
|
|
46
|
+
creators: [
|
|
47
|
+
{ orcid: '0000-0000-1111-222X' },
|
|
48
|
+
{ psu_id: 'axb123' },
|
|
49
|
+
{ display_name: 'Dr. Unidentified Creator' }
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
files = [
|
|
54
|
+
Pathname.new("/path/to/file1.txt"),
|
|
55
|
+
Pathname.new("/path/to/file2.txt")
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
ingest = Scholarsphere::Client::Ingest.new(
|
|
59
|
+
metadata: metadata,
|
|
60
|
+
files: files,
|
|
61
|
+
depositor: 'axb123'
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
response = ingest.publish
|
|
65
|
+
|
|
66
|
+
puts response.body
|
|
67
|
+
```
|
|
71
68
|
|
|
69
|
+
The json output should look like:
|
|
70
|
+
|
|
72
71
|
{
|
|
73
72
|
"message": "Work was successfully created",
|
|
74
73
|
"url": "/resources/0797e99c-7d4f-4e05-8bf6-86aea1029a6a"
|
|
@@ -77,3 +76,23 @@ To publish a work:
|
|
|
77
76
|
## Documentation
|
|
78
77
|
|
|
79
78
|
You can read the [ruby docs](https://www.rubydoc.info/github/psu-stewardship/scholarsphere-client/main) for the latest features.
|
|
79
|
+
|
|
80
|
+
## Testing
|
|
81
|
+
|
|
82
|
+
### Using an Existing Deployment
|
|
83
|
+
|
|
84
|
+
RSpec tests are run against saved API responses that are recorded using the VCR gem. If we want to run the test
|
|
85
|
+
suite against a live instance to see if our client works against a given deployment, update the endpoint in
|
|
86
|
+
`config/scholarsphere-client.yml` and run:
|
|
87
|
+
|
|
88
|
+
DISABLE_VCR=true bundle exec rspec
|
|
89
|
+
|
|
90
|
+
### Updating VCR Files
|
|
91
|
+
|
|
92
|
+
Simply removing the existing VCR files should be enough to update all the responses. If no yaml file exists for a given
|
|
93
|
+
test, VCR will record a new one. Be sure to clean up files afterwards using `bin/clean-vcr-files` which will remove
|
|
94
|
+
unnecessary binary data from the responses:
|
|
95
|
+
|
|
96
|
+
rm -Rf spec/fixtures/vcr_cassettes
|
|
97
|
+
bundle exec rspec
|
|
98
|
+
bin/clean-vcr-files
|
data/bin/clean-vcr-files
ADDED
|
@@ -10,8 +10,10 @@ module Scholarsphere
|
|
|
10
10
|
#
|
|
11
11
|
class Upload
|
|
12
12
|
# @param extname [String] Extension of the file to be uploaded, without the period, such as 'pdf'
|
|
13
|
-
|
|
13
|
+
# @param content_md5 [String] This should be the same as UploadedFile.content_md5
|
|
14
|
+
def initialize(extname:, content_md5:)
|
|
14
15
|
@extname = extname
|
|
16
|
+
@content_md5 = content_md5
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
# @return [String] Prefix where the file is stored in the S3 bucket.
|
|
@@ -31,18 +33,18 @@ module Scholarsphere
|
|
|
31
33
|
|
|
32
34
|
private
|
|
33
35
|
|
|
34
|
-
attr_reader :extname
|
|
36
|
+
attr_reader :extname, :content_md5
|
|
35
37
|
|
|
36
38
|
def request
|
|
37
39
|
@request ||= Scholarsphere::Client.connection.post do |req|
|
|
38
40
|
req.url 'uploads'
|
|
39
|
-
req.body = { extension: extname }.to_json
|
|
41
|
+
req.body = { extension: extname, content_md5: content_md5 }.to_json
|
|
40
42
|
end
|
|
41
43
|
end
|
|
42
44
|
|
|
43
45
|
def data
|
|
44
46
|
@data ||= begin
|
|
45
|
-
raise Client::Error unless request.success?
|
|
47
|
+
raise Client::Error.new(request.body) unless request.success?
|
|
46
48
|
|
|
47
49
|
JSON.parse(request.body)
|
|
48
50
|
end
|
|
@@ -24,15 +24,22 @@ module Scholarsphere
|
|
|
24
24
|
|
|
25
25
|
# @return [Faraday::Response] The response from Scholarsphere to the upload request.
|
|
26
26
|
def upload
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
raise Client::Error.new(request.body) unless request.success?
|
|
28
|
+
|
|
29
|
+
request
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
private
|
|
33
33
|
|
|
34
34
|
attr_reader :file, :content_md5
|
|
35
35
|
|
|
36
|
+
def request
|
|
37
|
+
@request ||= connection(file.presigned_url).put do |req|
|
|
38
|
+
req.body = file.source.read
|
|
39
|
+
req.headers['Content-MD5'] = file.content_md5
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
36
43
|
def connection(url)
|
|
37
44
|
Faraday::Connection.new(
|
|
38
45
|
url: url,
|
data/sample.rb
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'bundler/inline'
|
|
4
|
+
|
|
5
|
+
gemfile do
|
|
6
|
+
source 'https://rubygems.org'
|
|
7
|
+
gem 'scholarsphere-client', '~> 0.2'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
metadata = {
|
|
11
|
+
work_type: 'dataset',
|
|
12
|
+
visibility: 'open',
|
|
13
|
+
rights: 'https://creativecommons.org/licenses/by/4.0/',
|
|
14
|
+
title: 'Sample Title',
|
|
15
|
+
description: 'This is a sample work',
|
|
16
|
+
published_date: '2010-01-01',
|
|
17
|
+
creators: [
|
|
18
|
+
{ orcid: '0000-0000-1111-222X' },
|
|
19
|
+
{ psu_id: 'axb123' },
|
|
20
|
+
{ display_name: 'Dr. Unidentified Creator' }
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
files = [
|
|
25
|
+
Pathname.new('/path/to/file1.txt'),
|
|
26
|
+
Pathname.new('/path/to/file2.txt')
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
ingest = Scholarsphere::Client::Ingest.new(
|
|
30
|
+
metadata: metadata,
|
|
31
|
+
files: files,
|
|
32
|
+
depositor: 'axb123'
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
response = ingest.publish
|
|
36
|
+
|
|
37
|
+
puts response.body
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: scholarsphere-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Adam Wead
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-03-
|
|
11
|
+
date: 2021-03-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: aws-sdk-s3
|
|
@@ -223,6 +223,7 @@ files:
|
|
|
223
223
|
- Gemfile.lock
|
|
224
224
|
- README.md
|
|
225
225
|
- Rakefile
|
|
226
|
+
- bin/clean-vcr-files
|
|
226
227
|
- bin/console
|
|
227
228
|
- bin/setup
|
|
228
229
|
- config/.gitkeep
|
|
@@ -235,6 +236,7 @@ files:
|
|
|
235
236
|
- lib/scholarsphere/s3.rb
|
|
236
237
|
- lib/scholarsphere/s3/uploaded_file.rb
|
|
237
238
|
- lib/scholarsphere/s3/uploader.rb
|
|
239
|
+
- sample.rb
|
|
238
240
|
- scholarsphere-client.gemspec
|
|
239
241
|
homepage: https://github.com/psu-stewardship/scholarsphere-client
|
|
240
242
|
licenses: []
|