figshare_api_v2 0.9.7 → 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.
data/lib/institutions.rb CHANGED
@@ -4,19 +4,30 @@ module Figshare
4
4
  class Institutions < Base
5
5
  # Upload hr file
6
6
  #
7
- # @param hr_xml [String] See https://docs.figshare.com/#hr_feed_hr_feed_private_endpoint
7
+ # @param hr_xml_filename [String] Filename. See https://docs.figshare.com/#hr_feed_hr_feed_private_endpoint
8
8
  # @yield [Hash] { message:, data: null, errcode:}
9
- def hr_upload(hr_xml:, &block)
10
- put(api_query: 'institution/hrfeed/upload', data: hr_xml, content_type: 'multipart/form-data', &block)
9
+ def hr_upload(hr_xml_filename:, &block)
10
+ File.open(@file_name, 'rb') do |fin|
11
+ hr_xml = fin.read
12
+ args = { 'name' => 'hrfeed', 'filename' => hr_xml_filename }
13
+ post(api_query: 'institution/hrfeed/upload', args: args, data: hr_xml, content_type: 'multipart/form-data', &block)
14
+ end
11
15
  end
12
16
 
13
- # Get the institional account details
17
+ # Get the institional account's details (not a person's account details)
14
18
  #
15
- # @yield [Hash]
19
+ # @yield [Hash] {id:, name: "institute"}
16
20
  def account(&block)
17
21
  get(api_query: 'account/institution', &block)
18
22
  end
19
23
 
24
+ # Get the institional account embargo options (IP Ranges)
25
+ #
26
+ # @yield [Array] list of embargo ip ranges [ {id:, type: ip_range, ip_name: Figshare_IP_Range} ]
27
+ def account_embargo_options(&block)
28
+ get(api_query: 'account/institution/embargo_options', &block)
29
+ end
30
+
20
31
  # Requests a list of private institute articles
21
32
  #
22
33
  # @param status [Integer] Only return items with this status
@@ -26,6 +37,10 @@ module Figshare
26
37
  # @param item_type [String] Matches this item_type. See Figshare API docs for list (https://docs.figshare.com/#articles_list)
27
38
  # @param order [String] "published_date" Default, "modified_date", "views", "cites", "shares"
28
39
  # @param order_direction [String] "desc" Default, "asc"
40
+ # @param page [Numeric] Pages start at 1. Page and Page size go together
41
+ # @param page_size [Numeric]
42
+ # @param offset [Numeric] offset is 0 based. Offset and Limit go together
43
+ # @param limit [Numeric]
29
44
  # @yield [Hash] {id, title, doi, handle, group_id, url, url_public_html, url_public_api, url_private_htm,
30
45
  # url_private_api, published_date, timeline {...}, thumb, defined_type, defined_name }
31
46
  def private_articles( status: nil,
@@ -35,6 +50,10 @@ module Figshare
35
50
  resource_doi: nil,
36
51
  order: 'published_date',
37
52
  order_direction: 'desc',
53
+ page: nil,
54
+ page_size: nil,
55
+ offset: nil,
56
+ limit: nil,
38
57
  &block
39
58
  )
40
59
  args = {}
@@ -45,6 +64,10 @@ module Figshare
45
64
  args['modified_since'] = modified_since unless modified_since.nil?
46
65
  args['order'] = order unless order.nil?
47
66
  args['order_direction'] = order_direction unless order_direction.nil?
67
+ args['page'] = page unless page.nil?
68
+ args['page_size'] = page_size unless page_size.nil?
69
+ args['offset'] = offset unless offset.nil?
70
+ args['limit'] = limit unless limit.nil?
48
71
  get_paginate(api_query: 'account/institution/articles', args: args, &block)
49
72
  end
50
73
 
@@ -58,42 +81,116 @@ module Figshare
58
81
  args = {}
59
82
  args['resource_id'] = resource_id unless resource_id.nil?
60
83
  args['filename'] = filename unless filename.nil?
61
- get(api_query: 'institutions/{@institute_id}/articles/filter-by', args: args, &block)
84
+ get(api_query: "institutions/#{@institute_id}/articles/filter-by", args: args, &block)
85
+ end
86
+
87
+ # Get an institute group's custom fields
88
+ #
89
+ # @param group_id [Integer] Figshare group_id
90
+ # @yield [Array] [ {id:, name: field_name, field_type: text } ]
91
+ def group_custom_fields(group_id: nil, &block )
92
+ args = {}
93
+ args['group_id'] = group_id unless group_id.nil?
94
+ get(api_query: 'account/institution/custom_fields', args: args, &block)
95
+ end
96
+
97
+ # Set institute group's custom fields, from a CSV file
98
+ #
99
+ # @param custom_field_id [Integer] Figshare group_id
100
+ # @param filename [Integer] Figshare group_id
101
+ # @yield [Hash] {code: 200, message: ok } ]
102
+ def group_set_custom_fields(custom_field_id:, filename: )
103
+ File.open(filename, 'rb') do |fin|
104
+ custom_fields_csv = fin.read
105
+ args = { 'name' => 'external_file', 'filename' => filename }
106
+ post(api_query: "account/institution/custom_fields/#{custom_field_id}/items/upload", args: args, data: custom_fields_csv, content_type: 'multipart/form-data', &block)
107
+ end
62
108
  end
63
109
 
64
110
  # Get institution categories (including parent Categories)
65
111
  #
66
- # @yield [Hash] { parent_id, id, title }
112
+ # @yield [Array] [ { parent_id: 1, id: 11, title: "Anatomy", path:"/450/1024/6532", source_id: "300204", taxonomy_id: 4 } ]
67
113
  def categories(&block)
68
114
  get(api_query: 'account/categories', &block)
69
115
  end
70
116
 
71
117
  # Get the groups for which the account has administrative privileges (assigned and inherited).
72
118
  #
73
- # @yield [Hash] { id, name, resource_id, parent_id, association_criteria }
119
+ # @yield [Array] [ { id: 1, name: "Materials", resource_id: "string", parent_id: 0, association_criteria: "IT" } ]
74
120
  def groups(&block)
75
121
  get(api_query: 'account/groups', &block)
76
122
  end
77
123
 
124
+ # Get the institional account group's embargo options (IP Ranges)
125
+ #
126
+ # @param group_id [Integer]
127
+ # @yield [Array] list of embargo ip ranges [ {id:, type: ip_range, ip_name: Figshare_IP_Range} ]
128
+ def group_embargo_options(group_id:, &block)
129
+ get(api_query: "account/institution/groups/#{group_id}/embargo_options", &block)
130
+ end
131
+
78
132
  # Get the roles available for groups and the institution group.
79
133
  #
80
- # @yield [Hash] { id, name, category, description }
134
+ # @yield [Array] [ { id:, name:, category:, description: } ]
81
135
  def roles(&block)
82
136
  get(api_query: 'account/roles', &block)
83
137
  end
84
138
 
85
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.
86
141
  #
87
142
  # @param is_active [Boolean] user account is active
88
143
  # @param institution_user_id [String] As set in the HR upload
89
144
  # @param email [String] as set in the HR upload
90
- # @yield [Hash] { id, first_name, last_name, institution_id, email, active, institution_user_id }
91
- def accounts(is_active: nil, institution_user_id: nil, email: nil, &block)
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
147
+ # @param page [Numeric] Pages start at 1. Page and Page size go together
148
+ # @param page_size [Numeric]
149
+ # @param offset [Numeric] offset is 0 based. Offset and Limit go together
150
+ # @param limit [Numeric]
151
+ # @yield [Array] [{ id:, first_name:, last_name:, institution_id:, email:, active:, institution_user_id:, quota:, used_quota:, user_id:, orcid_id: }]
152
+ def accounts( is_active: nil,
153
+ institution_user_id: nil,
154
+ email: nil,
155
+ id_lte: nil,
156
+ id_gte: nil,
157
+ page: nil,
158
+ page_size: nil,
159
+ offset: nil,
160
+ limit: nil,
161
+ cursor_pagination: true,
162
+ &block
163
+ )
92
164
  args = {}
93
165
  args['is_active'] = is_active unless is_active.nil?
94
166
  args['institution_user_id'] = institution_user_id unless institution_user_id.nil?
95
167
  args['email'] = email unless email.nil?
96
- get_paginate(api_query: 'account/institution/accounts', args: args, &block)
168
+ args['id_lte'] = id_lte unless id_lte.nil?
169
+ args['id_gte'] = id_gte unless id_gte.nil?
170
+ args['page'] = page unless page.nil?
171
+ args['page_size'] = page_size unless page_size.nil?
172
+ args['offset'] = offset unless offset.nil?
173
+ args['limit'] = limit unless limit.nil?
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
97
194
  end
98
195
 
99
196
  # Create new Institution Account
@@ -106,7 +203,16 @@ module Figshare
106
203
  # @param symplectic_user_id [string]
107
204
  # @param quota [Integer] Figshare user quota
108
205
  # @param is_active [Boolean]
109
- def account_create(email:, first_name:, last_name:, group_id:, institution_user_id: nil, symplectic_user_id: nil, quota: nil, is_active: true, &block)
206
+ def account_create( email:,
207
+ first_name:,
208
+ last_name:,
209
+ group_id:,
210
+ institution_user_id: nil,
211
+ symplectic_user_id: nil,
212
+ quota: nil,
213
+ is_active: true,
214
+ &block
215
+ )
110
216
  args = {}
111
217
  args['email'] = email unless email.nil?
112
218
  args['first_name'] = first_name unless first_name.nil?
@@ -116,11 +222,12 @@ module Figshare
116
222
  args['symplectic_user_id'] = symplectic_user_id unless symplectic_user_id.nil?
117
223
  args['quota'] = quota unless quota.nil?
118
224
  args['is_active'] = is_active unless is_active.nil?
119
- post(api_query: "account/institution/accounts/#{account_id}", args: args, &block)
225
+ post(api_query: 'account/institution/accounts', args: args, &block)
120
226
  end
121
227
 
122
228
  # Update Institution Account
123
229
  #
230
+ # @param account_id [Integer] Whose account
124
231
  # @param email [String]
125
232
  # @param first_name [String]
126
233
  # @param last_name [String]
@@ -129,7 +236,17 @@ module Figshare
129
236
  # @param symplectic_user_id [string]
130
237
  # @param quota [Integer] Figshare user quota
131
238
  # @param is_active [Boolean]
132
- def account_update(email:, first_name:, last_name:, group_id:, institution_user_id: nil, symplectic_user_id: nil, quota: nil, is_active: true, &block)
239
+ def account_update( account_id:,
240
+ email: nil,
241
+ first_name: nil,
242
+ last_name: nil,
243
+ group_id: nil,
244
+ institution_user_id: nil,
245
+ symplectic_user_id: nil,
246
+ quota: nil,
247
+ is_active: true,
248
+ &block
249
+ )
133
250
  args = {}
134
251
  args['email'] = email unless email.nil?
135
252
  args['first_name'] = first_name unless first_name.nil?
@@ -142,7 +259,7 @@ module Figshare
142
259
  put(api_query: "account/institution/accounts/#{account_id}", args: args, &block)
143
260
  end
144
261
 
145
- # Get institution Account Group Roles
262
+ # Get institution Account Group Roles for an account
146
263
  #
147
264
  # @param account_id [Integer] Figshare user account id
148
265
  # @yield [Hash] { role_id [ { category, id, name }, ... ], ... }
@@ -153,7 +270,7 @@ module Figshare
153
270
  # Add Institution Account Group Roles
154
271
  #
155
272
  # @param account_id [Integer] Figshare user account id
156
- # @param body [Hash] see figshare api docs
273
+ # @param body [Hash] see figshare api cryptic docs { "2": [ 2, 7], "3": [7,9] }. Array of roles, per group
157
274
  def group_roles_add(account_id:, body:, &block)
158
275
  post(api_query: "account/institution/roles/#{account_id}", args: body, &block)
159
276
  end
@@ -163,12 +280,9 @@ module Figshare
163
280
  # @param account_id [Integer] Figshare user account id
164
281
  # @param role_id [Integer] Figshare role id
165
282
  # @param group_id [Integer] Figshare group id
166
- def group_role_delete( role_id, group_id, account_id:, &block)
283
+ def group_role_delete( account_id:, role_id:, group_id:, &block)
167
284
  args = {}
168
- args['account_id'] = account_id unless account_id.nil?
169
- args['role_id'] = role_id unless role_id.nil?
170
- args['group_id'] = group_id unless group_id.nil?
171
- delete(api_query: 'account/institution/roles/{account_id}', args: args, &block)
285
+ delete(api_query: "account/institution/roles/#{account_id}/#{group_id}/#{role_id}", args: args, &block)
172
286
  end
173
287
 
174
288
  # Get the accounts for which the account has administrative privileges (assigned and inherited).
@@ -176,14 +290,31 @@ module Figshare
176
290
  # @param is_active [Boolean] user account is active
177
291
  # @param institution_user_id [String] As set in the HR upload
178
292
  # @param email [String] as set in the HR upload
179
- # @yield [Hash] {id, first_name, last_name, institution_id, email, active, institution_user_id}
180
- def account_search(search_for: nil, is_active: nil, institution_user_id: nil, email: nil, &block)
293
+ # @param page [Numeric] Pages start at 1. Page and Page size go together
294
+ # @param page_size [Numeric]
295
+ # @param offset [Numeric] offset is 0 based. Offset and Limit go together
296
+ # @param limit [Numeric]
297
+ # @yield [Hash] {id, first_name, last_name, institution_id, email, active, institution_user_id, quota, used_quota, user_id, orcid_id}
298
+ def account_search( search_for: nil,
299
+ is_active: nil,
300
+ institution_user_id: nil,
301
+ email: nil,
302
+ page: nil,
303
+ page_size: nil,
304
+ offset: nil,
305
+ limit: nil,
306
+ &block
307
+ )
181
308
  args = {}
182
309
  args['search_for'] = search_for unless search_for.nil?
183
310
  args['is_active'] = is_active unless is_active.nil?
184
311
  args['institution_user_id'] = institution_user_id unless institution_user_id.nil?
185
312
  args['email'] = email unless email.nil?
186
- post(api_query: 'account/institution/accounts/search', args: args, &block)
313
+ args['page'] = page unless page.nil?
314
+ args['page_size'] = page_size unless page_size.nil?
315
+ args['offset'] = offset unless offset.nil?
316
+ args['limit'] = limit unless limit.nil?
317
+ post_paginate(api_query: 'account/institution/accounts/search', args: args, &block)
187
318
  end
188
319
 
189
320
  # Get institution user information using the account_id
@@ -198,13 +329,23 @@ module Figshare
198
329
  #
199
330
  # @param group_id [Integer] Figshare group ID
200
331
  # @param article_id [Integer] Figshare article ID
201
- # @param status [String] pending, approved, rejected, closed
332
+ # @param status [String] One of: pending, approved, rejected, closed
333
+ # @param offset [Numeric] offset is 0 based. Offset and Limit go together
334
+ # @param limit [Numeric]
202
335
  # @yield [Hash] {id, group_id, account_id, assigned_to, article_id, version, comment_count, status, created_date. modified_date }
203
- def curation_review(group_id: nil, article_id: nil, status: nil, &block)
336
+ def curation_review( group_id: nil,
337
+ article_id: nil,
338
+ status: nil,
339
+ offset: nil,
340
+ limit: nil,
341
+ &block
342
+ )
204
343
  args = {}
205
344
  args['group_id'] = group_id unless group_id.nil?
206
345
  args['article_id'] = article_id unless article_id.nil?
207
346
  args['status'] = status unless status.nil?
347
+ args['offset'] = offset unless offset.nil?
348
+ args['limit'] = limit unless limit.nil?
208
349
  # Odd one, as has offset,limit not page,page_size
209
350
  get_paginate(api_query: 'account/institution/reviews', args: args, by_offset: true, &block)
210
351
  end
@@ -220,10 +361,15 @@ module Figshare
220
361
  # Get a certain curation review's comments.
221
362
  #
222
363
  # @param curation_id [Integer] Figshare curation ID
364
+ # @param offset [Numeric] offset is 0 based. Offset and Limit go together
365
+ # @param limit [Numeric]
223
366
  # @yield [Hash] { id, account_id, type, text}
224
- def curation_review_comments(curation_id:, &block)
367
+ def curation_review_comments(curation_id:, offset: nil, limit: nil, &block)
225
368
  # Odd one, as has offset,limit not page,page_size.
226
- get_paginate(api_query: "account/institution/reviews/#{curation_id}/comments", by_offset: true, &block)
369
+ args = {}
370
+ args['offset'] = offset unless offset.nil?
371
+ args['limit'] = limit unless limit.nil?
372
+ get_paginate(api_query: "account/institution/review/#{curation_id}/comments", args: args, by_offset: true, &block)
227
373
  end
228
374
 
229
375
  # Add a new comment to the review.
@@ -231,8 +377,7 @@ module Figshare
231
377
  # @param curation_id [Integer] Figshare curation ID
232
378
  # @param comment [String] Comment text
233
379
  def curation_review_comments_update(curation_id:, comment:, &block)
234
- # Odd one, as has offset,limit not page,page_size.
235
- post(api_query: "account/institution/reviews/#{curation_id}/comments", args: { 'text' => comment }, &block)
380
+ post(api_query: "account/institution/review/#{curation_id}/comments", args: { 'text' => comment }, &block)
236
381
  end
237
382
  end
238
383
  end
data/lib/other.rb CHANGED
@@ -2,10 +2,18 @@ module Figshare
2
2
  # Misc Figshare API calls that they have classified as Other.
3
3
  #
4
4
  class Other < Base
5
+ # Fetch item types
6
+ #
7
+ # @param group_id [Integer]
8
+ # @yield [Array] [{id: 0, name:, string_id:, icon:, public_description:, is_selectable: , url_name: } ]
9
+ def item_types(group_id:, &block)
10
+ get(api_query: 'item_types', args: { 'group_id' => group_id }, &block)
11
+ end
12
+
5
13
  # Search from funding records
6
14
  #
7
15
  # @param search_for [String] string to search for
8
- # @yield [Hash] {id, title, grant_code, funder_name, is_user_defined, url}
16
+ # @yield [Array] [{id, title, grant_code, funder_name, is_user_defined, url}]
9
17
  def search_funding(search_for:, &block)
10
18
  post(api_query: 'account/funding/search', args: { 'search_for' => search_for }, &block)
11
19
  end
@@ -21,21 +29,21 @@ module Figshare
21
29
 
22
30
  # Get public categories
23
31
  #
24
- # @yield [Hash] {parent_id, id, title}
32
+ # @yield [Array] [{parent_id:, id:, title:, path:, source_id:, taxonomy_id:}]
25
33
  def public_categories
26
34
  get(api_query: 'categories', &block)
27
35
  end
28
36
 
29
37
  # Get public licenses
30
38
  #
31
- # @yield [Hash] {value, name, url}
39
+ # @yield [Array] [{value:, name:, url:}]
32
40
  def public_licenses
33
41
  get(api_query: 'licenses', &block)
34
42
  end
35
43
 
36
44
  # Get private licenses
37
45
  #
38
- # @yield [Hash] {value, name, url}
46
+ # @yield [Array] [{value:, name:, url:}]
39
47
  def private_account_licenses
40
48
  get(api_query: 'account/licenses', &block)
41
49
  end