figshare_api_v2 0.9.6 → 0.9.9

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,10 +4,14 @@ 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
17
  # Get the institional account details
@@ -17,6 +21,13 @@ module Figshare
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,26 +81,57 @@ 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
@@ -87,12 +141,34 @@ module Figshare
87
141
  # @param is_active [Boolean] user account is active
88
142
  # @param institution_user_id [String] As set in the HR upload
89
143
  # @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)
144
+ # @param id_lte [Integer] ID is <=
145
+ # @param id_gte [Integer] ID is >=
146
+ # @param page [Numeric] Pages start at 1. Page and Page size go together
147
+ # @param page_size [Numeric]
148
+ # @param offset [Numeric] offset is 0 based. Offset and Limit go together
149
+ # @param limit [Numeric]
150
+ # @yield [Array] [{ id:, first_name:, last_name:, institution_id:, email:, active:, institution_user_id:, quota:, used_quota:, user_id:, orcid_id: }]
151
+ def accounts( is_active: nil,
152
+ institution_user_id: nil,
153
+ email: nil,
154
+ id_lte: nil,
155
+ id_gte: nil,
156
+ page: nil,
157
+ page_size: nil,
158
+ offset: nil,
159
+ limit: nil,
160
+ &block
161
+ )
92
162
  args = {}
93
163
  args['is_active'] = is_active unless is_active.nil?
94
164
  args['institution_user_id'] = institution_user_id unless institution_user_id.nil?
95
165
  args['email'] = email unless email.nil?
166
+ args['id_lte'] = id_lte unless id_lte.nil?
167
+ args['id_gte'] = id_gte unless id_gte.nil?
168
+ args['page'] = page unless page.nil?
169
+ args['page_size'] = page_size unless page_size.nil?
170
+ args['offset'] = offset unless offset.nil?
171
+ args['limit'] = limit unless limit.nil?
96
172
  get_paginate(api_query: 'account/institution/accounts', args: args, &block)
97
173
  end
98
174
 
@@ -106,7 +182,16 @@ module Figshare
106
182
  # @param symplectic_user_id [string]
107
183
  # @param quota [Integer] Figshare user quota
108
184
  # @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)
185
+ def account_create( email:,
186
+ first_name:,
187
+ last_name:,
188
+ group_id:,
189
+ institution_user_id: nil,
190
+ symplectic_user_id: nil,
191
+ quota: nil,
192
+ is_active: true,
193
+ &block
194
+ )
110
195
  args = {}
111
196
  args['email'] = email unless email.nil?
112
197
  args['first_name'] = first_name unless first_name.nil?
@@ -116,11 +201,12 @@ module Figshare
116
201
  args['symplectic_user_id'] = symplectic_user_id unless symplectic_user_id.nil?
117
202
  args['quota'] = quota unless quota.nil?
118
203
  args['is_active'] = is_active unless is_active.nil?
119
- post(api_query: "account/institution/accounts/#{account_id}", args: args, &block)
204
+ post(api_query: 'account/institution/accounts', args: args, &block)
120
205
  end
121
206
 
122
207
  # Update Institution Account
123
208
  #
209
+ # @param account_id [Integer] Whose account
124
210
  # @param email [String]
125
211
  # @param first_name [String]
126
212
  # @param last_name [String]
@@ -129,7 +215,17 @@ module Figshare
129
215
  # @param symplectic_user_id [string]
130
216
  # @param quota [Integer] Figshare user quota
131
217
  # @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)
218
+ def account_update( account_id:,
219
+ email: nil,
220
+ first_name: nil,
221
+ last_name: nil,
222
+ group_id: nil,
223
+ institution_user_id: nil,
224
+ symplectic_user_id: nil,
225
+ quota: nil,
226
+ is_active: true,
227
+ &block
228
+ )
133
229
  args = {}
134
230
  args['email'] = email unless email.nil?
135
231
  args['first_name'] = first_name unless first_name.nil?
@@ -142,7 +238,7 @@ module Figshare
142
238
  put(api_query: "account/institution/accounts/#{account_id}", args: args, &block)
143
239
  end
144
240
 
145
- # Get institution Account Group Roles
241
+ # Get institution Account Group Roles for an account
146
242
  #
147
243
  # @param account_id [Integer] Figshare user account id
148
244
  # @yield [Hash] { role_id [ { category, id, name }, ... ], ... }
@@ -153,7 +249,7 @@ module Figshare
153
249
  # Add Institution Account Group Roles
154
250
  #
155
251
  # @param account_id [Integer] Figshare user account id
156
- # @param body [Hash] see figshare api docs
252
+ # @param body [Hash] see figshare api cryptic docs { "2": [ 2, 7], "3": [7,9] }. Array of roles, per group
157
253
  def group_roles_add(account_id:, body:, &block)
158
254
  post(api_query: "account/institution/roles/#{account_id}", args: body, &block)
159
255
  end
@@ -163,12 +259,9 @@ module Figshare
163
259
  # @param account_id [Integer] Figshare user account id
164
260
  # @param role_id [Integer] Figshare role id
165
261
  # @param group_id [Integer] Figshare group id
166
- def group_role_delete( role_id, group_id, account_id:, &block)
262
+ def group_role_delete( account_id:, role_id:, group_id:, &block)
167
263
  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)
264
+ delete(api_query: "account/institution/roles/#{account_id}/#{group_id}/#{role_id}", args: args, &block)
172
265
  end
173
266
 
174
267
  # Get the accounts for which the account has administrative privileges (assigned and inherited).
@@ -176,14 +269,31 @@ module Figshare
176
269
  # @param is_active [Boolean] user account is active
177
270
  # @param institution_user_id [String] As set in the HR upload
178
271
  # @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)
272
+ # @param page [Numeric] Pages start at 1. Page and Page size go together
273
+ # @param page_size [Numeric]
274
+ # @param offset [Numeric] offset is 0 based. Offset and Limit go together
275
+ # @param limit [Numeric]
276
+ # @yield [Hash] {id, first_name, last_name, institution_id, email, active, institution_user_id, quota, used_quota, user_id, orcid_id}
277
+ def account_search( search_for: nil,
278
+ is_active: nil,
279
+ institution_user_id: nil,
280
+ email: nil,
281
+ page: nil,
282
+ page_size: nil,
283
+ offset: nil,
284
+ limit: nil,
285
+ &block
286
+ )
181
287
  args = {}
182
288
  args['search_for'] = search_for unless search_for.nil?
183
289
  args['is_active'] = is_active unless is_active.nil?
184
290
  args['institution_user_id'] = institution_user_id unless institution_user_id.nil?
185
291
  args['email'] = email unless email.nil?
186
- post(api_query: 'account/institution/accounts/search', args: args, &block)
292
+ args['page'] = page unless page.nil?
293
+ args['page_size'] = page_size unless page_size.nil?
294
+ args['offset'] = offset unless offset.nil?
295
+ args['limit'] = limit unless limit.nil?
296
+ post_paginate(api_query: 'account/institution/accounts/search', args: args, &block)
187
297
  end
188
298
 
189
299
  # Get institution user information using the account_id
@@ -198,13 +308,23 @@ module Figshare
198
308
  #
199
309
  # @param group_id [Integer] Figshare group ID
200
310
  # @param article_id [Integer] Figshare article ID
201
- # @param status [String] pending, approved, rejected, closed
311
+ # @param status [String] One of: pending, approved, rejected, closed
312
+ # @param offset [Numeric] offset is 0 based. Offset and Limit go together
313
+ # @param limit [Numeric]
202
314
  # @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)
315
+ def curation_review( group_id: nil,
316
+ article_id: nil,
317
+ status: nil,
318
+ offset: nil,
319
+ limit: nil,
320
+ &block
321
+ )
204
322
  args = {}
205
323
  args['group_id'] = group_id unless group_id.nil?
206
324
  args['article_id'] = article_id unless article_id.nil?
207
325
  args['status'] = status unless status.nil?
326
+ args['offset'] = offset unless offset.nil?
327
+ args['limit'] = limit unless limit.nil?
208
328
  # Odd one, as has offset,limit not page,page_size
209
329
  get_paginate(api_query: 'account/institution/reviews', args: args, by_offset: true, &block)
210
330
  end
@@ -220,10 +340,15 @@ module Figshare
220
340
  # Get a certain curation review's comments.
221
341
  #
222
342
  # @param curation_id [Integer] Figshare curation ID
343
+ # @param offset [Numeric] offset is 0 based. Offset and Limit go together
344
+ # @param limit [Numeric]
223
345
  # @yield [Hash] { id, account_id, type, text}
224
- def curation_review_comments(curation_id:, &block)
346
+ def curation_review_comments(curation_id:, offset: nil, limit: nil, &block)
225
347
  # 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)
348
+ args = {}
349
+ args['offset'] = offset unless offset.nil?
350
+ args['limit'] = limit unless limit.nil?
351
+ get_paginate(api_query: "account/institution/review/#{curation_id}/comments", args: args, by_offset: true, &block)
227
352
  end
228
353
 
229
354
  # Add a new comment to the review.
@@ -231,8 +356,7 @@ module Figshare
231
356
  # @param curation_id [Integer] Figshare curation ID
232
357
  # @param comment [String] Comment text
233
358
  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)
359
+ post(api_query: "account/institution/review/#{curation_id}/comments", args: { 'text' => comment }, &block)
236
360
  end
237
361
  end
238
362
  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