Class: Figshare::PrivateCollections

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

Overview

Figshare Private Collections 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_delete(collection_id:, article_id:, impersonate: nil, &block) ⇒ Object

Get a private article’s details (Not a figshare API call. Duplicates PrivateArticles:article_detail)

Parameters:

  • collection_id (Integer)

    Figshare id of the collection

  • 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



272
273
274
275
276
# File 'lib/private_collections.rb', line 272

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

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

Get a private article’s details (Not a figshare API call. Duplicates PrivateArticles:article_detail)

Parameters:

  • 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



238
239
240
241
242
# File 'lib/private_collections.rb', line 238

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

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

Yield collection articles

Parameters:

  • collection_id (Integer)

    Figshare id of the collection

  • 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



228
229
230
231
232
# File 'lib/private_collections.rb', line 228

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

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

Yields:

  • (Hash)

    { location }



250
251
252
253
254
# File 'lib/private_collections.rb', line 250

def articles_add(collection_id:, articles: , impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  post( api_query: "account/collections/#{collection_id}/articles", args: args, data: { "articles": articles}, &block)
end

#articles_replace(collection_id:, articles:, impersonate: nil, &block) ⇒ Object

Get a private article’s details (Not a figshare API call. Duplicates PrivateArticles:article_detail)

Parameters:

  • collection_id (Integer)

    Figshare id of the collection

  • articles (Array)

    array of Figshare article ids

  • impersonate (Integer) (defaults to: nil)

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



261
262
263
264
265
# File 'lib/private_collections.rb', line 261

def articles_replace(collection_id:, articles:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  put( api_query: "account/collections/#{collection_id}/articles/#{article_id}", args: args, data: { "articles": articles}, &block)
end

#author_delete(collection_id:, impersonate: nil, author_id:) ⇒ Object

Remove author from the collection

Parameters:

  • collection_id (Integer)

    Figshare id of the collection

  • author_id (Integer)

    Figshare id for the author

  • impersonate (Integer) (defaults to: nil)

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



171
172
173
174
175
# File 'lib/private_collections.rb', line 171

def author_delete(collection_id:, impersonate: nil, author_id:)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  delete(api_query: "account/collections/#{collection_id}/authors/#{author_id}", args: args, &block)
end

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

Yield collections authors

Parameters:

  • collection_id (Integer)

    Figshare id of the collection

  • impersonate (Integer) (defaults to: nil)

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

Yields:

  • (Hash)

    full_name, is_active, url_name, orcid_id



137
138
139
140
141
# File 'lib/private_collections.rb', line 137

def authors(article_id, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  get(api_query: "account/collections/#{collection_id}/authors", args: args, &block)
end

#authors_add(article_id, impersonate: nil, authors:) {|Hash| ... } ⇒ Object

Associate new authors with the collection. This will add new authors to the list of already associated authors

Parameters:

  • collection_id (Integer)

    Figshare id of the collection

  • authors (Array)

    Can be a mix of { id } and/or { name }

  • impersonate (Integer) (defaults to: nil)

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

Yields:

  • (Hash)

    { location }



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

def authors_add(article_id, impersonate: nil, authors:)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  post(api_query: "account/collections/#{collection_id}/authors", args: args, data: {"authors" => authors}, &block)
end

#authors_replace(article_id, impersonate: nil, authors:) ⇒ Object

Replace existing authors list with a new list

Parameters:

  • collection_id (Integer)

    Figshare id of the collection

  • authors (Array)

    Can be a mix of { id } and/or { name }

  • impersonate (Integer) (defaults to: nil)

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



160
161
162
163
164
# File 'lib/private_collections.rb', line 160

def authors_replace(article_id, impersonate: nil, authors:)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  put(api_query: "account/collections/#{collection_id}/authors", args: args, data: {"authors" => authors}, &block)
end

#categories(collection_id:, impersonate: nil) {|Hash| ... } ⇒ Object

Yield collection categories

Parameters:

  • collection_id (Integer)

    Figshare id of the collection

  • impersonate (Integer) (defaults to: nil)

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

Yields:

  • (Hash)

    id, title



182
183
184
185
186
# File 'lib/private_collections.rb', line 182

def categories(collection_id:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  get(api_query: 'account/collections/#{collection_id}/categories', args: args, &block)
end

#categories_add(collection_id:, categories:, impersonate: nil) {|Hash| ... } ⇒ Object

Associate new categories with the collection. This will add new categories to the list of already associated categories

Parameters:

  • collection_id (Integer)

    Figshare id of the collection

  • categories (Array)
    categorie_id, …
  • impersonate (Integer) (defaults to: nil)

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

Yields:

  • (Hash)

    { location }



195
196
197
198
199
# File 'lib/private_collections.rb', line 195

def categories_add(collection_id:, categories:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  post(api_query: "account/collections/#{collection_id}/categories", args: args, data: { 'categories' => categories }, &block)
end

#categories_delete(collection_id:, category_id:, impersonate: nil, &block) ⇒ Object

Delete category from collection’s categories

Parameters:

  • collection_id (Integer)

    Figshare id of the collection

  • category_id (Integer)

    Figshare id of the category

  • impersonate (Integer) (defaults to: nil)

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



217
218
219
220
221
# File 'lib/private_collections.rb', line 217

def categories_delete(collection_id:, category_id:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  delete(api_query: "account/collections/#{collection_id}/categories/#{category_id}", args: args, &block)
end

#categories_replace(collection_id:, categories:, impersonate: nil, &block) ⇒ Object

Associate new categories with the collection. This will remove all already associated categories and add these new ones

Parameters:

  • collection_id (Integer)

    Figshare id of the collection

  • categories (Array)
    categorie_id, …
  • impersonate (Integer) (defaults to: nil)

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



206
207
208
209
210
# File 'lib/private_collections.rb', line 206

def categories_replace(collection_id:, categories:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  put(api_query: "account/collections/#{collection_id}/categories", args: args, data: { 'categories' => categories }, &block)
end

#collection_delete(collection_id:, impersonate: nil, &block) ⇒ Object

Delete a private collection

Parameters:

  • collection_id (Integer)

    Figshare id of the collection

  • impersonate (Integer) (defaults to: nil)

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



69
70
71
72
73
# File 'lib/private_collections.rb', line 69

def collection_delete(collection_id:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  delete( api_query: "account/collections/#{collection_id}/files/#{file_id}", args: args, &block )
end

#create(body:, impersonate: nil, &block) ⇒ Object

Create a new private Collection by sending collection information

Parameters:

  • body (Hash)

    See Figshare API docs

  • impersonate (Integer) (defaults to: nil)

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



59
60
61
62
63
# File 'lib/private_collections.rb', line 59

def create(body:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  post(api_query: "account/collections", args: args, data: body, &block)
end

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

Return details of specific collection (default version)

Parameters:

  • collection_id (Integer)

    Figshare id of the collection

  • 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



80
81
82
83
84
# File 'lib/private_collections.rb', line 80

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

Create new private link for this collection

Parameters:

  • collection_id (Integer)

    Figshare id of the collection

  • private_link (Hash)

    { expires_date, read_only }

  • impersonate (Integer) (defaults to: nil)

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

Yields:

  • (Hash)

    { location }



295
296
297
298
299
# File 'lib/private_collections.rb', line 295

def link_create(collection_id:, private_link:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  post(api_query: "account/collections/#{collection_id}/private_links", args: args, data: private_link, &block)
end

Disable/delete private link for this collection

Parameters:

  • collection_id (Integer)

    Figshare id of the collection

  • link_id (Integer)
  • impersonate (Integer) (defaults to: nil)

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



306
307
308
309
310
# File 'lib/private_collections.rb', line 306

def link_delete(collection_id:, link:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  delete(api_query: "account/collections/#{collection_id}/private_links/#{link_id}", args: args, &block)
end

Update private link for this collection

Parameters:

  • collection_id (Integer)

    Figshare id of the collection

  • private_link (Hash)

    { expires_date, read_only }

  • impersonate (Integer) (defaults to: nil)

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



317
318
319
320
321
# File 'lib/private_collections.rb', line 317

def link_update(collection_id:, link_id:, private_link:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  put(api_query: "account/collections/#{collection_id}/private_links/#{link_id}", args: args, data: private_link, &block)
end

List private links

Parameters:

  • collection_id (Integer)

    Figshare id of the collection

  • impersonate (Integer) (defaults to: nil)

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

Yields:

  • (Hash)

    is_active, expires_date



283
284
285
286
287
# File 'lib/private_collections.rb', line 283

def links(collection_id:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  get(api_query: "account/collections/#{collection_id}/private_links", args: args, &block)
end

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

Requests a list of own (or institute’s) collections

Parameters:

  • 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



13
14
15
16
17
18
19
# File 'lib/private_collections.rb', line 13

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

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

When a collection is published, a new public version will be generated. Any further updates to the collection will affect the private collection data. In order to make these changes publicly visible, an explicit publish operation is needed.

Parameters:

  • collection_id (Integer)

    Figshare id of the collection

  • impersonate (Integer) (defaults to: nil)

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

Yields:

  • (Hash)

    { location }



126
127
128
129
130
# File 'lib/private_collections.rb', line 126

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

#reserve_doi(collection_id:, impersonate: nil) {|Hash| ... } ⇒ Object

Reserve DOI for collection

Parameters:

  • collection_id (Integer)

    Figshare id of the collection

  • impersonate (Integer) (defaults to: nil)

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

Yields:

  • (Hash)

    { doi }



102
103
104
105
106
# File 'lib/private_collections.rb', line 102

def reserve_doi(collection_id:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  post(api_query: 'account/collections/#{collection_id}/reserve_doi', args: args, &block)
end

#reserve_handle(collection_id:, impersonate: nil) {|Hash| ... } ⇒ Object

Reserve Handle for collection

Parameters:

  • collection_id (Integer)

    Figshare id of the collection

  • impersonate (Integer) (defaults to: nil)

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

Yields:

  • (Hash)

    { handle }



113
114
115
116
117
# File 'lib/private_collections.rb', line 113

def reserve_handle(collection_id:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  post(api_query: 'account/collections/#{collection_id}/reserve_handle', args: args, &block)
end

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

Search within the own (or institute’s) collections

Parameters:

  • institution (Boolean)

    Just our institution

  • group_id (Integer) (defaults to: nil)

    Only return this group’s collections

  • 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

  • resource_doi (String) (defaults to: nil)

    Matches this resource doi

  • doi (String) (defaults to: nil)

    Matches this doi

  • handle (String) (defaults to: nil)

    Matches this handle

  • 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
50
51
52
53
# File 'lib/private_collections.rb', line 34

def search(institute: false, group_id: nil, impersonate: nil, 
                          published_since: nil, modified_since: nil, 
                          resource_doi: nil, doi: nil, handle: nil,  
                          order: 'published_date', order_direction: 'desc',
                          search_for:,
                          &block
                         )
  args = { 'search_for' => search_for }
  args["impersonate"] = impersonate  if ! impersonate.nil?
  args['institution'] = @institute_id if ! institute.nil?
  args['group_id'] = group_id if ! group_id.nil?
  args['resource_doi'] = resource_doi if ! resource_doi.nil?
  args['doi'] = doi if ! doi.nil?
  args['handle'] = handle if ! handle.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/collections/search', args: args, &block)
end

#update(collection_id:, body:, impersonate: nil, &block) ⇒ Object

Create a new private Collection by sending collection information

Parameters:

  • collection_id (Integer)

    Figshare id of the collection

  • body (Hash)

    See Figshare API docs

  • impersonate (Integer) (defaults to: nil)

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



91
92
93
94
95
# File 'lib/private_collections.rb', line 91

def update(collection_id:, body:, impersonate: nil, &block)
  args = {}
  args["impersonate"] = impersonate  if ! impersonate.nil?
  put(api_query: "account/collections", args: args, data: body, &block)
end