figshare_api_v2 0.9.1

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.
@@ -0,0 +1,121 @@
1
+ module Figshare
2
+ VERSION = '0.9.1'
3
+
4
+ require_relative 'base.rb'
5
+ require_relative 'authors.rb'
6
+ require_relative 'institutions.rb'
7
+ require_relative 'other.rb'
8
+ require_relative 'private_articles.rb'
9
+ require_relative 'private_collections.rb'
10
+ require_relative 'private_projects.rb'
11
+ require_relative 'public_articles.rb'
12
+ require_relative 'public_collections.rb'
13
+ require_relative 'public_projects.rb'
14
+ require_relative 'upload.rb'
15
+ require_relative 'stats.rb'
16
+ require_relative 'oai_pmh.rb'
17
+
18
+ # Hack :) to do a lazy initialization of the Figshare subclasses. i.e. only if they get called.
19
+ # Usage:
20
+ # @figshare = Figshare::Init.new(figshare_user: 'figshare_admin', conf_dir: "#{__dir__}/conf")
21
+ #
22
+ # @figshare.authors.detail(author_id: 12345) { |a| puts a }
23
+ # @figshare.institutions.private_articles { |article| puts article }
24
+ # ...
25
+ #
26
+ class Init
27
+ # Intitialize the Init class, so it can dynamically initialize the Figshare subclasses
28
+ #
29
+ # @param figshare_user [String] figshare user, in the figshare_keys.json
30
+ # @param conf_dir [String] directory for figshare_keys.json and figshare_site_params.json
31
+ def initialize(figshare_user:, conf_dir:)
32
+ @figshare_user = figshare_user
33
+ @conf_dir = conf_dir
34
+ end
35
+
36
+ # Create Figshare::Authors, if it doesn't exist. Initialized with @figshare_user and @conf_dir
37
+ #
38
+ # @return [Figshare::Authors]
39
+ def authors
40
+ @authors ||= Authors.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
41
+ end
42
+
43
+ # Create Figshare::Institutions, if it doesn't exist. Initialized with @figshare_user and @conf_dir
44
+ #
45
+ # @return [Figshare::Institutions]
46
+ def institutions
47
+ @institutions ||= Institutions.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
48
+ end
49
+
50
+ # Create Figshare::Other, if it doesn't exist. Initialized with @figshare_user and @conf_dir
51
+ #
52
+ # @return [Figshare::Other]
53
+ def other
54
+ @other ||= Other.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
55
+ end
56
+
57
+ # Create Figshare::PrivateArticles, if it doesn't exist. Initialized with @figshare_user and @conf_dir
58
+ #
59
+ # @return [Figshare::PrivateArticles]
60
+ def private_articles
61
+ @private_articles ||= PrivateArticles.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
62
+ end
63
+
64
+ # Create Figshare::PrivateCollections, if it doesn't exist. Initialized with @figshare_user and @conf_dir
65
+ #
66
+ # @return [Figshare::PrivateCollections]
67
+ def private_collections
68
+ @private_collections ||= PrivateCollections.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
69
+ end
70
+
71
+ # Create Figshare::PrivateProjects, if it doesn't exist. Initialized with @figshare_user and @conf_dir
72
+ #
73
+ # @return [Figshare::PrivateProjects]
74
+ def private_projects
75
+ @private_projects ||= PrivateProjects.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
76
+ end
77
+
78
+ # Create Figshare::PublicArticles, if it doesn't exist. Initialized with @figshare_user and @conf_dir
79
+ #
80
+ # @return [Figshare::PublicArticles]
81
+ def public_articles
82
+ @public_articles ||= PublicArticles.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
83
+ end
84
+
85
+ # Create Figshare::PublicCollections, if it doesn't exist. Initialized with @figshare_user and @conf_dir
86
+ #
87
+ # @return [Figshare::PublicCollections]
88
+ def public_collections
89
+ @public_collections ||= PublicCollections.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
90
+ end
91
+
92
+ # Create Figshare::PublicProjects, if it doesn't exist. Initialized with @figshare_user and @conf_dir
93
+ #
94
+ # @return [Figshare::PublicProjects]
95
+ def public_projects
96
+ @public_projects ||= PublicProjects.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
97
+ end
98
+
99
+ # Create Figshare::Upload, if it doesn't exist. Initialized with @figshare_user and @conf_dir
100
+ #
101
+ # @return [Figshare::Upload]
102
+ def upload
103
+ @upload ||= Upload.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
104
+ end
105
+
106
+ # Create Figshare::Stats, if it doesn't exist. Initialized with @figshare_user and @conf_dir
107
+ #
108
+ # @return [Figshare::Stats]
109
+ def stats
110
+ @stats ||= Stats.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
111
+ end
112
+
113
+ # Create Figshare::OAI_PMH, if it doesn't exist. Initialized with @figshare_user and @conf_dir
114
+ #
115
+ # @return [Figshare::OAI_PMH]
116
+ def oai_pmh
117
+ @oai_pmh ||= OAI_PMH.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
118
+ end
119
+
120
+ end
121
+ end # module
@@ -0,0 +1,238 @@
1
+ module Figshare
2
+
3
+ # Figshare Institutions API
4
+ #
5
+ class Institutions < Base
6
+
7
+ # Upload hr file
8
+ #
9
+ # @param hr_xml [String] See https://docs.figshare.com/#hr_feed_hr_feed_private_endpoint
10
+ # @yield [Hash] { message:, data: null, errcode:}
11
+ def hr_upload(hr_xml:, &block)
12
+ put(api_query: "institution/hrfeed/upload", data: hr_xml, content_type: 'multipart/form-data' &block)
13
+ end
14
+
15
+ # Get the institional account details
16
+ #
17
+ # @yield [Hash]
18
+ def account(&block)
19
+ get(api_query: "account/institution", &block)
20
+ end
21
+
22
+ # Requests a list of private institute articles
23
+ #
24
+ # @param status [Integer] Only return items with this status
25
+ # @param published_since [Time] Return results if published after this time
26
+ # @param modified_since [Time] Return results if modified after this time
27
+ # @param resource_doi [String] Matches this resource doi
28
+ # @param item_type [String] Matches this item_type. See Figshare API docs for list (https://docs.figshare.com/#articles_list)
29
+ # @param order [String] "published_date" Default, "modified_date", "views", "cites", "shares"
30
+ # @param order_direction [String] "desc" Default, "asc"
31
+ # @yield [Hash] {id, title, doi, handle, group_id, url, url_public_html, url_public_api, url_private_htm,
32
+ # url_private_api, published_date, timeline {...}, thumb, defined_type, defined_name }
33
+ def private_articles(status: nil,
34
+ published_since: nil, modified_since: nil,
35
+ item_type: nil, resource_doi: nil,
36
+ order: 'published_date', order_direction: 'desc',
37
+ &block
38
+ )
39
+ args = {}
40
+ args['status'] = status if ! status.nil?
41
+ args['item_type'] = item_type if ! item_type.nil?
42
+ args['resource_doi'] = resource_doi if ! resource_doi.nil?
43
+ args['published_since'] = published_since if ! published_since.nil?
44
+ args['modified_since'] = modified_since if ! modified_since.nil?
45
+ args['order'] = order if ! order.nil?
46
+ args['order_direction'] = order_direction if ! order_direction.nil?
47
+ get_paginate(api_query: 'account/institution/articles', args: args, &block)
48
+ end
49
+
50
+ # Requests an institute file
51
+ #
52
+ # @param resource_id [Integer] Figshare resource_id (publisher ID?)
53
+ # @param filename [String] Figshare file name
54
+ # @yield [Hash] {id, title, doi, handle, group_id, url, url_public_html, url_public_api, url_private_htm,
55
+ # url_private_api, published_date, timeline {...}, thumb, defined_type, defined_name }
56
+ def articles_filter_by(resource_id: nil, filename: nil, &block )
57
+ args = {}
58
+ args['resource_id'] = resource_id if ! resource_id.nil?
59
+ args['filename'] = filename if ! filename.nil?
60
+ get(api_query: "institutions/{@institute_id}/articles/filter-by", args: args, &block)
61
+ end
62
+
63
+ # Get institution categories (including parent Categories)
64
+ #
65
+ # @yield [Hash] { parent_id, id, title }
66
+ def categories(&block)
67
+ get(api_query: "account/categories", &block)
68
+ end
69
+
70
+ # Get the groups for which the account has administrative privileges (assigned and inherited).
71
+ #
72
+ # @yield [Hash] { id, name, resource_id, parent_id, association_criteria }
73
+ def groups(&block)
74
+ get(api_query: "account/groups", &block)
75
+ end
76
+
77
+ # Get the roles available for groups and the institution group.
78
+ #
79
+ # @yield [Hash] { id, name, category, description }
80
+ def roles(&block)
81
+ get(api_query: "account/roles", &block)
82
+ end
83
+
84
+ # Get the accounts for which the account has administrative privileges (assigned and inherited).
85
+ #
86
+ # @param is_active [Boolean] user account is active
87
+ # @param institution_user_id [String] As set in the HR upload
88
+ # @param email [String] as set in the HR upload
89
+ # @yield [Hash] { id, first_name, last_name, institution_id, email, active, institution_user_id }
90
+ def accounts(is_active: nil, institution_user_id: nil, email: nil, &block)
91
+ args = {}
92
+ args['is_active'] = is_active if ! is_active.nil?
93
+ args['institution_user_id'] = institution_user_id if ! institution_user_id.nil?
94
+ args['email'] = email if ! email.nil?
95
+ get_paginate(api_query: "account/institution/accounts", args: args, &block)
96
+ end
97
+
98
+ # Create new Institution Account
99
+ #
100
+ # @param email [String]
101
+ # @param first_name [String]
102
+ # @param last_name [String]
103
+ # @param group_id [Integer] Figshare group ID
104
+ # @param institution_user_id [string]
105
+ # @param symplectic_user_id [string]
106
+ # @param quota [Integer] Figshare user quota
107
+ # @param is_active [Boolean]
108
+ def account_create(email:, first_name:, last_name:, group_id:, institution_user_id: nil, symplectic_user_id: nil, quota: nil, is_active: true, &block)
109
+ args = {}
110
+ args['email'] = email if ! email.nil?
111
+ args['first_name'] = first_name if ! first_name.nil?
112
+ args['last_name'] = last_name if ! last_name.nil?
113
+ args['group_id'] = group_id if ! group_id.nil?
114
+ args['institution_user_id'] = institution_user_id if ! institution_user_id.nil?
115
+ args['symplectic_user_id'] = symplectic_user_id if ! symplectic_user_id.nil?
116
+ args['quota'] = quota if ! quota.nil?
117
+ args['is_active'] = is_active if ! is_active.nil?
118
+ post(api_query: "account/institution/accounts/#{account_id}", args: args, &block)
119
+ end
120
+
121
+ # Update Institution Account
122
+ #
123
+ # @param email [String]
124
+ # @param first_name [String]
125
+ # @param last_name [String]
126
+ # @param group_id [Integer] Figshare group ID
127
+ # @param institution_user_id [string]
128
+ # @param symplectic_user_id [string]
129
+ # @param quota [Integer] Figshare user quota
130
+ # @param is_active [Boolean]
131
+ def account_update(email:, first_name:, last_name:, group_id:, institution_user_id: nil, symplectic_user_id: nil, quota: nil, is_active: true, &block)
132
+ args = {}
133
+ args['email'] = email if ! email.nil?
134
+ args['first_name'] = first_name if ! first_name.nil?
135
+ args['last_name'] = last_name if ! last_name.nil?
136
+ args['group_id'] = group_id if ! group_id.nil?
137
+ args['institution_user_id'] = institution_user_id if ! institution_user_id.nil?
138
+ args['symplectic_user_id'] = symplectic_user_id if ! symplectic_user_id.nil?
139
+ args['quota'] = quota if ! quota.nil?
140
+ args['is_active'] = is_active if ! is_active.nil?
141
+ put(api_query: "account/institution/accounts/#{account_id}", args: args, &block)
142
+ end
143
+
144
+ # Get institution Account Group Roles
145
+ #
146
+ # @param account_id [Integer] Figshare user account id
147
+ # @yield [Hash] { role_id [ { category, id, name }, ... ], ... }
148
+ def group_roles(account_id:, &block)
149
+ get(api_query: "account/institution/roles/{account_id}", &block)
150
+ end
151
+
152
+ # Add Institution Account Group Roles
153
+ #
154
+ # @param account_id [Integer] Figshare user account id
155
+ # @param body [Hash] see figshare api docs
156
+ def group_roles_add(account_id:, body:, &block)
157
+ post(api_query: "account/institution/roles/{account_id}", args: body, &block)
158
+ end
159
+
160
+ # Delete Institution Account Group Role
161
+ #
162
+ # @param account_id [Integer] Figshare user account id
163
+ # @param role_id [Integer] Figshare role id
164
+ # @param group_id [Integer] Figshare group id
165
+ def group_role_delete( role_id, group_id, account_id:, &block)
166
+ args = {}
167
+ args['account_id'] = account_id if ! account_id.nil?
168
+ args['role_id'] = role_id if ! role_id.nil?
169
+ args['group_id'] = group_id if ! group_id.nil?
170
+ delete(api_query: "account/institution/roles/{account_id}", args: args, &block)
171
+ end
172
+
173
+ # Get the accounts for which the account has administrative privileges (assigned and inherited).
174
+ #
175
+ # @param is_active [Boolean] user account is active
176
+ # @param institution_user_id [String] As set in the HR upload
177
+ # @param email [String] as set in the HR upload
178
+ # @yield [Hash] {id, first_name, last_name, institution_id, email, active, institution_user_id}
179
+ def account_search(search_for:, is_active: nil, institution_user_id: nil, email: nil, &block)
180
+ args = {}
181
+ args['search_for'] = search_for
182
+ args['is_active'] = is_active if ! is_active.nil?
183
+ args['institution_user_id'] = institution_user_id if ! institution_user_id.nil?
184
+ args['email'] = email if ! email.nil?
185
+ post(api_query: "account/institution/accounts/search", args: args, &block)
186
+ end
187
+
188
+ # Get institution user information using the account_id
189
+ #
190
+ # @param account_id [Integer] Figshare user account id
191
+ # @yield [Hash] { id, first_name, last_name, name, is_active, url_name, is_public, job_title, orcid_id }
192
+ def user(account_id:, &block)
193
+ get(api_query: "account/institution/users/#{account_id}", &block)
194
+ end
195
+
196
+ # Get a list of curation reviews for this institution
197
+ #
198
+ # @param group_id [Integer] Figshare group ID
199
+ # @param article_id [Integer] Figshare article ID
200
+ # @param status [String] pending, approved, rejected, closed
201
+ # @yield [Hash] {id, group_id, account_id, assigned_to, article_id, version, comment_count, status, created_date. modified_date }
202
+ def curation_review(group_id: nil, article_id: nil, status: nil, &block)
203
+ args = {}
204
+ args['group_id'] = group_id if ! group_id.nil?
205
+ args['article_id'] = article_id if ! article_id.nil?
206
+ args['status'] = status if ! status.nil?
207
+ #Odd one, as has offset,limit not page,page_size
208
+ get_paginate(api_query: "account/institution/reviews", args: args, by_offset: true, &block)
209
+ end
210
+
211
+ # Get a curation review record
212
+ #
213
+ # @param curation_id [Integer] Figshare curation ID
214
+ # @yield [Hash] see Figshare API docs for response sample
215
+ def curation_detail(curation_id: , &block)
216
+ get(api_query: "account/institution/review/#{curation_id}", &block)
217
+ end
218
+
219
+ # Get a certain curation review's comments.
220
+ #
221
+ # @param curation_id [Integer] Figshare curation ID
222
+ # @yield [Hash] { id, account_id, type, text}
223
+ def curation_comments(curation_id: , &block)
224
+ #Odd one, as has offset,limit not page,page_size.
225
+ get_paginate(api_query: "account/institution/reviews/#{curation_id}/comments", by_offset: true, &block)
226
+ end
227
+
228
+ # Add a new comment to the review.
229
+ #
230
+ # @param curation_id [Integer] Figshare curation ID
231
+ # @param comment [String] Comment text
232
+ def curation_comments(curation_id: , &block)
233
+ #Odd one, as has offset,limit not page,page_size.
234
+ post(api_query: "account/institution/reviews/#{curation_id}/comments", args: { "text" => comment }, &block)
235
+ end
236
+
237
+ end #of class
238
+ end #of module
@@ -0,0 +1,6 @@
1
+ module Figshare
2
+ # OAI PMH API (not implemented yet)
3
+ #
4
+ class OAI_PMH
5
+ end #class
6
+ end # module
@@ -0,0 +1,51 @@
1
+ module Figshare
2
+
3
+ # Misc Figshare API calls that they have classified as Other.
4
+ #
5
+ class Other < Base
6
+
7
+ # Search from funding records
8
+ #
9
+ # @param search_for [String] string to search for
10
+ # @yield [Hash] {id, title, grant_code, funder_name, is_user_defined, url}
11
+ def search_funding(search_for:, &block)
12
+ post(api_query: "account/funding/search", args: { "search_for" => search_for }, &block)
13
+ end
14
+
15
+ # Get Account information for current user
16
+ #
17
+ # @yield [Hash] {id, first_name, ...} see figshare API docs
18
+ def private_account_info
19
+ get(api_query: "account", &block)
20
+ end
21
+
22
+ # Get public categories
23
+ #
24
+ # @yield [Hash] {parent_id, id, title}
25
+ def public_categories
26
+ get(api_query: "categories", &block)
27
+ end
28
+
29
+ # Get public licenses
30
+ #
31
+ # @yield [Hash] {value, name, url}
32
+ def public_licenses
33
+ get(api_query: "licenses", &block)
34
+ end
35
+
36
+ # Get private licenses
37
+ #
38
+ # @yield [Hash] {value, name, url}
39
+ def private_account_licenses
40
+ get(api_query: "account/licenses", &block)
41
+ end
42
+
43
+ # Download a file
44
+ #
45
+ # @param file_id [Integer] Figshare file id
46
+ # @yield [Data] Binary data
47
+ def public_file_download(file_id:, &block)
48
+ get(api_query: "file/download/#{file_id}", &block)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,354 @@
1
+ module Figshare
2
+
3
+ # Figshare private articles API
4
+ #
5
+ class PrivateArticles < Base
6
+
7
+ # Get Own Articles (or private articles of others if institute is true)
8
+ #
9
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
10
+ # @yield [Hash] {id, title, doi, handle, url, published_date}
11
+ def list(impersonate: nil, &block)
12
+ args = {}
13
+ args["impersonate"] = impersonate if ! impersonate.nil?
14
+ get_paginate(api_query: 'account/articles', args: args, &block)
15
+ end
16
+
17
+ # Search within the private articles (our own, or the institutes)
18
+ #
19
+ # @param institution [Boolean] Just our institution
20
+ # @param group_id [Integer] Only return this group's collections
21
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
22
+ # @param published_since [Time] Return results if published after this time
23
+ # @param modified_since [Time] Return results if modified after this time
24
+ # @param resource_doi [String] Matches this resource doi
25
+ # @param item_type [String] Matches this item_type. See Figshare API docs for list (https://docs.figshare.com/#articles_list)
26
+ # @param doi [String] Matches this doi
27
+ # @param handle [String] Matches this handle
28
+ # @param order [String] "published_date" Default, "modified_date", "views", "cites", "shares"
29
+ # @param order_direction [String] "desc" Default, "asc"
30
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
31
+ # @yield [Hash] {id, title, doi, handle, url, published_date}
32
+ def search(institute: false, group_id: nil, impersonate: nil,
33
+ published_since: nil, modified_since: nil,
34
+ item_type: nil, resource_doi: nil, doi: nil, handle: nil,
35
+ order: 'published_date', order_direction: 'desc',
36
+ search_for:,
37
+ &block
38
+ )
39
+ args = { 'search_for' => search_for }
40
+ args["impersonate"] = impersonate if ! impersonate.nil?
41
+ args['institution'] = @institute_id if ! institute.nil?
42
+ args['group_id'] = group_id if ! group_id.nil?
43
+ args['item_type'] = item_type if ! item_type.nil?
44
+ args['resource_doi'] = resource_doi if ! resource_doi.nil?
45
+ args['doi'] = doi if ! doi.nil?
46
+ args['handle'] = handle if ! handle.nil?
47
+ args['published_since'] = published_since if ! published_since.nil?
48
+ args['modified_since'] = modified_since if ! modified_since.nil?
49
+ args['order'] = order if ! order.nil?
50
+ args['order_direction'] = order_direction if ! order_direction.nil?
51
+ post(api_query: 'account/articles/search', args: args, &block)
52
+ end
53
+
54
+ # Create a new Article by sending article information
55
+ #
56
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
57
+ # @yield [Hash] { location }
58
+ def create(impersonate: nil, &block)
59
+ args = {}
60
+ args["impersonate"] = impersonate if ! impersonate.nil?
61
+ post(api_query: "account/articles/#{article_id}", args: args, &block)
62
+ end
63
+
64
+ # Delete an article (WARNING!!!!!)
65
+ #
66
+ # @param article_id [Integer] Figshare id of the article
67
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
68
+ def article_delete(article_id:, impersonate: nil, &block)
69
+ args = {}
70
+ args["impersonate"] = impersonate if ! impersonate.nil?
71
+ delete(api_query: "account/articles/#{article_id}", args: args, &block)
72
+ end
73
+
74
+ # Get a private article's details
75
+ #
76
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
77
+ # @param article_id [Integer] Figshare id of the article
78
+ def detail(article_id:, impersonate: nil, &block)
79
+ args = {}
80
+ args["impersonate"] = impersonate if ! impersonate.nil?
81
+ get(api_query: "account/articles/#{article_id}", args: args, &block)
82
+ end
83
+
84
+ # Updating an article by passing body parameters
85
+ #
86
+ # @param article_id [Integer] Figshare id of the article
87
+ # @param body [Hash] See API docs.
88
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
89
+ def update(article_id:, body:, impersonate: nil, &block)
90
+ args = {}
91
+ args["impersonate"] = impersonate if ! impersonate.nil?
92
+ put(api_query: "account/articles/#{article_id}", args: args, data: body, &block)
93
+ end
94
+
95
+ # Will lift the embargo for the specified article
96
+ #
97
+ # @param article_id [Integer] Figshare id of the article
98
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
99
+ def embargo_delete(article_id:, impersonate: nil, &block)
100
+ args = {}
101
+ args["impersonate"] = impersonate if ! impersonate.nil?
102
+ delete(api_query: "account/articles/#{article_id}/embargo", args: args, &block)
103
+ end
104
+
105
+ # Get a private article embargo details
106
+ #
107
+ # @param article_id [Integer] Figshare id of the article
108
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
109
+ # @yield [Hash] {is_embargoed, embargo_date, embargo_reason}
110
+ def embargo_detail(article_id:, impersonate: nil, &block)
111
+ args = {}
112
+ args["impersonate"] = impersonate if ! impersonate.nil?
113
+ get(api_query: "account/articles/#{article_id}/embargo", args: args, &block)
114
+ end
115
+
116
+ # Updates an article embargo status.
117
+ # Does not imply that the article will be published when the embargo will expire.
118
+ # You must explicitly call the publish endpoint to enable this functionality.
119
+ #
120
+ # @param article_id [Integer] Figshare id of the article
121
+ # @param is_embargoed [Boolean]
122
+ # @param embargo_data [Time] Still needs to be published, after this date
123
+ # @param embargo_type [Integer]
124
+ # @param embargo_reason [String]
125
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
126
+ def embargo_update(article_id:, is_embargoed: true, embargo_date: , embargo_type: 'file', embargo_reason:, impersonate: nil, &block)
127
+ args = {}
128
+ args["impersonate"] = impersonate if ! impersonate.nil?
129
+ embargo_record = {"is_embargoed" => is_embargoed,
130
+ "embargo_date" => embargo_date.strftime("%Y-%m-%dT%H:%M:%S"),
131
+ "embargo_type" => embargo_type,
132
+ "embargo_reason" => embargo_reason
133
+ }
134
+ put(api_query: "account/articles/#{article_id}/embargo", args: args, data: embargo_record, &block)
135
+ end
136
+
137
+ # Publish an article
138
+ # If the whole article is under embargo, it will not be published immediately, but when the embargo expires or is lifted.
139
+ # When an article is published, a new public version will be generated.
140
+ # Any further updates to the article will affect the private article data.
141
+ # In order to make these changes publicly visible, an explicit publish operation is needed.
142
+ #
143
+ # @param article_id [Integer] Figshare id of the article
144
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
145
+ def publish(article_id:, impersonate: nil, &block)
146
+ args = {}
147
+ args["impersonate"] = impersonate if ! impersonate.nil?
148
+ post(api_query: "account/articles/#{article_id}/publish", args: args, &block)
149
+ end
150
+
151
+ # Reserve DOI for article
152
+ #
153
+ # @param article_id [Integer] Figshare id of the article
154
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
155
+ def reserve_doi(article_id:, impersonate: nil, &block)
156
+ args = {}
157
+ args["impersonate"] = impersonate if ! impersonate.nil?
158
+ post(api_query: "account/articles/#{article_id}/reserve_doi", args: args, &block)
159
+ end
160
+
161
+ # Reserve Handle for article
162
+ #
163
+ # @param article_id [Integer] Figshare id of the article
164
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
165
+ def reserve_handle(article_id:, impersonate: nil, &block)
166
+ args = {}
167
+ args["impersonate"] = impersonate if ! impersonate.nil?
168
+ post(api_query: "account/articles/#{article_id}/reserve_handle", args: args, &block)
169
+ end
170
+
171
+ # Yield articles authors
172
+ #
173
+ # @param article_id [Integer] Figshare id of the article
174
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
175
+ # @yield [Hash] {id, full_name, is_active, url_name, orcid_id}
176
+ def authors(article_id, impersonate: nil, &block)
177
+ args = {}
178
+ args["impersonate"] = impersonate if ! impersonate.nil?
179
+ get(api_query: "account/articles/#{article_id}/authors", args: args, &block)
180
+ end
181
+
182
+ # Associate new authors with the article. This will add new authors to the list of already associated authors
183
+ #
184
+ # @param article_id [Integer] Figshare id of the article
185
+ # @param authors [Array] Can be a mix of { id } and/or { name }
186
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
187
+ def authors_add(article_id:, authors:, impersonate: nil, &block)
188
+ args = {}
189
+ args["impersonate"] = impersonate if ! impersonate.nil?
190
+ post(api_query: "account/articles/#{article_id}/authors", args: args, data: {"authors" => authors}, &block)
191
+ end
192
+
193
+ # Replace existing authors list with a new list
194
+ #
195
+ # @param article_id [Integer] Figshare id of the article
196
+ # @param authors [Array] Can be a mix of { id } and/or { name }
197
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
198
+ def authors_replace(article_id:, authors:, impersonate: nil, &block)
199
+ args = {}
200
+ args["impersonate"] = impersonate if ! impersonate.nil?
201
+ put(api_query: "account/articles/#{article_id}/authors", args: args, data: {"authors" => authors}, &block)
202
+ end
203
+
204
+ # Remove author from the article
205
+ #
206
+ # @param article_id [Integer] Figshare id of the article
207
+ # @param author_id [Integer] Figshare id for the author
208
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
209
+ def author_delete(article_id:, author_id:, impersonate: nil, &block)
210
+ args = {}
211
+ args["impersonate"] = impersonate if ! impersonate.nil?
212
+ delete(api_query: "account/articles/#{article_id}/authors/#{author_id}", args: args, &block)
213
+ end
214
+
215
+ # List categories for a specific article
216
+ #
217
+ # @param article_id [Integer] Figshare id of the article
218
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
219
+ # yield [Hash] { parent_id, id, title }
220
+ def categories(article_id:, impersonate: nil, &block)
221
+ args = {}
222
+ args["impersonate"] = impersonate if ! impersonate.nil?
223
+ get(api_query: "account/articles/#{article_id}/categories", args: args, &block)
224
+ end
225
+
226
+ # Associate new categories with the article.
227
+ # This will add new categories to the list of already associated categories
228
+ #
229
+ # @param article_id [Integer] Figshare id of the article
230
+ # @param categories [Array] [ categorie_id, ... ]
231
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
232
+ def categories_add(article_id:, categories:, impersonate: nil, &block)
233
+ args = {}
234
+ args["impersonate"] = impersonate if ! impersonate.nil?
235
+ post(api_query: "account/articles/#{article_id}/categories", args: args, data: { 'categories' => categories }, &block)
236
+ end
237
+
238
+ # Associate new categories with the article. This will remove all already associated categories and add these new ones
239
+ #
240
+ # @param article_id [Integer] Figshare id of the article
241
+ # @param categories [Array] [ categorie_id, ... ]
242
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
243
+ def categories_replace(article_id:, categories:, impersonate: nil, &block)
244
+ args = {}
245
+ args["impersonate"] = impersonate if ! impersonate.nil?
246
+ put(api_query: "account/articles/#{article_id}/categories", args: args, data: { 'categories' => categories }, &block)
247
+ end
248
+
249
+ # Delete category from article's categories
250
+ #
251
+ # @param article_id [Integer] Figshare id of the article
252
+ # @param category_id [Integer] Figshare id of the category
253
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
254
+ def categories_delete(article_id:, category_id:, impersonate: nil, &block)
255
+ args = {}
256
+ args["impersonate"] = impersonate if ! impersonate.nil?
257
+ delete(api_query: "account/articles/#{article_id}/categories/#{category_id}", args: args, &block)
258
+ end
259
+
260
+ # List private links
261
+ #
262
+ # @param article_id [Integer] Figshare id of the article
263
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
264
+ # @yield [Hash] {id, is_active, expires_date}
265
+ def links(article_id:, impersonate: nil, &block)
266
+ args = {}
267
+ args["impersonate"] = impersonate if ! impersonate.nil?
268
+ get(api_query: "account/articles/#{article_id}/private_links", args: args, &block)
269
+ end
270
+
271
+ # Create new private link for this article
272
+ #
273
+ # @param article_id [Integer] Figshare id of the article
274
+ # @param private_link [Hash] { expires_date }
275
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
276
+ # @yield [Hash] { location }
277
+ def link_create(article_id:, private_link:, impersonate: nil, &block)
278
+ args = {}
279
+ args["impersonate"] = impersonate if ! impersonate.nil?
280
+ post(api_query: "account/articles/#{article_id}/private_links", data: private_link, args: args, &block)
281
+ end
282
+
283
+ # Disable/delete private link for this article
284
+ #
285
+ # @param article_id [Integer] Figshare id of the article
286
+ # @param link_id [Integer]
287
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
288
+ def link_delete(article_id:, link:, impersonate: nil, &block)
289
+ args = {}
290
+ args["impersonate"] = impersonate if ! impersonate.nil?
291
+ delete(api_query: "account/articles/#{article_id}/private_links/#{link_id}", args: args, &block)
292
+ end
293
+
294
+ # Update private link for this article
295
+ #
296
+ # @param article_id [Integer] Figshare id of the article
297
+ # @param expires_date [Time]
298
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
299
+ def link_update(article_id:, link_id:, expires_date:, impersonate: nil, &block)
300
+ args = {}
301
+ args["impersonate"] = impersonate if ! impersonate.nil?
302
+ put(api_query: "account/articles/#{article_id}/private_links/#{link_id}", args: args, data: { "expires_date" => expires_date.iso8601 }, &block)
303
+ end
304
+
305
+ # List private files in an article
306
+ #
307
+ # @param article_id [Integer] Figshare id of the article
308
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
309
+ # @yield [Hash] {status, viewer_type, preview_state, upload_url, upload_token, id, name, size, is_link_only,
310
+ # download_url, supplied_md5, computed_md5}
311
+ def files(article_id:, impersonate: nil, &block)
312
+ args = {}
313
+ args["impersonate"] = impersonate if ! impersonate.nil?
314
+ get(api_query: "account/articles/#{article_id}/files", args: args, &block)
315
+ end
316
+
317
+ # Single file detail
318
+ #
319
+ # @param article_id [Integer] Figshare id of the article
320
+ # @param file_id [Integer] Figshare id of the file
321
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
322
+ # @yield [Hash] {status, viewer_type, preview_state, upload_url, upload_token, id, name, size, is_link_only,
323
+ # download_url, supplied_md5, computed_md5}
324
+ def file_detail(article_id:, file_id:, impersonate: nil, &block)
325
+ args = {}
326
+ args["impersonate"] = impersonate if ! impersonate.nil?
327
+ get(api_query: "account/articles/#{article_id}/files/#{file_id}", args: args, &block)
328
+ end
329
+
330
+ # Delete a file from an article
331
+ #
332
+ # @param article_id [Integer] Figshare id of the article
333
+ # @param file_id [Integer] Figshare id of the file
334
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
335
+ def file_delete(article_id:, file_id: , impersonate: nil, &block)
336
+ args = {}
337
+ args["impersonate"] = impersonate if ! impersonate.nil?
338
+ delete( api_query: "account/articles/#{article_id}/files/#{file_id}", args: args, &block )
339
+ end
340
+
341
+ # WARNING!!!! Delete every file in an article
342
+ #
343
+ # @param article_id [Integer] Figshare id of the article
344
+ # @param impersonate [Integer] Figshare account_id of the user we are making this call on behalf of
345
+ # @yield [Hash] Figshare file record of each file being deleted (if block_given?)
346
+ def delete_all_files(article_id:, impersonate: nil)
347
+ article_files(article_id: article_id, impersonate: impersonate) do |f|
348
+ yield f if block_given?
349
+ article_file_delete(article_id: article_id, file_id: f['id'], impersonate: impersonate)
350
+ end
351
+ end
352
+
353
+ end
354
+ end