dataverse 0.1.8 → 0.1.10

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: 49b1b7ca158eabe9bc66b2bd0e83a6e1da6aa0fe6984acef57119a477bc0252d
4
- data.tar.gz: 426a3872a464ec3954b71b1c87851795be6ac219ef2f9777e38748f2c00b4914
3
+ metadata.gz: 2da0e7678288d4f1091c613efaef0214423da1c678f5dea4f905ba0117d6309e
4
+ data.tar.gz: 5529f3d38a3625932b4e181dcbef378bc8dc92edb9bdd8dd4a60a3044cb2c786
5
5
  SHA512:
6
- metadata.gz: a3bb597791841213b4c1b445e62b511f5de2226e55ade9b16134afa3d96b7963892e42d429397a938237bb02f596662ba757d0497981c7419cdb284e0ecc1c32
7
- data.tar.gz: cd3bf30ffc312df8142d2c176c3ecc7caddafb9e6a47bdcff2a364236d7e2841de05d8d789ff87cbf97efe32021e541cd1418ea515e4665edba1feaa404457f3
6
+ metadata.gz: b9217fc9aa689af803b1658e3d2549aa7f269f027afc2776d9c0d211a26df2dbe98c708fe64bfa20179835f5089afae147a8bf60d87f4e4c8bec5a0a8c15d0ba
7
+ data.tar.gz: a5adaec85a22668edd06b6b0598233bf78335cec5fd62882b902a5d57b99859fb4fd3c486597c127450fbf42b8f6cbe64cd14c2cf25ebf00a8a7d2f5b0c09226
data/.gitignore CHANGED
@@ -14,3 +14,4 @@
14
14
 
15
15
  /*.json
16
16
  /*.xml
17
+ /*.rb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dataverse (0.1.8)
4
+ dataverse (0.1.10)
5
5
  rest-client (~> 2.0)
6
6
 
7
7
  GEM
@@ -19,7 +19,7 @@ GEM
19
19
  method_source (1.0.0)
20
20
  mime-types (3.4.1)
21
21
  mime-types-data (~> 3.2015)
22
- mime-types-data (3.2022.0105)
22
+ mime-types-data (3.2023.0218.1)
23
23
  netrc (0.11.0)
24
24
  pry (0.14.1)
25
25
  coderay (~> 1.1)
@@ -60,4 +60,4 @@ DEPENDENCIES
60
60
  rspec (~> 3.0)
61
61
 
62
62
  BUNDLED WITH
63
- 2.2.32
63
+ 2.3.25
@@ -49,7 +49,7 @@ module Dataverse
49
49
  self.class.api_call(url, **args)
50
50
  end
51
51
 
52
- def self.api_call(url, method: :get, headers: {}, params: {}, body: nil, format: :api, block: nil, options: {})
52
+ def self.api_call(url, method: :get, headers: {}, params: {}, body: nil, format: :api, block: nil, timeout: 120, options: {})
53
53
 
54
54
  unless ENV.has_key?('API_URL') && ENV.has_key?('API_TOKEN')
55
55
  raise Error.new("Set environment variables 'API_URL' and 'API_TOKEN'")
@@ -83,6 +83,7 @@ module Dataverse
83
83
  url: url,
84
84
  headers: headers,
85
85
  payload: body,
86
+ timeout: timeout,
86
87
  # log: STDOUT,
87
88
  **options
88
89
  )
@@ -117,8 +118,8 @@ module Dataverse
117
118
  end
118
119
  end
119
120
 
120
- # if log = ENV['RESTCLIENT_LOG']
121
- # RestClient.log = STDOUT if log.upcase == 'STDOUT'
122
- # RestClient.log = STDERR if log.upcase == 'STDERR'
123
- # RestClient.log = log
124
- # end
121
+ if log = ENV['RESTCLIENT_LOG']
122
+ RestClient.log = STDOUT if log.upcase == 'STDOUT'
123
+ RestClient.log = STDERR if log.upcase == 'STDERR'
124
+ RestClient.log = log
125
+ end
@@ -74,28 +74,65 @@ module Dataverse
74
74
  api_call("dataverses/#{id}/#{url}", **args)
75
75
  end
76
76
 
77
- def children
78
- @children ||= begin
79
- result = []
80
- data = call("contents")
81
- data.each do |x|
77
+ def each_child(&block)
78
+ data = call("contents")
79
+ data.each do |x|
80
+ begin
82
81
  case x['type']
83
82
  when 'dataverse'
84
- result << Dataverse.id(x['id'])
83
+ dv = Dataverse.id(x['id'])
84
+ data << (block_given? ? yield(child) : child)
85
+
85
86
  when 'dataset'
86
87
  ds = Dataset.id(x['id'])
87
88
  result << ds if ds.version
88
89
  else
89
90
  raise Error.new("Unsupported type: #{x['type']} (#{x['name']})")
90
91
  end
92
+ rescue => e
93
+ puts "ERROR: Skipped creating #{x['type']} object '#{x['id']}' : '#{e.message}'."
94
+ end
95
+ end
96
+ result
97
+ end
98
+
99
+
100
+ def children(&block)
101
+ if @children && @children.is_a?(Array)
102
+ @children.each { |child| yield(child) } if block_given?
103
+ else
104
+ @children = begin
105
+ result = []
106
+ data = call("contents")
107
+ data.each do |x|
108
+ begin
109
+ case x['type']
110
+ when 'dataverse'
111
+ dv = Dataverse.id(x['id'])
112
+ yield dv if block_given?
113
+ result << dv
114
+ when 'dataset'
115
+ ds = Dataset.id(x['id'])
116
+ if ds.version
117
+ yield ds if block_given?
118
+ result << ds
119
+ end
120
+ else
121
+ raise Error.new("Unsupported type: #{x['type']} (#{x['name']})")
122
+ end
123
+ rescue => e
124
+ puts "ERROR: Skipped #{x['type']} object '#{x['id']}' : '#{e.message}'."
125
+ end
126
+ end
127
+ result
91
128
  end
92
- result
93
129
  end
130
+ @children
94
131
  end
95
132
 
96
133
  def each_dataverse(&block)
97
134
  data = []
98
- children.each do |child|
135
+ children do |child|
99
136
  if child.is_a?(Dataverse)
100
137
  data << (block_given? ? yield(child) : child)
101
138
  data += child.each_dataverse(&block)
@@ -106,7 +143,7 @@ module Dataverse
106
143
 
107
144
  def each_dataset(&block)
108
145
  data = []
109
- children.each do |child|
146
+ children do |child|
110
147
  if child.is_a?(Dataverse)
111
148
  data += child.each_dataset(&block)
112
149
  elsif child.is_a?(Dataset)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dataverse
4
- VERSION = "0.1.8"
4
+ VERSION = "0.1.10"
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.8
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kris Dekeyser
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-07 00:00:00.000000000 Z
11
+ date: 2023-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  requirements: []
76
- rubygems_version: 3.1.6
76
+ rubygems_version: 3.4.13
77
77
  signing_key:
78
78
  specification_version: 4
79
79
  summary: Dataverse API.