├── .Rbuildignore ├── .gitignore ├── .travis.yml ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── R ├── zen_auth.R ├── zen_collection_create.R ├── zen_collection_delete.R ├── zen_collection_list.R ├── zen_collection_retrieve.R ├── zen_collection_update.R ├── zen_file_create.R ├── zen_file_delete.R ├── zen_file_edit.R ├── zen_file_list.R ├── zen_file_publish.R ├── zen_file_retrieve.R ├── zen_file_sort.R ├── zen_file_update.R ├── zen_utils.R └── zenodo-package.R ├── README.md ├── man-roxygen └── access_token.R ├── man ├── zen_collections.Rd ├── zen_create.Rd └── zenodo-package.Rd ├── tests ├── testthat.R └── testthat │ ├── test-collections.R │ ├── test-fileops.R │ └── test-misc.R └── zenodo.Rproj /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^\.travis\.yml$ 2 | ^.*\.Rproj$ 3 | ^\.Rproj\.user$ 4 | man-roxygen 5 | local.R -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ###R### 2 | 3 | # History files 4 | .Rhistory 5 | 6 | # Example code in package build process 7 | *-Ex.R 8 | 9 | # R data files from past sessions 10 | .Rdata 11 | local.R 12 | 13 | # RStudio files 14 | .Rproj.user/ 15 | 16 | local.R 17 | .Rproj.user 18 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Sample .travis.yml for R projects from https://github.com/craigcitro/r-travis 2 | 3 | language: c 4 | 5 | before_install: 6 | - curl -OL http://raw.github.com/craigcitro/r-travis/master/scripts/travis-tool.sh 7 | - chmod 755 ./travis-tool.sh 8 | - ./travis-tool.sh bootstrap 9 | 10 | install: 11 | - ./travis-tool.sh install_deps 12 | 13 | script: ./travis-tool.sh run_tests 14 | 15 | on_failure: 16 | - ./travis-tool.sh dump_logs 17 | 18 | notifications: 19 | email: 20 | on_success: change 21 | on_failure: change 22 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: zenodo 2 | Title: Programmatic Interface to the Zenodo Research Data Archive 3 | Version: 0.1.99 4 | Authors@R: c(person("Karthik", "Ram", role = c("aut", "cre"), 5 | email = "karthik.ram@gmail.com"), 6 | person("Gregory", "Jefferis", role = "aut", 7 | email = "jefferis@gmail.com")) 8 | Description: A full interface to the Zenodo API, includes support for uploading your research outputs. 9 | Depends: R (>= 3.2) 10 | License: MIT + file LICENSE 11 | LazyData: true 12 | Imports: 13 | assertthat, 14 | data.table, 15 | dplyr, 16 | httr, 17 | jsonlite 18 | Suggests: testthat 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2015 2 | COPYRIGHT HOLDER: Karthik Ram -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2 (4.1.1): do not edit by hand 2 | 3 | export(zen_collections) 4 | export(zen_create) 5 | import(jsonlite) 6 | importFrom(assertthat,assert_that) 7 | importFrom(httr,POST) 8 | importFrom(httr,content) 9 | -------------------------------------------------------------------------------- /R/zen_auth.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | zen_auth <- function(key = "", secret = "") { 5 | # Once completed, this fn will allow for 6 | # automatic authentication. 7 | # For now, it's just as easy to add a token 8 | # to one's R profile to use the remaining endpoints 9 | } 10 | -------------------------------------------------------------------------------- /R/zen_collection_create.R: -------------------------------------------------------------------------------- 1 | 2 | # Description Create a new deposition resource. 3 | # URL https://zenodo.org/api/deposit/depositions 4 | # Method POST 5 | # Request headers Content-Type: application/json 6 | # Scopes deposit:write 7 | # Success response 8 | # Code: 201 Created 9 | # Body: a deposition resource. 10 | 11 | #' Create a collection on Zenodo 12 | #' 13 | #' @param collection_name Name of a new collection to be created on Zenodo 14 | #' @template access_token 15 | #' @export 16 | #' @importFrom httr POST content 17 | #' @importFrom assertthat assert_that 18 | zen_create <- function(collection_name = NULL, access_token = getOption('zenodo_token')) { 19 | assert_that(!is.null(collection_name)) # no empty collection 20 | # TODO: Check to see if collection exists 21 | create_url <- "https://zenodo.org/api/deposit/depositions" 22 | response <- POST() 23 | results <- content(response) 24 | results 25 | } 26 | -------------------------------------------------------------------------------- /R/zen_collection_delete.R: -------------------------------------------------------------------------------- 1 | # Description Delete an existing deposition resource. Note, only unpublished depositions may be deleted. 2 | # URL https://zenodo.org/api/deposit/depositions/:id 3 | # Method DELETE 4 | # Scopes deposit:write 5 | # URL parameters 6 | # Required: 7 | # id: Deposition identifier 8 | # Success response 9 | # Code: 204 No Content 10 | # Body: Empty. 11 | # Error response 12 | # 404 Not found: Deposition does not exist. 13 | # 403 Forbidden: Deleting an already published deposition. 14 | # See also HTTP status codes (400 and 500 series errors) and error responses. 15 | 16 | -------------------------------------------------------------------------------- /R/zen_collection_list.R: -------------------------------------------------------------------------------- 1 | 2 | #' List Zenodo collections. 3 | #' 4 | #' List all depositions for the currently authenticated user. Collections 5 | #' typically archive all outputs of a research project. 6 | #' @template access_token 7 | #' @export 8 | #' @examples \dontrun{ 9 | #' my_collections <- zen_collections() 10 | #' } 11 | zen_collections <- function(access_token = getOption('zenodo_token')) { 12 | dir_path <- "https://zenodo.org/api/deposit/depositions" 13 | args <- as.list(c(access_token = access_token)) 14 | results <- httr::GET(dir_path, query = args) 15 | request <- httr::content(results) 16 | process_hitter_response(request) 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /R/zen_collection_retrieve.R: -------------------------------------------------------------------------------- 1 | # Description Retrieve a single deposition resource. 2 | # URL https://zenodo.org/api/deposit/depositions/:id 3 | # Method GET 4 | # URL parameters 5 | # Required: 6 | # id: Deposition identifier 7 | # Success response 8 | # Code: 200 OK 9 | # Body: a deposition resource. -------------------------------------------------------------------------------- /R/zen_collection_update.R: -------------------------------------------------------------------------------- 1 | # Description Update an existing deposition resource. 2 | # URL https://zenodo.org/api/deposit/depositions/:id 3 | # Method PUT 4 | # Request headers Content-Type: application/json 5 | # Scopes deposit:write 6 | # URL parameters 7 | # Required: 8 | # id: Deposition identifier 9 | # Data parameters 10 | # A deposition metadata resource. Example: 11 | 12 | # { 13 | # "metadata": { 14 | # "upload_type": "presentation", 15 | # ... 16 | # } 17 | # } 18 | # Success response 19 | # Code: 200 OK 20 | # Body: a deposition resource. -------------------------------------------------------------------------------- /R/zen_file_create.R: -------------------------------------------------------------------------------- 1 | # Description Upload a new file. 2 | # URL https://zenodo.org/api/deposit/depositions/:id/files 3 | # Method POST 4 | # Request headers Content-Type: multipart/form-data 5 | # Scopes deposit:write 6 | # URL parameters 7 | # Required: 8 | # id: Deposition identifier 9 | # Data parameters 10 | # Success response 11 | # Code: 201 Created 12 | # Body: a deposition file resource. 13 | # Error response See HTTP status codes (400 and 500 series errors) and error responses. -------------------------------------------------------------------------------- /R/zen_file_delete.R: -------------------------------------------------------------------------------- 1 | # Description Delete an existing deposition file resource. Note, only deposition files for unpublished depositions may be deleted. 2 | # URL https://zenodo.org/api/deposit/depositions/:id/files/:file_id 3 | # Method DELETE 4 | # Scopes deposit:write 5 | # URL parameters 6 | # Required: 7 | # id: Deposition identifier 8 | # file_id: Deposition file identifier 9 | # Success response 10 | # Code: 204 No Content 11 | # Body: Empty. 12 | # Error response 13 | # 404 Not found: Deposition file does not exist. 14 | # 403 Forbidden: Deleting an already published deposition. 15 | # See also HTTP status codes (400 and 500 series errors) and error responses. -------------------------------------------------------------------------------- /R/zen_file_edit.R: -------------------------------------------------------------------------------- 1 | # Description Unlock already submitted deposition for editing. 2 | # URL https://zenodo.org/api/deposit/depositions/:id/actions/edit 3 | # Method POST 4 | # Request headers None 5 | # Scopes deposit:actions 6 | # URL parameters 7 | # Required: 8 | # id: Deposition identifier 9 | # Success response 10 | # Code: 201 Created 11 | # Body: a deposition resource. -------------------------------------------------------------------------------- /R/zen_file_list.R: -------------------------------------------------------------------------------- 1 | # Description List all deposition files for a given deposition. 2 | # URL https://zenodo.org/api/deposit/depositions/:id/files 3 | # Method GET 4 | # URL parameters 5 | # Required: 6 | # id: Deposition identifier 7 | # Success response 8 | # Code: 200 OK 9 | # Body: an array of deposition file resources. 10 | # Error response See HTTP status codes (400 and 500 series errors) and error responses. -------------------------------------------------------------------------------- /R/zen_file_publish.R: -------------------------------------------------------------------------------- 1 | 2 | # Description Publish a deposition. Note, once a deposition is published, you can no longer delete it. 3 | # URL https://zenodo.org/api/deposit/depositions/:id/actions/publish 4 | # Method POST 5 | # Request headers None 6 | # Scopes deposit:actions 7 | # URL parameters 8 | # Required: 9 | # id: Deposition identifier 10 | # Success response 11 | # Code: 202 Accepted 12 | # Body: a deposition resource. 13 | # Error response See HTTP status codes (400 and 500 series errors) and error responses. -------------------------------------------------------------------------------- /R/zen_file_retrieve.R: -------------------------------------------------------------------------------- 1 | # Description Retrieve a single deposition file. 2 | # URL https://zenodo.org/api/deposit/depositions/:id/files/:file_id 3 | # Method GET 4 | # URL parameters 5 | # Required: 6 | # id: Deposition identifier 7 | # file_id: Deposition file identifier 8 | # Success response 9 | # Code: 200 OK 10 | # Body: a deposition file resource. 11 | # Error response See HTTP status codes (400 and 500 series errors) and error responses. -------------------------------------------------------------------------------- /R/zen_file_sort.R: -------------------------------------------------------------------------------- 1 | # Description Sort the files for a deposition. By default, the first file is shown in the file preview. 2 | # URL https://zenodo.org/api/deposit/depositions/:id/files 3 | # Method PUT 4 | # Request headers Content-Type: application/json 5 | # Scopes deposit:write 6 | # URL parameters 7 | # Required: 8 | # id: Deposition identifier 9 | # Data parameters 10 | # A JSON array of partial deposition file resources with only the id attribute. Example: 11 | 12 | # [ 13 | # {"id": ""}, 14 | # {"id": ""}, 15 | # ... 16 | # ] 17 | # Success response 18 | # Code: 200 OK 19 | # Body: an array of deposition file resources. -------------------------------------------------------------------------------- /R/zen_file_update.R: -------------------------------------------------------------------------------- 1 | # Description Update a deposition file resource. Currently the only use is renaming an already uploaded file. If you one to replace the actual file, please delete the file and upload a new file. 2 | # URL https://zenodo.org/api/deposit/depositions/:id/files/:file_id 3 | # Method PUT 4 | # Request headers Content-Type: application/json 5 | # Scopes deposit:write 6 | # URL parameters 7 | # Required: 8 | # id: Deposition identifier 9 | # file_id: Deposition file identifier 10 | # Data parameters 11 | # A partial deposition file resources with only the filename attributes. Example: 12 | 13 | # { 14 | # "filename": "" 15 | # } 16 | # Success response 17 | # Code: 200 OK 18 | # Body: a deposition file resource. 19 | # Error response See HTTP status codes (400 and 500 series errors) and error responses. -------------------------------------------------------------------------------- /R/zen_utils.R: -------------------------------------------------------------------------------- 1 | #' Function abstracts out some standard functionality necessary to 2 | #' handle \code{httr} responses. 3 | #' @noRd 4 | #' @keywords Internal 5 | process_hitter_response <- function(response) { 6 | res <- lapply(response, function(s) data.frame(t(unlist(s)))) 7 | # This could be improved so I don't end up relying on two 8 | # libraries to do the job. 9 | dplyr::tbl_df(data.table::rbindlist(res, fill = TRUE)) 10 | } 11 | 12 | -------------------------------------------------------------------------------- /R/zenodo-package.R: -------------------------------------------------------------------------------- 1 | #' Programmatic access to the Zenodo API 2 | #' 3 | #' @description See \url{https://zenodo.org/dev} for details 4 | #' 5 | #' @name zenodo-package 6 | #' @aliases zenodo 7 | #' @docType package 8 | #' @keywords package 9 | #' @import jsonlite 10 | NULL 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](https://img.shields.io/badge/development-active-blue.svg) [![Build Status](https://travis-ci.org/ropensci/zenodo.svg?branch=master)](https://travis-ci.org/ropensci/zenodo) 2 | 3 | # R interface to Zenodo 4 | ![zenodo_logo](https://zenodo.org/img/logos/zenodo-black-200.png) 5 | 6 | ## What is Zenodo? 7 | Zenodo is an open repository for scientific data based at CERN in Swizerland. Zenodo facilitates researchers to share and preserve _any_ research outputs in any size, any format and from any science. Zenodo also mints DOIs. 8 | 9 | __Setup__ 10 | * Sign up for [zenodo](https://zenodo.org/youraccount/register) 11 | * Log in and go your profile 12 | * Click personal access tokens and grab one. 13 | 14 | Then add the following line to your `.rprofile`. You can also pass this explicitly to every function, but exposing the token will compromise your account. 15 | 16 | ```r 17 | options(zenodo_token = "YOUR-KEY") 18 | ``` 19 | 20 | 21 | __Installing this package__ 22 | 23 | ```r 24 | devtools::install_github("ropensci/rzenodo") 25 | ``` 26 | 27 | ## Functions 28 | 29 | | Function | Description | 30 | |---|---| 31 | | `zenodo_dir()` | Provides a `data.frame` with listing of current Zenodo collections. 32 | 33 | ## Resources 34 | 35 | * The [full API documentation](https://zenodo.org/dev) for the Zenodo API. 36 | 37 | --- 38 | 39 | 40 | [![ropensci_footer](http://ropensci.org/public_images/github_footer.png)](http://ropensci.org) 41 | -------------------------------------------------------------------------------- /man-roxygen/access_token.R: -------------------------------------------------------------------------------- 1 | #' @param access_token Your Zenodo access token 2 | -------------------------------------------------------------------------------- /man/zen_collections.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2 (4.1.1): do not edit by hand 2 | % Please edit documentation in R/zen_collection_list.R 3 | \name{zen_collections} 4 | \alias{zen_collections} 5 | \title{List Zenodo collections.} 6 | \usage{ 7 | zen_collections(access_token = getOption("zenodo_token")) 8 | } 9 | \arguments{ 10 | \item{access_token}{Your Zenodo access token} 11 | } 12 | \description{ 13 | List all depositions for the currently authenticated user. Collections 14 | typically archive all outputs of a research project. 15 | } 16 | \examples{ 17 | \dontrun{ 18 | my_collections <- zen_collections() 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/zen_create.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2 (4.1.1): do not edit by hand 2 | % Please edit documentation in R/zen_collection_create.R 3 | \name{zen_create} 4 | \alias{zen_create} 5 | \title{Create a collection on Zenodo} 6 | \usage{ 7 | zen_create(collection_name = NULL, access_token = getOption("zenodo_token")) 8 | } 9 | \arguments{ 10 | \item{collection_name}{Name of a new collection to be created on Zenodo} 11 | 12 | \item{access_token}{Your Zenodo access token} 13 | } 14 | \description{ 15 | Create a collection on Zenodo 16 | } 17 | 18 | -------------------------------------------------------------------------------- /man/zenodo-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2 (4.1.1): do not edit by hand 2 | % Please edit documentation in R/zenodo-package.R 3 | \docType{package} 4 | \name{zenodo-package} 5 | \alias{zenodo} 6 | \alias{zenodo-package} 7 | \title{Programmatic access to the Zenodo API} 8 | \description{ 9 | See \url{https://zenodo.org/dev} for details 10 | } 11 | \keyword{package} 12 | 13 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(zenodo) 3 | 4 | test_check("zenodo") 5 | -------------------------------------------------------------------------------- /tests/testthat/test-collections.R: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karthik/zenodo/e8fd9304296e8ba2babfe1ca7301fc366b42e28e/tests/testthat/test-collections.R -------------------------------------------------------------------------------- /tests/testthat/test-fileops.R: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karthik/zenodo/e8fd9304296e8ba2babfe1ca7301fc366b42e28e/tests/testthat/test-fileops.R -------------------------------------------------------------------------------- /tests/testthat/test-misc.R: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karthik/zenodo/e8fd9304296e8ba2babfe1ca7301fc366b42e28e/tests/testthat/test-misc.R -------------------------------------------------------------------------------- /zenodo.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: knitr 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageRoxygenize: rd,collate,namespace 22 | --------------------------------------------------------------------------------