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:

  • Figshare id of the collection

  • Figshare id of the article

  • (defaults to: nil)

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



330
331
332
333
334
# File 'lib/private_collections.rb', line 330

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

  • Figshare id of the article

  • (defaults to: nil)

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



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

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

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

Yield collection articles

Parameters:

  • Figshare id of the collection

  • (defaults to: nil)

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

Yields:

  • (Hash)

    See Figshare API docs



286
287
288
289
290
# File 'lib/private_collections.rb', line 286

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

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

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

Parameters:

  • Figshare id of the collection

  • array of Figshare article ids

  • (defaults to: nil)

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

Yields:

  • (Hash)

    { location }



308
309
310
311
312
# File 'lib/private_collections.rb', line 308

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

  • Figshare id of the collection

  • array of Figshare article ids

  • (defaults to: nil)

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



319
320
321
322
323
# File 'lib/private_collections.rb', line 319

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

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

Remove author from the collection

Parameters:

  • Figshare id of the collection

  • Figshare id for the author

  • (defaults to: nil)

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



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

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

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

Yield collections authors

Parameters:

  • Figshare id of the collection

  • (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



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

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

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

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

Parameters:

  • Figshare id of the collection

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

  • (defaults to: nil)

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

Yields:

  • (Hash)

    { location }



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

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

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

Replace existing authors list with a new list

Parameters:

  • Figshare id of the collection

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

  • (defaults to: nil)

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



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

def authors_replace(collection_id:, authors:, impersonate: nil)
  args = {}
  args['impersonate'] = impersonate unless 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:

  • Figshare id of the collection

  • (defaults to: nil)

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

Yields:

  • (Hash)

    id, title, path, source_id, taxonomy_id



240
241
242
243
244
# File 'lib/private_collections.rb', line 240

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

  • Figshare id of the collection

  • categorie_id, …
  • (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
# File 'lib/private_collections.rb', line 253

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

  • Figshare id of the collection

  • Figshare id of the category

  • (defaults to: nil)

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



275
276
277
278
279
# File 'lib/private_collections.rb', line 275

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

  • Figshare id of the collection

  • categorie_id, …
  • (defaults to: nil)

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



264
265
266
267
268
# File 'lib/private_collections.rb', line 264

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

  • Figshare id of the collection

  • (defaults to: nil)

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



104
105
106
107
108
# File 'lib/private_collections.rb', line 104

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

#collection_resource(collection_id:, title:, id: nil, doi: nil, link: nil, status: nil, version: nil, impersonate: nil) {|Hash| ... } ⇒ Object

Collection Resource

Parameters:

  • (defaults to: nil)
  • (defaults to: nil)
  • (defaults to: nil)
  • (defaults to: nil)

    ‘frozen’, …

  • (defaults to: nil)

Yields:

  • (Hash)

    { location: “string” }



164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/private_collections.rb', line 164

def collection_resource(collection_id:, title:, id: nil, doi: nil, link: nil, status: nil, version: nil, impersonate: nil, &block)
  args = {}
  args['impersonate'] = impersonate unless impersonate.nil?
  resource = {}
  resource['title'] = title
  resource['id'] = id unless id.nil?
  resource['doi'] = doi unless doi.nil?
  resource['link'] = link unless link.nil?
  resource['status'] = status unless status.nil?
  resource['version'] = version unless version.nil?
  post(api_query: "account/collections/#{collection_id}/resource", args: args, data: resource, &block)
end

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

Create a new private Collection by sending collection information

Parameters:

  • See Figshare API docs

  • (defaults to: nil)

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



94
95
96
97
98
# File 'lib/private_collections.rb', line 94

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

  • Figshare id of the collection

  • (defaults to: nil)

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

Yields:

  • (Hash)

    See figshare api docs



115
116
117
118
119
# File 'lib/private_collections.rb', line 115

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

Create new private link for this collection

Parameters:

  • Figshare id of the collection

  • (defaults to: nil)
  • (defaults to: true)
  • (defaults to: nil)

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

Yields:

  • (Hash)

    { location:, html_location:, token: }



354
355
356
357
358
359
360
361
# File 'lib/private_collections.rb', line 354

def link_create(collection_id:, expires_date: nil, read_only: true, impersonate: nil, &block)
  args = {}
  args['impersonate'] = impersonate unless impersonate.nil?
  link_properties = {}
  link_properties['expires_date'] = expires_date.iso8601 unless expires_date.nil?
  link_properties['read_only'] = read_only unless read_only.nil?
  post(api_query: "account/collections/#{collection_id}/private_links", args: args, data: link_properties, &block)
end

Disable/delete private link for this collection

Parameters:

  • Figshare id of the collection

  • (defaults to: nil)

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



368
369
370
371
372
# File 'lib/private_collections.rb', line 368

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

Update private link for this collection

Parameters:

  • Figshare id of the collection

  • (defaults to: nil)
  • (defaults to: true)
  • (defaults to: nil)

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



380
381
382
383
384
385
386
387
# File 'lib/private_collections.rb', line 380

def link_update(collection_id:, link_id:, expires_date: nil, read_only: true, impersonate: nil, &block)
  args = {}
  args['impersonate'] = impersonate unless impersonate.nil?
  link_properties = {}
  link_properties['expires_date'] = expires_date.iso8601 unless expires_date.nil?
  link_properties['read_only'] = read_only unless read_only.nil?
  put(api_query: "account/collections/#{collection_id}/private_links/#{link_id}", args: args, data: link_properties, &block)
end

List private links

Parameters:

  • Figshare id of the collection

  • (defaults to: nil)

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

Yields:

  • (Hash)

    {id:, is_active:, expires_date:, html_location: }



341
342
343
344
345
# File 'lib/private_collections.rb', line 341

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

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

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

Parameters:

  • (defaults to: 'published_date')

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

  • (defaults to: 'desc')

    “desc” Default, “asc”

  • (defaults to: nil)

    Pages start at 1. Page and Page size go together

  • (defaults to: nil)
  • (defaults to: nil)

    offset is 0 based. Offset and Limit go together

  • (defaults to: nil)
  • (defaults to: nil)

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

Yields:

  • (Hash)

    title, doi, handle, url, timeline: {…, published_date} see docs.figshare.com



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/private_collections.rb', line 15

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

  • Figshare id of the collection

  • (defaults to: nil)

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

Yields:

  • (Hash)

    { location }



184
185
186
187
188
# File 'lib/private_collections.rb', line 184

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

  • Figshare id of the collection

  • (defaults to: nil)

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

Yields:

  • (Hash)

    { doi }



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

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

  • Figshare id of the collection

  • (defaults to: nil)

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

Yields:

  • (Hash)

    { handle }



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

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

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

Search within the own (or institute’s) collections

Parameters:

  • Just our institution

  • (defaults to: nil)

    Only return this group’s collections

  • (defaults to: nil)

    Return results if published after this time

  • (defaults to: nil)

    Return results if modified after this time

  • (defaults to: nil)

    Matches this resource id

  • (defaults to: nil)

    Matches this resource doi

  • (defaults to: nil)

    Matches this doi

  • (defaults to: nil)

    Matches this handle

  • (defaults to: 'published_date')

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

  • (defaults to: 'desc')

    “desc” Default, “asc”

  • (defaults to: nil)

    Pages start at 1. Page and Page size go together

  • (defaults to: nil)
  • (defaults to: nil)

    offset is 0 based. Offset and Limit go together

  • (defaults to: nil)
  • (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



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
79
80
81
82
83
84
85
86
87
88
# File 'lib/private_collections.rb', line 53

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

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

Create a new private Collection by sending collection information

Parameters:

  • Figshare id of the collection

  • See Figshare API docs

  • (defaults to: nil)

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



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

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