Skip to content

Commit

Permalink
#5 iterate to get all depositions, size param added for flexibility
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Jun 10, 2019
1 parent 8c442ed commit be71d0e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
27 changes: 21 additions & 6 deletions R/ZenodoManager.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
#' \item{\code{getCommunityById(id)}}{
#' Get community by Id
#' }
#' \item{\code{getDepositions()}}{
#' Get the list of Zenodo records deposited in your Zenodo workspace
#' \item{\code{getDepositions(size)}}{
#' Get the list of Zenodo records deposited in your Zenodo workspace. By defaut
#' the list of depositions will be returned by page with a size of 10 results per
#' page (default size of the Zenodo API).
#' }
#' \item{\code{depositRecord(record, publish)}}{
#' A method to deposit/update a Zenodo record. The record should be an object
Expand Down Expand Up @@ -240,14 +242,27 @@ ZenodoManager <- R6Class("ZenodoManager",
#------------------------------------------------------------------------------------------

#getDepositions
getDepositions = function(){
zenReq <- ZenodoRequest$new(private$url, "GET", "deposit/depositions",
getDepositions = function(size = 10){
page <- 1
zenReq <- ZenodoRequest$new(private$url, "GET", sprintf("deposit/depositions?size=%s&page=%s", size, page),
token = private$token, logger = self$loggerType)
zenReq$execute()
out <- NULL
if(zenReq$getStatus() == 200){
out <- lapply(zenReq$getResponse(), ZenodoRecord$new)
self$INFO("Successfuly fetched list of depositions")
resp <- zenReq$getResponse()
hasRecords <- length(resp)>0
while(hasRecords){
out <- c(out, lapply(resp, ZenodoRecord$new))
self$INFO("Successfuly fetched list of depositions - page %s")
#next
page <- page+1
zenReq <- ZenodoRequest$new(private$url, "GET", sprintf("deposit/depositions?size=%s&page=%s", size, page),
token = private$token, logger = self$loggerType)
zenReq$execute()
resp <- zenReq$getResponse()
hasRecords <- length(resp)>0
}
self$INFO("Successfuly fetched list of depositions!")
}else{
out <- zenReq$getResponse()
self$ERROR(sprintf("Error while fetching depositions: %s", out$message))
Expand Down
6 changes: 4 additions & 2 deletions man/ZenodoManager.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/zen4R.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit be71d0e

Please sign in to comment.