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_record: nil, page: nil, page_size: nil, offset: nil, limit: nil, impersonate: nil) {|Hash| ... } ⇒ Object

Create a new Article and associate it with this project

Parameters:

  • project_id (Integer)

    Figshare id of the project

  • article_record (Hash) (defaults to: nil)

    See docs.figshare.com

  • page (Numeric) (defaults to: nil)

    Pages start at 1. Page and Page size go together

  • page_size (Numeric) (defaults to: nil)
  • offset (Numeric) (defaults to: nil)

    offset is 0 based. Offset and Limit go together

  • limit (Numeric) (defaults to: nil)
  • impersonate (Integer) (defaults to: nil)

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

Yields:

  • (Hash)

    { entity_id:, location:, warnings: [ “string” ] }



319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/private_projects.rb', line 319

def article_create( project_id:,
                    article_record: nil,
                    page: nil,
                    page_size: nil,
                    offset: nil,
                    limit: nil,
                    impersonate: nil,
                    &block
                  )
  args = { 'article' => article_record }
  args['page'] = page unless page.nil?
  args['page_size'] = page_size unless page_size.nil?
  args['offset'] = offset unless offset.nil?
  args['limit'] = limit unless limit.nil?
  args['impersonate'] = impersonate unless 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



343
344
345
346
347
# File 'lib/private_projects.rb', line 343

def article_delete(project_id:, article_id:, impersonate: nil, &block)
  args = {}
  args['impersonate'] = impersonate unless 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 docs.figshare.com for article hash



355
356
357
358
359
# File 'lib/private_projects.rb', line 355

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

#articles(project_id:, page: nil, page_size: nil, offset: nil, limit: nil, impersonate: nil) {|Array| ... } ⇒ Object

Return details of list of articles for a specific project

Parameters:

  • project_id (Integer)

    Figshare id of the project

  • page (Numeric) (defaults to: nil)

    Pages start at 1. Page and Page size go together

  • page_size (Numeric) (defaults to: nil)
  • offset (Numeric) (defaults to: nil)

    offset is 0 based. Offset and Limit go together

  • limit (Numeric) (defaults to: nil)
  • impersonate (Integer) (defaults to: nil)

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

Yields:

  • (Array)

    See Figshare API Doc



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/private_projects.rb', line 292

def articles( project_id:,
              page: nil,
              page_size: nil,
              offset: nil,
              limit: nil,
              impersonate: nil,
              &block
            )
  args = {}
  args['page'] = page unless page.nil?
  args['page_size'] = page_size unless page_size.nil?
  args['offset'] = offset unless offset.nil?
  args['limit'] = limit unless limit.nil?
  args['impersonate'] = impersonate unless 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



379
380
381
382
383
# File 'lib/private_projects.rb', line 379

def artilce_file_detail(project_id:, article_id:, file_id:, impersonate: nil, &block)
  args = {}
  args['impersonate'] = impersonate unless 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) {|Array| ... } ⇒ 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:

  • (Array)

    See docs.figshare.com



367
368
369
370
371
# File 'lib/private_projects.rb', line 367

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

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

Invite a new collaborators to the project

Parameters:

  • project_id (Integer)

    Figshare id of the project_id

  • role_name (String)

    “viewer”, …

  • user_id (Integer) (defaults to: nil)

    Need user_id and/or email

  • email (String) (defaults to: nil)

    Need user_id and/or email

  • comment (String)

Yields:

  • (String)

    { message }



256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/private_projects.rb', line 256

def collaborator_invite(project_id:, role_name:, comment:, user_id: nil, email: nil, impersonate: nil, &block)
  raise 'collaborator_invite(): Need a user_id or an email address' if user_id.nil? && email.nil?

  args = {
    'role_name' => role_name,
    'comment' => comment
  }
  args['user_id'] = user_id unless user_id.nil?
  args['email'] = email unless email.nil?
  args['impersonate'] = impersonate unless 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



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

def collaborator_remove(project_id:, user_id:, impersonate: nil, &block)
  raise 'collaborator_remove(): Need a user_id' if user_id.nil?

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

#collaborators(project_id:, impersonate: nil) {|Array| ... } ⇒ 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:

  • (Array)

    [{ status:, role_name:, user_id:, name: }]



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

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

#create(title:, description:, group_id:, funding: '', funding_list: [], custom_field_list: nil, 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, … ]

  • custom_field_list (Array) (defaults to: nil)

    [value, … ]

  • impersonate (Integer) (defaults to: nil)

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

Yields:

  • (Hash)

    { location }



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/private_projects.rb', line 90

def create(title:, description:, group_id:, funding: '', funding_list: [], custom_field_list: nil, impersonate: nil, &block)
  args = { 'title' => title,
           'description' => description,
           'group_id' => group_id,
           'funding' => funding,
           'funding_list' => funding_list
         }
  args['custom_field_list'] = custom_field_list unless custom_field_list.nil?
  args['impersonate'] = impersonate unless 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



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

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

#list(storage: nil, roles: nil, order: 'published_date', order_direction: 'desc', page: nil, page_size: nil, offset: nil, limit: nil, impersonate: nil) {|Array| ... } ⇒ 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”

  • page (Numeric) (defaults to: nil)

    Pages start at 1. Page and Page size go together

  • page_size (Numeric) (defaults to: nil)
  • offset (Numeric) (defaults to: nil)

    offset is 0 based. Offset and Limit go together

  • limit (Numeric) (defaults to: nil)
  • impersonate (Integer) (defaults to: nil)

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

Yields:

  • (Array)

    [storage, url, published_date, id, title]



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/private_projects.rb', line 17

def list( storage: nil,
          roles: nil,
          order: 'published_date',
          order_direction: 'desc',
          page: nil,
          page_size: nil,
          offset: nil,
          limit: nil,
          impersonate: nil,
          &block
        )
  args = {}
  args['storage'] = storage unless storage.nil?
  args['roles'] = roles unless roles.nil?
  args['order'] = order unless order.nil?
  args['order_direction'] = order_direction unless order_direction.nil?
  args['page'] = page unless page.nil?
  args['page_size'] = page_size unless page_size.nil?
  args['offset'] = offset unless offset.nil?
  args['limit'] = limit unless limit.nil?
  args['impersonate'] = impersonate unless impersonate.nil?
  get_paginate(api_query: 'account/projects', args: args, &block)
end

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

Create a project note

Parameters:

  • project_id (Integer)

    Figshare id of the project

  • text (String)

    The note

  • impersonate (Integer) (defaults to: nil)

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

Yields:

  • (Hash)

    { location }



187
188
189
190
191
# File 'lib/private_projects.rb', line 187

def note_create(project_id:, text:, impersonate: nil, &block)
  args = { 'text' => text }
  args['impersonate'] = impersonate unless 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



198
199
200
201
202
# File 'lib/private_projects.rb', line 198

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

#note_detail(project_id:, note_id:, 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:, id:, user_id:, abstract:, user_name:, created_date:, modified_data: }



210
211
212
213
214
# File 'lib/private_projects.rb', line 210

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

#note_update(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



222
223
224
225
226
# File 'lib/private_projects.rb', line 222

def note_update(project_id:, note_id:, text:, impersonate: nil, &block)
  args = { 'text' => text }
  args['impersonate'] = impersonate unless impersonate.nil?
  put(api_query: "account/projects/#{project_id}/notes/#{note_id}", args: args, &block)
end

#notes(project_id:, page: nil, page_size: nil, offset: nil, limit: nil, impersonate: nil) {|Array| ... } ⇒ Object

List projects notes

Parameters:

  • project_id (Integer)

    Figshare id of the project

  • page (Numeric) (defaults to: nil)

    Pages start at 1. Page and Page size go together

  • page_size (Numeric) (defaults to: nil)
  • offset (Numeric) (defaults to: nil)

    offset is 0 based. Offset and Limit go together

  • limit (Numeric) (defaults to: nil)
  • impersonate (Integer) (defaults to: nil)

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

Yields:

  • (Array)

    [user_id:, abstract:, user_name:, created_date:, modified_date:]



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/private_projects.rb', line 164

def notes(  project_id:,
            page: nil,
            page_size: nil,
            offset: nil,
            limit: nil,
            impersonate: nil,
            &block
         )
  args = {}
  args['page'] = page unless page.nil?
  args['page_size'] = page_size unless page_size.nil?
  args['offset'] = offset unless offset.nil?
  args['limit'] = limit unless limit.nil?
  args['impersonate'] = impersonate unless impersonate.nil?
  get_paginate(api_query: "account/projects/#{project_id}/notes", args: args, &block)
end

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

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

Parameters:

  • project_id (Integer)

    Figshare id of the project_id



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

def project_collaborators_leave(project_id:, impersonate: nil, &block)
  args = {}
  args['impersonate'] = impersonate unless 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



106
107
108
109
110
# File 'lib/private_projects.rb', line 106

def project_delete(project_id:, impersonate: nil, &block)
  args = {}
  args['impersonate'] = impersonate unless 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:



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

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

#search(search_for:, institute: false, group_id: nil, published_since: nil, modified_since: nil, order: 'published_date', order_direction: 'desc', page: nil, page_size: nil, offset: nil, limit: nil, impersonate: nil) {|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, url, role, storage, published_date



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/private_projects.rb', line 51

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

#update(project_id:, title: nil, description: nil, funding: nil, funding_list: nil, custom_field_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, … ]

  • custom_field_list (Array) (defaults to: nil)

    [value, … ]

  • impersonate (Integer) (defaults to: nil)

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

Yields:

  • (Hash)

    { location }



133
134
135
136
137
138
139
140
141
142
# File 'lib/private_projects.rb', line 133

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