Class: Figshare::PrivateProjects

Inherits:
Base
  • Object
show all
Defined in:
lib/private_projects.rb

Overview

Figshare private project api

Instance Attribute Summary

Attributes inherited from Base

#api_url, #article_index_file, #auth_token, #base_dir, #hostname, #institute_id

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Figshare::Base

Instance Method Details

#article_create(project_id:, article:, impersonate: nil) {|Hash| ... } ⇒ Object

Create a new Article and associate it with this project

Parameters:

  • project_id (Integer)

    Figshare id of the project

  • article (Hash)

    See figshare API docs

  • impersonate (Integer) (defaults to: nil)

    Figshare account_id of the user we are making this call on behalf of

Yields:

  • (Hash)

    { location }



253
254
255
256
257
258
# File 'lib/private_projects.rb', line 253

def article_create(project_id:, article:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  # Figshare Docs say this should be post_paginate, but that makes no sense. Will have to test
  post_paginate(api_query: "account/projects/#{project_id}/articles", args: args, &block)
end

#article_delete(project_id:, article_id:, impersonate: nil, &block) ⇒ Object

delete an article from a project

Parameters:

  • project_id (Integer)

    Figshare id of the project

  • article_id (Integer)

    Figshare id of the article

  • impersonate (Integer) (defaults to: nil)

    Figshare account_id of the user we are making this call on behalf of



265
266
267
268
269
# File 'lib/private_projects.rb', line 265

def article_delete(project_id:, article_id:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  delete(api_query: "account/projects/#{project_id}/articles/#{article_id}", args: args, &block)
end

#article_detail(project_id:, article_id:, impersonate: nil) {|Hash| ... } ⇒ Object

Get the details of an artilcle in a project

Parameters:

  • project_id (Integer)

    Figshare id of the project

  • article_id (Integer)

    Figshare id of the article

  • impersonate (Integer) (defaults to: nil)

    Figshare account_id of the user we are making this call on behalf of

Yields:

  • (Hash)

    See Fishare API docs for article hash



277
278
279
280
281
# File 'lib/private_projects.rb', line 277

def article_detail(project_id:, article_id:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  get(api_query: "account/projects/#{project_id}/articles/#{article_id}", args: args, &block)
end

#articles(project_id:, impersonate: nil) {|Hash| ... } ⇒ Object

Return details of list of articles for a specific project

Parameters:

  • project_id (Integer)

    Figshare id of the project

  • impersonate (Integer) (defaults to: nil)

    Figshare account_id of the user we are making this call on behalf of

Yields:

  • (Hash)

    See Figshare API Doc



241
242
243
244
245
# File 'lib/private_projects.rb', line 241

def articles(project_id:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  get_paginate(api_query: "account/projects/#{project_id}/articles", args: args, &block)
end

#artilce_file_detail(project_id:, article_id:, file_id:, impersonate: nil, &block) ⇒ Object

Get the files associated with an artilcle in a project

Parameters:

  • project_id (Integer)

    Figshare id of the project

  • article_id (Integer)

    Figshare id of the article

  • file_id (Integer)

    Figshare id of the file

  • impersonate (Integer) (defaults to: nil)

    Figshare account_id of the user we are making this call on behalf of



301
302
303
304
305
# File 'lib/private_projects.rb', line 301

def artilce_file_detail(project_id:, article_id:, file_id:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  delete(api_query: "account/projects/#{project_id}/articles/#{article_id}/files/#{file_id}", args: args, &block)
end

#artilce_files(project_id:, article_id:, impersonate: nil) {|Hash| ... } ⇒ Object

Get the files associated with an artilcle in a project

Parameters:

  • project_id (Integer)

    Figshare id of the project

  • article_id (Integer)

    Figshare id of the article

  • impersonate (Integer) (defaults to: nil)

    Figshare account_id of the user we are making this call on behalf of

Yields:

  • (Hash)

    See Fishare API docs for article hash



289
290
291
292
293
# File 'lib/private_projects.rb', line 289

def artilce_files(project_id:, article_id:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  get(api_query: "account/projects/#{project_id}/articles/#{article_id}/files", args: args, &block)
end

#collaborator_invite(project_id:, role_name:, user_id: nil, email: nil, comment:, impersonate: nil) {|String| ... } ⇒ Object

Invite a new collaborators to the project

Parameters:

  • project_id (Integer)

    Figshare id of the project_id

  • role_name (String)
  • user_id (Integer) (defaults to: nil)

    Need user_id or email

  • email (String) (defaults to: nil)

    Used, if user_id is nil

  • comment (String)

Yields:

  • (String)

    { message }



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/private_projects.rb', line 208

def collaborator_invite(project_id:, role_name:, user_id: nil, email: nil, comment:, impersonate: nil, &block)
  args = {
    'role_name' => role_name,
    'comment' => comment
  }
  if ! user_id.nil?
    args['user_id'] = user_id
  elsif ! email.nil?
    args['email'] = email
  else
    raise "collaborator_invite(): Need a user_id or an email address" 
  end
  args["impersonate"] = impersonate  if ! impersonate.nil?
  collaborator = { "role_name" => role_name, "user_id" => user_id, "email" => email, "comment" => comment }
  post(api_query: "account/project/#{project_id}/collaborators", args: args, data: collaborator, &block)
end

#collaborator_remove(project_id:, user_id:, impersonate: nil, &block) ⇒ Object

Leave a project (Please note: project’s owner cannot leave the project.)

Parameters:

  • project_id (Integer)

    Figshare id of the project_id

  • user_id (Integer)

    Figshare id of a user in the project

  • impersonate (Integer) (defaults to: nil)

    Figshare account_id of the user we are making this call on behalf of



230
231
232
233
234
# File 'lib/private_projects.rb', line 230

def collaborator_remove(project_id:, user_id:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  delete(api_query: "account/project/#{project_id}/collaborators/#{user_id}", args: args, &block)
end

#collaborators(project_id:, impersonate: nil) {|Hash| ... } ⇒ Object

Get the project collaborators

Parameters:

  • project_id (Integer)

    Figshare id of the project_id

  • impersonate (Integer) (defaults to: nil)

    Figshare account_id of the user we are making this call on behalf of

Yields:

  • (Hash)

    { status, role_name, user_id, name }



194
195
196
197
198
# File 'lib/private_projects.rb', line 194

def collaborators(project_id:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  get(api_query: "account/projects/#{project_id}/collaborators", args: args, &block)
end

#create(title:, description:, funding: '', funding_list: [], group_id:, impersonate: nil) {|Hash| ... } ⇒ Object

Create a new project

#param group_id [Integer] Figshare group the project falls under.

Parameters:

  • title (String)
  • description (String)
  • funding (String) (defaults to: '')
  • funding_list (Array) (defaults to: [])
    title, …
  • impersonate (Integer) (defaults to: nil)

    Figshare account_id of the user we are making this call on behalf of

Yields:

  • (Hash)

    { location }



60
61
62
63
64
65
66
67
68
69
# File 'lib/private_projects.rb', line 60

def create(title:, description:, funding: '', funding_list: [], group_id:, impersonate: nil, &block)
  args = { "title" => title, 
           "description" => description, 
           "group_id" => group_id,
           "funding" => funding,
           "funding_list" => funding_list
         }
  args["impersonate"] = impersonate  if ! impersonate.nil?
  post(api_query: 'account/projects', args: args, &block)
end

#detail(project_id:, impersonate: nil) {|Hash| ... } ⇒ Object

Return details of specific private project

Parameters:

  • project_id (Integer)

    Figshare id of the project_id

  • impersonate (Integer) (defaults to: nil)

    Figshare account_id of the user we are making this call on behalf of

Yields:

  • (Hash)

    See figshare api docs



86
87
88
89
90
# File 'lib/private_projects.rb', line 86

def detail(project_id:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  get(api_query: "account/projects/#{project_id}",  args: args, &block)
end

#list(storage: nil, roles: nil, order: 'published_date', order_direction: 'desc', impersonate: nil) {|Hash| ... } ⇒ Object

Requests a list private projects

Parameters:

  • storage (String) (defaults to: nil)

    group, individual (only return collections from this institution)

  • roles (String) (defaults to: nil)

    Any combination of owner, collaborator, viewer separated by comma. Examples: “owner” or “owner,collaborator”.

  • order (String) (defaults to: 'published_date')

    “published_date” Default, “modified_date”, “views”, “cites”, “shares”

  • order_direction (String) (defaults to: 'desc')

    “desc” Default, “asc”

  • impersonate (Integer) (defaults to: nil)

    Figshare account_id of the user we are making this call on behalf of

Yields:

  • (Hash)

    storage, url, published_date, id, title



14
15
16
17
18
19
20
21
22
# File 'lib/private_projects.rb', line 14

def list(storage: nil, roles: nil, order: 'published_date', order_direction: 'desc', impersonate: nil, &block)
  args = {}
  args['storage'] = storage if ! storage.nil?
  args['roles'] = roles if ! roles.nil?
  args['order'] = order if ! order.nil?
  args['order_direction'] = order_direction if ! order_direction.nil?
  args["impersonate"] = impersonate  if ! impersonate.nil?
  get_paginate(api_query: 'account/projects', args: args, &block)
end

#note_create(project_id:, note_id:, text:, impersonate: nil, &block) ⇒ Object

update a project note

Parameters:

  • project_id (Integer)

    Figshare id of the project

  • note_id (Integer)

    Figshare id of the note

  • text (String)

    The note

  • impersonate (Integer) (defaults to: nil)

    Figshare account_id of the user we are making this call on behalf of



139
140
141
142
143
# File 'lib/private_projects.rb', line 139

def note_create(project_id:, text:, impersonate: nil, &block)
  args = { 'text' => text }
  args["impersonate"] = impersonate  if ! impersonate.nil?
  post(api_query: "account/projects/#{project_id}/notes", args: args, &block)
end

#note_delete(project_id:, note_id:, impersonate: nil, &block) ⇒ Object

Delete a project note

Parameters:

  • project_id (Integer)

    Figshare id of the project

  • note_id (Integer)

    Figshare id of the note

  • impersonate (Integer) (defaults to: nil)

    Figshare account_id of the user we are making this call on behalf of



150
151
152
153
154
# File 'lib/private_projects.rb', line 150

def note_delete(project_id:, note_id:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  delete(api_query: "account/projects/#{project_id}/notes/#{note_id}", args: args, &block)
end

#note_detail(impersonate: nil) {|Hash| ... } ⇒ Object

Get a note’s text

Parameters:

  • project_id (Integer)

    Figshare id of the project

  • note_id (Integer)

    Figshare id of the note

  • impersonate (Integer) (defaults to: nil)

    Figshare account_id of the user we are making this call on behalf of

Yields:

  • (Hash)

    { text }



162
163
164
165
166
# File 'lib/private_projects.rb', line 162

def note_detail(impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  get(api_query: "account/projects/#{project_id}/notes/#{note_id}", args: args, &block)
end

#notes(project_id:, impersonate: nil) {|Hash| ... } ⇒ Object

List projects notes

Parameters:

  • project_id (Integer)

    Figshare id of the project

  • impersonate (Integer) (defaults to: nil)

    Figshare account_id of the user we are making this call on behalf of

Yields:

  • (Hash)

    user_id, abstract, user_name, created_date, modified_date



127
128
129
130
131
# File 'lib/private_projects.rb', line 127

def notes(project_id:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  get_paginate(api_query: "account/projects/#{project_id}/notes", args: args, &block)
end

#private_project_collaborators_leave(project_id:, impersonate: nil, &block) ⇒ Object

Leave a project (Please note: project’s owner cannot leave the project.)

Parameters:

  • project_id (Integer)

    Figshare id of the project_id



183
184
185
186
187
# File 'lib/private_projects.rb', line 183

def private_project_collaborators_leave(project_id:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  post(api_query: "account/projects/#{project_id}/leave", args: args, &block)
end

#project_delete(project_id:, impersonate: nil, &block) ⇒ Object

Delete an existing project

Parameters:

  • project_id (Integer)

    Figshare project ID

  • impersonate (Integer) (defaults to: nil)

    Figshare account_id of the user we are making this call on behalf of



75
76
77
78
79
# File 'lib/private_projects.rb', line 75

def project_delete(project_id:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  delete(api_query: 'account/projects/#{project_id}', args: args, &block)
end

#publish(project_id:, impersonate: nil) {|Hash| ... } ⇒ Object

Publish a project

Parameters:

  • project_id (Integer)

    Figshare id of the project

  • impersonate (Integer) (defaults to: nil)

    Figshare account_id of the user we are making this call on behalf of

Yields:

  • (Hash)

    Message



116
117
118
119
120
# File 'lib/private_projects.rb', line 116

def publish(project_id:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  post(api_query: "account/projects/#{project_id}/publish", args: args, &block)
end

#search(institute: false, group_id: nil, impersonate: nil, published_since: nil, modified_since: nil, order: 'published_date', order_direction: 'desc', search_for:) {|Hash| ... } ⇒ Object

Search within the own (or institute’s) projects

Parameters:

  • institution (Boolean)

    Just our institution

  • group_id (Integer) (defaults to: nil)

    Only return this group’s project

  • published_since (Time) (defaults to: nil)

    Return results if published after this time

  • modified_since (Time) (defaults to: nil)

    Return results if modified after this time

  • order (String) (defaults to: 'published_date')

    “published_date” Default, “modified_date”, “views”, “cites”, “shares”

  • order_direction (String) (defaults to: 'desc')

    “desc” Default, “asc”

  • impersonate (Integer) (defaults to: nil)

    Figshare account_id of the user we are making this call on behalf of

Yields:

  • (Hash)

    title, doi, handle, url, published_date



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/private_projects.rb', line 34

def search(institute: false, group_id: nil, impersonate: nil, 
                    published_since: nil, modified_since: nil, 
                    order: 'published_date', order_direction: 'desc',
                    search_for:,
                    &block
                   )
  args = { 'search_for' => search_for }
  args['institution'] = @institute_id if ! institute.nil?
  args['group'] = group_id if ! group_id.nil?
  args["impersonate"] = impersonate  if ! impersonate.nil?
  args['published_since'] = published_since if ! published_since.nil?
  args['modified_since'] = modified_since if ! modified_since.nil?
  args['order'] = order if ! order.nil?
  args['order_direction'] = order_direction if ! order_direction.nil?
  post(api_query: 'account/projects/search', args: args, &block)
end

#update(project_id:, title: nil, description: nil, funding: nil, funding_list: nil, impersonate: nil) {|Hash| ... } ⇒ Object

Update an existing project

Parameters:

  • project_id (Integer)

    Figshare id of the project_id

  • title (String) (defaults to: nil)
  • description (String) (defaults to: nil)
  • funding (String) (defaults to: nil)
  • funding_list (Array) (defaults to: nil)
    title, …
  • impersonate (Integer) (defaults to: nil)

    Figshare account_id of the user we are making this call on behalf of

Yields:

  • (Hash)

    { location }



101
102
103
104
105
106
107
108
109
# File 'lib/private_projects.rb', line 101

def update(project_id:, title: nil, description: nil, funding: nil, funding_list: nil, impersonate: nil, &block)
  args = {}
  args["title"] = title if ! title.nil? 
  args["description"] = description if ! description.nil? 
  args["funding"] = funding if ! funding.nil? 
  args["funding_list"] = funding_list if ! funding_list.nil? 
  args["impersonate"] = impersonate  if ! impersonate.nil?
  put(api_query: "account/projects/#{project_id}", args: args, &block)
end