figshare_api_v2 0.9.9 → 0.9.10
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/History.txt +20 -0
- data/lib/base.rb +59 -35
- data/lib/figshare_api_v2.rb +1 -1
- data/lib/institutions.rb +26 -5
- data/lib/private_projects.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: 1b02d428dc8877f75c9bf9ba05d54b1465944745ec2ff1ca0c962bc6803cdc0a
|
4
|
+
data.tar.gz: 6095dffd50dbd105b0ccadeffd3f9243c0434f44cb79bcec32872008add97fab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59456d19b2df1624bd7f276c6672326ce888fa967f51ff8aace4b8317ac67990e579aaa85affcd098f4b390b46073353df479d50cd9a65b1b690e04d2a96fcc1
|
7
|
+
data.tar.gz: c06980357bed4295c410ae9f08a04de00108620647268445990c8d7c5a82221d4d824c0a32e1baa08918f9be9c628057afce07dca3c5da2b0013258f1258e485
|
data/History.txt
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
robertburrowes Fri May 13 08:40:05 2022 +1200
|
2
|
+
Bumped minor version
|
3
|
+
robertburrowes Thu May 12 17:25:07 2022 +1200
|
4
|
+
Moved the accounts_wrapper() into institution.accounts(), less the debugging stuff
|
5
|
+
robertburrowes Thu May 12 17:06:48 2022 +1200
|
6
|
+
Comment
|
7
|
+
robertburrowes Thu May 12 16:52:57 2022 +1200
|
8
|
+
Check returned account IDs are in order (they do seem to be)
|
9
|
+
robertburrowes Thu May 12 16:32:58 2022 +1200
|
10
|
+
Incorporate the new id_gte into institute.accounts, as page/page_size pagination has a 9000 record limit.
|
11
|
+
robertburrowes Thu May 12 16:22:48 2022 +1200
|
12
|
+
return earlier, in _paginate, to not set 'page'
|
13
|
+
robertburrowes Thu May 12 15:56:44 2022 +1200
|
14
|
+
Added 'once_only' to the post and get _pagination calls, so we don't automatically move onto the next page.
|
15
|
+
robertburrowes Thu May 12 11:18:45 2022 +1200
|
16
|
+
Refactored _pagination response code to see if it helped fix the duplicate record issue. It didn't.
|
17
|
+
robertburrowes Thu May 12 09:43:45 2022 +1200
|
18
|
+
Added debug output of updated Figshare API.
|
19
|
+
robertburrowes Wed May 11 09:07:42 2022 +1200
|
20
|
+
update comments
|
1
21
|
robertburrowes Tue May 10 10:42:27 2022 +1200
|
2
22
|
Comment
|
3
23
|
robertburrowes Tue May 10 10:40:02 2022 +1200
|
data/lib/base.rb
CHANGED
@@ -71,41 +71,53 @@ module Figshare
|
|
71
71
|
# @param by_offset [Boolean] use offset/limit rather than page/page_size in API calls
|
72
72
|
# @yield [String] if given a block, iterates through the result from figshare
|
73
73
|
# @return [Integer] number of results.
|
74
|
-
private def get_paginate(api_query:, args: {}, debug: false, by_offset: false, &block)
|
74
|
+
private def get_paginate(api_query:, args: {}, debug: false, by_offset: false, once_only: false, &block)
|
75
75
|
args = {} if args.nil?
|
76
|
-
|
77
|
-
raise 'get_paginate(): Expecting args to be a Hash'
|
78
|
-
end
|
79
|
-
|
80
|
-
# Loop variables, if we are using pages
|
81
|
-
page = args['page'].nil? ? 1 : args['page']
|
82
|
-
page_size = args['page_size'].nil? ? 100 : args['page_size']
|
83
|
-
|
84
|
-
# Loop variables, if we are using offsets
|
85
|
-
offset = args['offset'].nil? ? 0 : args['offset']
|
86
|
-
limit = args['limit'].nil? ? 100 : args['limit']
|
76
|
+
raise 'get_paginate(): Expecting args to be a Hash' unless args.is_a?(Hash)
|
87
77
|
|
88
78
|
by_offset = true if args['page'].nil? && ! args['offset'].nil?
|
79
|
+
if by_offset
|
80
|
+
# Loop variables, if we are using offsets
|
81
|
+
offset = args['offset'].nil? ? 0 : args['offset']
|
82
|
+
limit = args['limit'].nil? ? 100 : args['limit']
|
83
|
+
args['offset'] = offset
|
84
|
+
args['limit'] = limit
|
85
|
+
else
|
86
|
+
page = args['page'].nil? ? 1 : args['page']
|
87
|
+
page_size = args['page_size'].nil? ? 100 : args['page_size']
|
88
|
+
args['page'] = page
|
89
|
+
args['page_size'] = page_size
|
90
|
+
end
|
89
91
|
|
90
92
|
# How many results so far.
|
91
93
|
result_count = 0
|
92
94
|
|
93
95
|
loop do
|
94
96
|
content_type = response = nil
|
95
|
-
form_args = by_offset ? { 'limit' => limit, 'offset' => offset } : { 'page_size' => page_size, 'page' => page }
|
96
97
|
WIKK::WebBrowser.https_session( host: @hostname, verify_cert: false ) do |ws|
|
97
98
|
response = ws.get_page( query: "#{@api_url}#{api_query}",
|
98
99
|
authorization: "token #{@auth_token}",
|
99
|
-
form_values:
|
100
|
+
form_values: args
|
100
101
|
)
|
101
102
|
content_type = ws.header_value(key: 'Content-Type')
|
102
103
|
end
|
104
|
+
# File.write("/tmp/debug_#{args['id_gte']}_#{page}.json", response)
|
103
105
|
page_count = iterate_json_response(response: response, content_type: content_type, debug: debug, &block)
|
104
106
|
result_count += page_count
|
105
|
-
break if page_count < page_size # Got less results than we asked for, so it was the last page
|
106
107
|
|
107
|
-
|
108
|
-
|
108
|
+
return result_count if once_only
|
109
|
+
|
110
|
+
if by_offset
|
111
|
+
break if page_count < limit # Got less results than we asked for, so it was the last page
|
112
|
+
|
113
|
+
offset += limit # if we use offset
|
114
|
+
args['offset'] = offset
|
115
|
+
else
|
116
|
+
break if page_count < page_size # Got less results than we asked for, so it was the last page
|
117
|
+
|
118
|
+
page += 1 # Ready to fetch next page
|
119
|
+
args['page'] = page
|
120
|
+
end
|
109
121
|
end
|
110
122
|
|
111
123
|
return result_count
|
@@ -156,42 +168,54 @@ module Figshare
|
|
156
168
|
# @param by_offset [Boolean] use offset/limit rather than page/page_size in API calls
|
157
169
|
# @yield [String] if given a block, iterates through the result from figshare
|
158
170
|
# @return [Integer] number of results.
|
159
|
-
private def post_paginate(api_query:, args: {}, debug: false, by_offset: false, &block)
|
171
|
+
private def post_paginate(api_query:, args: {}, debug: false, by_offset: false, once_only: false, &block)
|
160
172
|
# Loop variables, if we are using pages
|
161
|
-
|
162
|
-
|
173
|
+
args = {} if args.nil?
|
174
|
+
raise 'post_paginate(): Expecting args to be a Hash' unless args.is_a?(Hash)
|
163
175
|
|
164
|
-
|
165
|
-
|
166
|
-
|
176
|
+
by_offset = true if args['page'].nil? && ! args['offset'].nil?
|
177
|
+
if by_offset
|
178
|
+
# Loop variables, if we are using offsets
|
179
|
+
offset = args['offset'].nil? ? 0 : args['offset']
|
180
|
+
limit = args['limit'].nil? ? 100 : args['limit']
|
181
|
+
args['offset'] = offset
|
182
|
+
args['limit'] = limit
|
183
|
+
else
|
184
|
+
page = args['page'].nil? ? 1 : args['page']
|
185
|
+
page_size = args['page_size'].nil? ? 100 : args['page_size']
|
186
|
+
args['page'] = page
|
187
|
+
args['page_size'] = page_size
|
188
|
+
end
|
167
189
|
|
168
190
|
# How many results so far.
|
169
191
|
result_count = 0
|
170
192
|
|
171
|
-
by_offset = true if args['page'].nil? && ! args['offset'].nil?
|
172
|
-
|
173
|
-
args = {} if args.nil?
|
174
|
-
if ! args.is_a?(Hash)
|
175
|
-
raise 'post_paginate(): Expecting args to be a Hash'
|
176
|
-
end
|
177
|
-
|
178
193
|
loop do
|
179
194
|
content_type = response = nil
|
180
|
-
form_args = by_offset ? { 'limit' => limit, 'offset' => offset } : { 'page_size' => page_size, 'page' => page }
|
181
195
|
WIKK::WebBrowser.https_session( host: @hostname, verify_cert: false ) do |ws|
|
182
196
|
response = ws.post_page( query: "#{@api_url}#{api_query}",
|
183
197
|
content_type: 'application/json; charset=UTF-8',
|
184
198
|
authorization: "token #{@auth_token}",
|
185
|
-
data: args.
|
199
|
+
data: args.to_j
|
186
200
|
)
|
187
201
|
content_type = ws.header_value(key: 'Content-Type')
|
188
202
|
end
|
189
203
|
page_count = iterate_json_response(response: response, content_type: content_type, debug: debug, &block)
|
190
204
|
result_count += page_count
|
191
|
-
break if page_count < page_size # Got less results than we asked for, so it was the last page
|
192
205
|
|
193
|
-
|
194
|
-
|
206
|
+
return result_count if once_only
|
207
|
+
|
208
|
+
if by_offset
|
209
|
+
break if page_count < limit # Got less results than we asked for, so it was the last page
|
210
|
+
|
211
|
+
offset += limit # if we use offset
|
212
|
+
args['offset'] = offset
|
213
|
+
else
|
214
|
+
break if page_count < page_size # Got less results than we asked for, so it was the last page
|
215
|
+
|
216
|
+
page += 1 # Ready to fetch next page
|
217
|
+
args['page'] = page
|
218
|
+
end
|
195
219
|
end
|
196
220
|
return result_count
|
197
221
|
end
|
data/lib/figshare_api_v2.rb
CHANGED
data/lib/institutions.rb
CHANGED
@@ -14,9 +14,9 @@ module Figshare
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
# Get the institional account details
|
17
|
+
# Get the institional account's details (not a person's account details)
|
18
18
|
#
|
19
|
-
# @yield [Hash]
|
19
|
+
# @yield [Hash] {id:, name: "institute"}
|
20
20
|
def account(&block)
|
21
21
|
get(api_query: 'account/institution', &block)
|
22
22
|
end
|
@@ -137,12 +137,13 @@ module Figshare
|
|
137
137
|
end
|
138
138
|
|
139
139
|
# Get the accounts for which the account has administrative privileges (assigned and inherited).
|
140
|
+
# Accounts are returned in account id order, and there is a 9000 user upper limit. See id_gte.
|
140
141
|
#
|
141
142
|
# @param is_active [Boolean] user account is active
|
142
143
|
# @param institution_user_id [String] As set in the HR upload
|
143
144
|
# @param email [String] as set in the HR upload
|
144
|
-
# @param id_lte [Integer] ID is <=
|
145
|
-
# @param id_gte [Integer] ID is >=
|
145
|
+
# @param id_lte [Integer] ID is <= Introduced to get around the buffer limit of 9000 users
|
146
|
+
# @param id_gte [Integer] ID is >= Introduced to get around the buffer limit of 9000 users
|
146
147
|
# @param page [Numeric] Pages start at 1. Page and Page size go together
|
147
148
|
# @param page_size [Numeric]
|
148
149
|
# @param offset [Numeric] offset is 0 based. Offset and Limit go together
|
@@ -157,6 +158,7 @@ module Figshare
|
|
157
158
|
page_size: nil,
|
158
159
|
offset: nil,
|
159
160
|
limit: nil,
|
161
|
+
cursor_pagination: true,
|
160
162
|
&block
|
161
163
|
)
|
162
164
|
args = {}
|
@@ -169,7 +171,26 @@ module Figshare
|
|
169
171
|
args['page_size'] = page_size unless page_size.nil?
|
170
172
|
args['offset'] = offset unless offset.nil?
|
171
173
|
args['limit'] = limit unless limit.nil?
|
172
|
-
|
174
|
+
if cursor_pagination
|
175
|
+
highest_id_gte = 0
|
176
|
+
args['id_lte'] = nil
|
177
|
+
args['page_size'] = 100
|
178
|
+
loop do
|
179
|
+
count = 0
|
180
|
+
args['page'] = 1
|
181
|
+
args['id_gte'] = highest_id_gte + 1
|
182
|
+
get_paginate(api_query: 'account/institution/accounts', args: args, once_only: true) do |account|
|
183
|
+
next if account.nil? || account['id'].nil?
|
184
|
+
|
185
|
+
count += 1
|
186
|
+
highest_id_gte = account['id'].to_i if highest_id_gte < account['id'].to_i
|
187
|
+
yield account
|
188
|
+
end
|
189
|
+
break if count < 100 # Didn't reach the page_size limit.
|
190
|
+
end
|
191
|
+
else # Do it the old broken way (Pagination only works for the first 9000 entries)
|
192
|
+
get_paginate(api_query: 'account/institution/accounts', args: args, &block)
|
193
|
+
end
|
173
194
|
end
|
174
195
|
|
175
196
|
# Create new Institution Account
|
data/lib/private_projects.rb
CHANGED
@@ -363,7 +363,7 @@ module Figshare
|
|
363
363
|
# @param project_id [Integer] Figshare id of the project
|
364
364
|
# @param article_id [Integer] Figshare id of the article
|
365
365
|
# @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
|
366
|
-
# @yield [Array] See docs.figshare.com
|
366
|
+
# @yield [Array] See docs.figshare.com
|
367
367
|
def artilce_files(project_id:, article_id:, impersonate: nil, &block)
|
368
368
|
args = {}
|
369
369
|
args['impersonate'] = impersonate unless impersonate.nil?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: figshare_api_v2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Burrowes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-05-
|
11
|
+
date: 2022-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: wikk_json
|