dataverse 0.1.0 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +7 -6
- data/README.md +40 -32
- data/lib/dataverse/dataset.rb +23 -4
- data/lib/dataverse/dataverse.rb +1 -1
- data/lib/dataverse/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cda403bd3db139414a52ba45bf1b56b4a049272c30c93c55992b565d641a884
|
4
|
+
data.tar.gz: 6417dbba3c344699a2eb1e108bbfe56fbc0e0beb35c485f9f817b4ba5c632c1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 390ffc30a79de1d3a8ad498f1ddd6e09952dd6f0b01430a3c07de2ea66378cd0c3f05eea5722eae0541e95bae17732a03ad71171fc35068c14c5542473c8cc2b
|
7
|
+
data.tar.gz: 3cb02dfbf012360d234607669c30ce7ecbcf001269fe35bdde96ddf9abd2a9c4bd9edf20e748fad6bf604bd6767139fd253da831b29383b7dce0e98d73db705d
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dataverse (0.1.
|
4
|
+
dataverse (0.1.4)
|
5
5
|
rest-client (~> 2.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -14,12 +14,12 @@ GEM
|
|
14
14
|
unf (>= 0.0.5, < 1.0.0)
|
15
15
|
dotenv (2.7.6)
|
16
16
|
http-accept (1.7.0)
|
17
|
-
http-cookie (1.0.
|
17
|
+
http-cookie (1.0.4)
|
18
18
|
domain_name (~> 0.5)
|
19
19
|
method_source (1.0.0)
|
20
|
-
mime-types (3.
|
20
|
+
mime-types (3.4.1)
|
21
21
|
mime-types-data (~> 3.2015)
|
22
|
-
mime-types-data (3.2021.
|
22
|
+
mime-types-data (3.2021.1115)
|
23
23
|
netrc (0.11.0)
|
24
24
|
pry (0.14.0)
|
25
25
|
coderay (~> 1.1)
|
@@ -45,9 +45,10 @@ GEM
|
|
45
45
|
rspec-support (3.10.2)
|
46
46
|
unf (0.1.4)
|
47
47
|
unf_ext
|
48
|
-
unf_ext (0.0.
|
48
|
+
unf_ext (0.0.8)
|
49
49
|
|
50
50
|
PLATFORMS
|
51
|
+
ruby
|
51
52
|
x86_64-linux
|
52
53
|
|
53
54
|
DEPENDENCIES
|
@@ -59,4 +60,4 @@ DEPENDENCIES
|
|
59
60
|
rspec (~> 3.0)
|
60
61
|
|
61
62
|
BUNDLED WITH
|
62
|
-
2.2.
|
63
|
+
2.2.18
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
# Dataverse
|
1
|
+
# Dataverse API gem
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
This gem wraps the Dataverse API in a set of Ruby classes. You can use the classes to perform the API calls and process the result on the Ruby objects. It builds upon the rest-client gem to perform the low-level REST API calls. For more information about Dataverse and the API, see https://dataverse.org/ and https://guides.dataverse.org/en/latest/api/index.html
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -14,15 +12,23 @@ gem 'dataverse'
|
|
14
12
|
|
15
13
|
And then execute:
|
16
14
|
|
17
|
-
|
15
|
+
```
|
16
|
+
$ bundle install
|
17
|
+
```
|
18
18
|
|
19
19
|
Or install it yourself as:
|
20
20
|
|
21
|
-
|
21
|
+
```
|
22
|
+
$ gem install dataverse
|
23
|
+
```
|
22
24
|
|
23
25
|
## Usage
|
24
26
|
|
25
|
-
|
27
|
+
First load the library with
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'dataverse'
|
31
|
+
```
|
26
32
|
|
27
33
|
In order to configure the API calls, you need to define at least two environment variables:
|
28
34
|
|
@@ -30,29 +36,31 @@ In order to configure the API calls, you need to define at least two environment
|
|
30
36
|
- API_TOKEN: a token to identify and authorize the user. Note that for some API calls a superuser token may be required.
|
31
37
|
- RESTCLIENT_LOG: if defined, will log the REST API calls to the given file. Set to 'stdout' if you want to log to screen.
|
32
38
|
|
39
|
+
You can set these environment variables in a .env file and use the dotenv gem to load the variables. The file .env.template is provided as a starting point for you.
|
40
|
+
|
33
41
|
## Dataverse::Dataverse
|
34
42
|
|
35
|
-
The class that captures the api dealing with
|
43
|
+
The class that captures the api dealing with Dataverse collections.
|
36
44
|
|
37
|
-
### Accessing an existing
|
45
|
+
### Accessing an existing Dataverse collection
|
38
46
|
|
39
|
-
You can create a new instance by supplying the id or alias of an existing
|
47
|
+
You can create a new instance by supplying the id or alias of an existing Dataverse collection to the constructor:
|
40
48
|
|
41
49
|
```ruby
|
42
50
|
Dataverse::Dataverse.id('my_dataverse')
|
43
51
|
# => #<Dataverse::Dataverse:0x0...>
|
44
52
|
```
|
45
53
|
|
46
|
-
You can pass the value ':root' or use the #root class method if you want to access the root
|
54
|
+
You can pass the value ':root' or use the #root class method if you want to access the Dataverse root collection.
|
47
55
|
|
48
56
|
```ruby
|
49
57
|
Dataverse::Dataverse.id(':root') == Dataverse::Dataverse.root
|
50
58
|
# => true
|
51
59
|
```
|
52
60
|
|
53
|
-
### Creating a new
|
61
|
+
### Creating a new Dataverse collection
|
54
62
|
|
55
|
-
To create a new
|
63
|
+
To create a new Dataverse collection, you should first open an instance for the parent Dataverse collection, then call the #create method on it, supplying either a Hash, a file name or a JSON string.
|
56
64
|
|
57
65
|
```ruby
|
58
66
|
parent_dv = Dataverse::Dataverse.id('parent_dv')
|
@@ -77,14 +85,14 @@ Dataverse::Dataverse::TYPES
|
|
77
85
|
# "UNCATEGORIZED"]
|
78
86
|
```
|
79
87
|
|
80
|
-
All the metadata of an existing
|
88
|
+
All the metadata of an existing Dataverse collection can be retrieved as a Hash with the #rdm_data method:
|
81
89
|
|
82
90
|
```ruby
|
83
91
|
parent_dv.rdm_data
|
84
92
|
# => {"id"=>5, "alias"=>"parent_dv", ...}
|
85
93
|
```
|
86
94
|
|
87
|
-
The resulting Hash can be saved to a file and used to create a new
|
95
|
+
The resulting Hash can be saved to a file and used to create a new Dataverse collection:
|
88
96
|
|
89
97
|
```ruby
|
90
98
|
data = parent_dv.rdm_data.dup
|
@@ -95,14 +103,14 @@ new_dv = parent_dv.create(filename)
|
|
95
103
|
# => #<Dataverse::Dataverse:0x0...>
|
96
104
|
```
|
97
105
|
|
98
|
-
### Deleting a
|
106
|
+
### Deleting a Dataverse collection
|
99
107
|
|
100
108
|
```ruby
|
101
109
|
new_dv.delete
|
102
110
|
# => {"message" => "Dataverse 15 deleted"}
|
103
111
|
```
|
104
112
|
|
105
|
-
### Publishing a
|
113
|
+
### Publishing a Dataverse collection
|
106
114
|
|
107
115
|
```ruby
|
108
116
|
new_dv.publish
|
@@ -112,11 +120,11 @@ new_dv.publish
|
|
112
120
|
# => Dataverse::Error: Dataverse new_dv has already been published
|
113
121
|
```
|
114
122
|
|
115
|
-
Note that if a
|
123
|
+
Note that if a Dataverse collection was already published, the call will raise a Dataverse::Error exception.
|
116
124
|
|
117
|
-
### Access
|
125
|
+
### Access properties of a Dataverse collection
|
118
126
|
|
119
|
-
The Dataverse
|
127
|
+
The properties of a Dataverse collection can be accessed similar to a Hash:
|
120
128
|
|
121
129
|
```ruby
|
122
130
|
parent_dv.keys
|
@@ -159,7 +167,7 @@ data
|
|
159
167
|
# => {"alias" => "new_dv", ...}
|
160
168
|
```
|
161
169
|
|
162
|
-
The id or alias that was used to instantiate the Dataverse:
|
170
|
+
The id or alias that was used to instantiate the Dataverse collection:
|
163
171
|
|
164
172
|
```ruby
|
165
173
|
parent_dv.id
|
@@ -179,7 +187,7 @@ parent_dv['alias']
|
|
179
187
|
# => "parent_dv"
|
180
188
|
```
|
181
189
|
|
182
|
-
### Report the data file size of a Dataverse (in bytes)
|
190
|
+
### Report the data file size of a Dataverse collection (in bytes)
|
183
191
|
|
184
192
|
```ruby
|
185
193
|
parent_dv.size
|
@@ -188,14 +196,14 @@ parent_dv.size
|
|
188
196
|
|
189
197
|
### Browsing
|
190
198
|
|
191
|
-
Get an array of child
|
199
|
+
Get an array of child Dataverse collections and datasets:
|
192
200
|
|
193
201
|
```ruby
|
194
202
|
parent_dv.children
|
195
203
|
# => [#<Dataverse::Dataverse:0x0...>, #<Dataverse::Dataset:0x0...>]
|
196
204
|
```
|
197
205
|
|
198
|
-
Iterate over all child
|
206
|
+
Iterate over all child Dataverse collections recursively:
|
199
207
|
|
200
208
|
```ruby
|
201
209
|
parent_dv.each_dataverse do |dv|
|
@@ -209,8 +217,8 @@ end
|
|
209
217
|
Iterate over all child datasets recursively:
|
210
218
|
|
211
219
|
```ruby
|
212
|
-
parent_dv.
|
213
|
-
puts
|
220
|
+
parent_dv.each_dataset do |ds|
|
221
|
+
puts ds.size
|
214
222
|
end
|
215
223
|
# => 123456
|
216
224
|
# => 456123
|
@@ -223,7 +231,7 @@ The class that encapsulates the dataset related API.
|
|
223
231
|
|
224
232
|
### Accessing an existing dataset
|
225
233
|
|
226
|
-
A new Dataset instance can be obtained from the parent Dataverse's #children call or can be directly instantiated if you know the dataset's id or persistent identifier:
|
234
|
+
A new Dataset instance can be obtained from the parent Dataverse collection's #children call or can be directly instantiated if you know the dataset's id or persistent identifier:
|
227
235
|
|
228
236
|
```ruby
|
229
237
|
ds = parent_dv.children[1]
|
@@ -238,7 +246,7 @@ Dataverse::Dataset.pid('doi:10.5072/FK2/J8SJZB')
|
|
238
246
|
|
239
247
|
### Creating a new dataset
|
240
248
|
|
241
|
-
A new dataset can only be created on an existing
|
249
|
+
A new dataset can only be created on an existing Dataverse collection. You should supply either a Hash, a file name or a JSON string to the #create_dataset method.
|
242
250
|
|
243
251
|
```ruby
|
244
252
|
ds = parent_dv.create_dataset(
|
@@ -259,7 +267,7 @@ data = ds.raw_data
|
|
259
267
|
# => {"datasetVersion" => {"metadataBlocks" => {"citation" => {...}}}}
|
260
268
|
```
|
261
269
|
|
262
|
-
The resulting Hash can be used to create a new
|
270
|
+
The resulting Hash can be used to create a new dataset, either directly or by saving it to a file.
|
263
271
|
|
264
272
|
```ruby
|
265
273
|
data = ds.raw_data
|
@@ -274,7 +282,7 @@ new_ds = parent_dv.create_dataset(filename)
|
|
274
282
|
|
275
283
|
### Importing a dataset
|
276
284
|
|
277
|
-
The #import_dataset method on a
|
285
|
+
The #import_dataset method on a Dataverse collection allows to import an existing dataset. The dataset should be registred and its persisten identifier should be supplied in the pid argument. The data argument is similar to the #create_dataset method.
|
278
286
|
|
279
287
|
```ruby
|
280
288
|
data = 'dataset.json'
|
@@ -415,7 +423,7 @@ data = ds.export_metadata('schema.org')
|
|
415
423
|
# => {"@context"=>"http://schema.org", "@type"=>"Dataset", ...}
|
416
424
|
```
|
417
425
|
|
418
|
-
The resulting Hash can be used to create a new
|
426
|
+
The resulting Hash can be used to create a new dataset, either directly or by saving it to a file.
|
419
427
|
|
420
428
|
```ruby
|
421
429
|
data = ds.raw_data
|
@@ -595,4 +603,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
595
603
|
|
596
604
|
## Code of Conduct
|
597
605
|
|
598
|
-
Everyone interacting in the Dataverse project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/libis/dataverse_api/blob/master/CODE_OF_CONDUCT.md).
|
606
|
+
Everyone interacting in the Dataverse API project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/libis/dataverse_api/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/dataverse/dataset.rb
CHANGED
@@ -25,7 +25,7 @@ module Dataverse
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def delete
|
28
|
-
|
28
|
+
raise Error.new 'Can only delete draft version' unless draft_version
|
29
29
|
versions
|
30
30
|
result = call('versions/:draft', method: :delete)
|
31
31
|
@version_data.delete(:draft)
|
@@ -61,7 +61,7 @@ module Dataverse
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def size
|
64
|
-
data = call("storagesize"
|
64
|
+
data = call("storagesize", params: {includeCached: 'true'})
|
65
65
|
data['message'][/[,\d]+/].delete(',').to_i
|
66
66
|
end
|
67
67
|
|
@@ -140,6 +140,13 @@ module Dataverse
|
|
140
140
|
.merge(version_data(version))
|
141
141
|
.merge('metadata' => metadata(version: version))
|
142
142
|
.merge('files' => files(version: version))
|
143
|
+
.tap do |h|
|
144
|
+
h['license'] = {
|
145
|
+
'label' => license_name,
|
146
|
+
'uri' => license_url,
|
147
|
+
'iconUrl' => license_icon
|
148
|
+
}
|
149
|
+
end
|
143
150
|
end
|
144
151
|
|
145
152
|
def raw_data(version: :latest, with_files: false)
|
@@ -188,6 +195,18 @@ module Dataverse
|
|
188
195
|
end
|
189
196
|
end
|
190
197
|
|
198
|
+
def license_url
|
199
|
+
fetch('termsOfUse')[/(?<=href=")[^"]*(?=")/] rescue nil
|
200
|
+
end
|
201
|
+
|
202
|
+
def license_name
|
203
|
+
fetch('termsOfUse')[/[^>]*(?=<\/a>.$)/] rescue nil
|
204
|
+
end
|
205
|
+
|
206
|
+
def license_icon
|
207
|
+
fetch('termsOfUse')[/(?<=src=")[^"]*(?=")/] rescue nil
|
208
|
+
end
|
209
|
+
|
191
210
|
protected
|
192
211
|
|
193
212
|
def initialize(id)
|
@@ -255,7 +274,7 @@ module Dataverse
|
|
255
274
|
end
|
256
275
|
|
257
276
|
def version_data(version)
|
258
|
-
|
277
|
+
@version_data[resolve_version(version)].transform_keys { |k| k == 'id' ? 'versionId' : k }
|
259
278
|
end
|
260
279
|
|
261
280
|
private
|
@@ -373,4 +392,4 @@ module Dataverse
|
|
373
392
|
end
|
374
393
|
|
375
394
|
end
|
376
|
-
end
|
395
|
+
end
|
data/lib/dataverse/dataverse.rb
CHANGED
data/lib/dataverse/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dataverse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kris Dekeyser
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|