Class: Figshare::PrivateCollections
- 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
-
#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).
-
#article_detail(article_id:, impersonate: nil, &block) ⇒ Object
Get a private article’s details (Not a figshare API call. Duplicates PrivateArticles:article_detail).
-
#articles(collection_id:, impersonate: nil) {|Hash| ... } ⇒ Object
Yield collection articles.
-
#articles_add(collection_id:, articles:, impersonate: nil) {|Hash| ... } ⇒ Object
Associate new articles with the collection.
-
#articles_replace(collection_id:, articles:, impersonate: nil, &block) ⇒ Object
Get a private article’s details (Not a figshare API call. Duplicates PrivateArticles:article_detail).
-
#author_delete(collection_id:, author_id:, impersonate: nil) ⇒ Object
Remove author from the collection.
-
#authors(collection_id:, impersonate: nil) {|Hash| ... } ⇒ Object
Yield collections authors.
-
#authors_add(collection_id:, authors:, impersonate: nil) {|Hash| ... } ⇒ Object
Associate new authors with the collection.
-
#authors_replace(collection_id:, authors:, impersonate: nil) ⇒ Object
Replace existing authors list with a new list.
-
#body(title:, description: nil, is_metadata_record: nil, metadata_reason: nil, tags: nil, keywords: nil, references: nil, categories: nil, categories_by_source_id: nil, authors: nil, custom_fields: nil, custom_fields_list: nil, defined_type: nil, funding: nil, funding_list: nil, license: nil, doi: nil, handle: nil, resource_doi: nil, resource_title: nil, timeline: nil, group_id: nil) ⇒ Object
Create a body for use with create and update methods.
-
#categories(collection_id:, impersonate: nil) {|Hash| ... } ⇒ Object
Yield collection categories.
-
#categories_add(collection_id:, categories:, impersonate: nil) {|Hash| ... } ⇒ Object
Associate new categories with the collection.
-
#categories_delete(collection_id:, category_id:, impersonate: nil, &block) ⇒ Object
Delete category from collection’s categories.
-
#categories_replace(collection_id:, categories:, impersonate: nil, &block) ⇒ Object
Associate new categories with the collection.
-
#collection_delete(collection_id:, impersonate: nil, &block) ⇒ Object
Delete a private collection.
-
#collection_resource(collection_id:, title:, id: nil, doi: nil, link: nil, status: nil, version: nil, impersonate: nil) {|Hash| ... } ⇒ Object
Collection Resource.
-
#create(body:, impersonate: nil, &block) ⇒ Object
Create a new private Collection by sending collection information.
-
#detail(collection_id:, impersonate: nil) {|Hash| ... } ⇒ Object
Return details of specific collection (default version).
-
#link_create(collection_id:, expires_date: nil, read_only: true, impersonate: nil) {|Hash| ... } ⇒ Object
Create new private link for this collection.
-
#link_delete(collection_id:, link_id:, impersonate: nil, &block) ⇒ Object
Disable/delete private link for this collection.
-
#link_update(collection_id:, link_id:, expires_date: nil, read_only: true, impersonate: nil, &block) ⇒ Object
Update private link for this collection.
-
#links(collection_id:, impersonate: nil) {|Hash| ... } ⇒ Object
List private links.
-
#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.
-
#publish(collection_id:, impersonate: nil) {|Hash| ... } ⇒ Object
When a collection is published, a new public version will be generated.
-
#reserve_doi(collection_id:, impersonate: nil) {|Hash| ... } ⇒ Object
Reserve DOI for collection.
-
#reserve_handle(collection_id:, impersonate: nil) {|Hash| ... } ⇒ Object
Reserve Handle for collection.
-
#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.
-
#update(collection_id:, body:, impersonate: nil, &block) ⇒ Object
Create a new private Collection by sending collection information.
Methods inherited from Base
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)
426 427 428 429 430 |
# File 'lib/private_collections.rb', line 426 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)
381 382 383 384 385 |
# File 'lib/private_collections.rb', line 381 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
369 370 371 372 373 374 375 |
# File 'lib/private_collections.rb', line 369 def articles(collection_id:, impersonate: nil, &block) args = {} args['impersonate'] = impersonate unless impersonate.nil? args['offset'] = 0 args['limit'] = 100 # Looks to respect this. The default is 10! get_paginate(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
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'lib/private_collections.rb', line 393 def articles_add(collection_id:, articles:, impersonate: nil, &block) # Adding articles that are already in the collection causes an error, so we remove the duplicates existing_articles = [] self.articles(collection_id: collection_id, impersonate: impersonate) { |a| existing_articles << a['id'] } insert_list = [] articles.each { |article| insert_list << article unless existing_articles.include?(article) } args = {} args['impersonate'] = impersonate unless impersonate.nil? # There is a 10 article limit, for one add. No idea why (0...insert_list.length).step(10) do |offset| eor = offset + 10 # end of range eor = articles.length if eor > articles.length # Truncate range, if beyond end of the array post( api_query: "account/collections/#{collection_id}/articles", args: args, data: { articles: insert_list[offset...eor] }, &block) end 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)
415 416 417 418 419 |
# File 'lib/private_collections.rb', line 415 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
312 313 314 315 316 |
# File 'lib/private_collections.rb', line 312 def (collection_id:, author_id:, impersonate: nil) args = {} args['impersonate'] = impersonate unless impersonate.nil? delete(api_query: "account/collections/#{collection_id}/authors/#{}", args: args, &block) end |
#authors(collection_id:, impersonate: nil) {|Hash| ... } ⇒ Object
Yield collections authors
278 279 280 281 282 |
# File 'lib/private_collections.rb', line 278 def (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
290 291 292 293 294 |
# File 'lib/private_collections.rb', line 290 def (collection_id:, authors:, impersonate: nil) args = {} args['impersonate'] = impersonate unless impersonate.nil? post(api_query: "account/collections/#{collection_id}/authors", args: args, data: { 'authors' => }, &block) end |
#authors_replace(collection_id:, authors:, impersonate: nil) ⇒ Object
Replace existing authors list with a new list
301 302 303 304 305 |
# File 'lib/private_collections.rb', line 301 def (collection_id:, authors:, impersonate: nil) args = {} args['impersonate'] = impersonate unless impersonate.nil? put(api_query: "account/collections/#{collection_id}/authors", args: args, data: { 'authors' => }, &block) end |
#body(title:, description: nil, is_metadata_record: nil, metadata_reason: nil, tags: nil, keywords: nil, references: nil, categories: nil, categories_by_source_id: nil, authors: nil, custom_fields: nil, custom_fields_list: nil, defined_type: nil, funding: nil, funding_list: nil, license: nil, doi: nil, handle: nil, resource_doi: nil, resource_title: nil, timeline: nil, group_id: nil) ⇒ Object
Create a body for use with create and update methods
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/private_collections.rb', line 112 def body( title:, description: nil, is_metadata_record: nil, metadata_reason: nil, tags: nil, keywords: nil, references: nil, categories: nil, categories_by_source_id: nil, authors: nil, custom_fields: nil, custom_fields_list: nil, defined_type: nil, funding: nil, funding_list: nil, license: nil, doi: nil, handle: nil, resource_doi: nil, resource_title: nil, timeline: nil, group_id: nil ) body_ = { 'title' => title } body_['description'] = description unless description.nil? body_['is_metadata_record'] = unless .nil? body_['metadata_reason'] = unless .nil? body_['tags'] = unless .nil? body_['keywords'] = keywords unless keywords.nil? body_['references'] = references unless references.nil? body_['categories'] = categories unless categories.nil? body_['categories_by_source_id'] = categories_by_source_id unless categories_by_source_id.nil? = [] if .instance_of?(Array) .each do || << if .instance_of?(Hash) else { 'name' => } end end end body_['authors'] = body_['custom_fields'] = custom_fields unless custom_fields.nil? body_['custom_fields_list'] = custom_fields_list unless custom_fields_list.nil? body_['defined_type'] = defined_type unless defined_type.nil? body_['funding'] = funding unless funding.nil? body_['funding_list'] = funding_list unless funding_list.nil? body_['license'] = license unless license.nil? body_['doi'] = doi unless doi.nil? body_['handle'] = handle unless handle.nil? body_['resource_doi'] = resource_doi unless resource_doi.nil? body_['resource_title'] = resource_title unless resource_title.nil? body_['timeline'] = timeline unless timeline.nil? body_['group_id'] = group_id unless group_id.nil? return body_ end |
#categories(collection_id:, impersonate: nil) {|Hash| ... } ⇒ Object
Yield collection categories
323 324 325 326 327 |
# File 'lib/private_collections.rb', line 323 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
336 337 338 339 340 |
# File 'lib/private_collections.rb', line 336 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
358 359 360 361 362 |
# File 'lib/private_collections.rb', line 358 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
347 348 349 350 351 |
# File 'lib/private_collections.rb', line 347 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
187 188 189 190 191 |
# File 'lib/private_collections.rb', line 187 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
247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/private_collections.rb', line 247 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
177 178 179 180 181 |
# File 'lib/private_collections.rb', line 177 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)
198 199 200 201 202 |
# File 'lib/private_collections.rb', line 198 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 |
#link_create(collection_id:, expires_date: nil, read_only: true, impersonate: nil) {|Hash| ... } ⇒ Object
Create new private link for this collection
450 451 452 453 454 455 456 457 |
# File 'lib/private_collections.rb', line 450 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 |
#link_delete(collection_id:, link_id:, impersonate: nil, &block) ⇒ Object
Disable/delete private link for this collection
464 465 466 467 468 |
# File 'lib/private_collections.rb', line 464 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 |
#link_update(collection_id:, link_id:, expires_date: nil, read_only: true, impersonate: nil, &block) ⇒ Object
Update private link for this collection
476 477 478 479 480 481 482 483 |
# File 'lib/private_collections.rb', line 476 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 |
#links(collection_id:, impersonate: nil) {|Hash| ... } ⇒ Object
List private links
437 438 439 440 441 |
# File 'lib/private_collections.rb', line 437 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
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.
267 268 269 270 271 |
# File 'lib/private_collections.rb', line 267 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
220 221 222 223 224 |
# File 'lib/private_collections.rb', line 220 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
231 232 233 234 235 |
# File 'lib/private_collections.rb', line 231 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
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.to_i if institute 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
209 210 211 212 213 |
# File 'lib/private_collections.rb', line 209 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 |