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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 218801f555a41f3c5a6b5f780903c8558c5df6d1b149470e649a763bf2f7fd39
4
- data.tar.gz: 498a782ecc5c745fa4b23c2bae2cd599b73a855dec072e91a1f96a254db9c8be
3
+ metadata.gz: 8cda403bd3db139414a52ba45bf1b56b4a049272c30c93c55992b565d641a884
4
+ data.tar.gz: 6417dbba3c344699a2eb1e108bbfe56fbc0e0beb35c485f9f817b4ba5c632c1a
5
5
  SHA512:
6
- metadata.gz: 6cd333801c73346653ca2a9780f9cf99d22bb2d2e343d424dff73e48a6789dd87487309a8d7ae72b905bc6c9512de2f84d12f08e188c8a2d0cf1f18add2344c2
7
- data.tar.gz: 65ad0e6cf95d2a557195414226da5fa751dde28e3111370beb46c5f24b00b65781ba40183d8b3dbee3fe568eab3520bf355920aa975e215326d20af5695978af
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.0)
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.3)
17
+ http-cookie (1.0.4)
18
18
  domain_name (~> 0.5)
19
19
  method_source (1.0.0)
20
- mime-types (3.3.1)
20
+ mime-types (3.4.1)
21
21
  mime-types-data (~> 3.2015)
22
- mime-types-data (3.2021.0225)
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.7.7)
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.15
63
+ 2.2.18
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
- # Dataverse
1
+ # Dataverse API gem
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dataverse`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- $ bundle install
15
+ ```
16
+ $ bundle install
17
+ ```
18
18
 
19
19
  Or install it yourself as:
20
20
 
21
- $ gem install dataverse
21
+ ```
22
+ $ gem install dataverse
23
+ ```
22
24
 
23
25
  ## Usage
24
26
 
25
- This gem wraps the Dataverse.org 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.
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 dataverses.
43
+ The class that captures the api dealing with Dataverse collections.
36
44
 
37
- ### Accessing an existing dataverse
45
+ ### Accessing an existing Dataverse collection
38
46
 
39
- You can create a new instance by supplying the id or alias of an existing dataverse to the constructor:
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 dataverse.
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 dataverse
61
+ ### Creating a new Dataverse collection
54
62
 
55
- To create a new dataverse, you should first open an instance for the parent dataverse, then call the #create method on it, supplying either a Hash, a file name or a JSON string.
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 dataverse can be retrieved as a Hash with the #rdm_data method:
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 dataverse:
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 dataverse
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 dataverse
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 dataverse was already published, the call will raise a Dataverse::Error exception.
123
+ Note that if a Dataverse collection was already published, the call will raise a Dataverse::Error exception.
116
124
 
117
- ### Access dataverse properties
125
+ ### Access properties of a Dataverse collection
118
126
 
119
- The Dataverse properties can be accessed similar to a Hash:
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 dataverses and datasets:
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 dataverses recursively:
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.each_dataverse do |dv|
213
- puts dv.size
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 dataverse. You should supply either a Hash, a file name or a JSON string to the #create_dataset method.
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 dataverse, either directly or by saving it to a file.
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 dataverse 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.
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 dataverse, either directly or by saving it to a file.
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).
@@ -25,7 +25,7 @@ module Dataverse
25
25
  end
26
26
 
27
27
  def delete
28
- url = raise Error.new 'Can only delete draft version' unless draft_version
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". params: {includCached: 'true'})
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
- data = @version_data[resolve_version(version)].transform_keys {|k| k == 'id' ? 'versionId' : k}
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
@@ -127,7 +127,7 @@ module Dataverse
127
127
  end
128
128
 
129
129
  def export_metadata(md_type)
130
- format = case md_type.to_s
130
+ case md_type.to_s
131
131
  when 'rdm'
132
132
  return rdm_data
133
133
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dataverse
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.4"
5
5
  end
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.0
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-04-06 00:00:00.000000000 Z
11
+ date: 2021-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client