Skip to content

Commit

Permalink
#133 fix getRecords
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Nov 1, 2023
1 parent 1c40598 commit 139d4c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
29 changes: 20 additions & 9 deletions R/ZenodoManager.R
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ ZenodoManager <- R6Class("ZenodoManager",
#' @param exact object of class \code{logical} indicating if exact matching has to be applied. Default is \code{TRUE}
#' @param quiet object of class \code{logical} indicating if logs have to skipped. Default is \code{FALSE}
#' @return a list of \code{ZenodoRecord}
getDepositions = function(q = "", size = 10, all_versions = FALSE, exact = FALSE,
getDepositions = function(q = "", size = 10, all_versions = FALSE, exact = TRUE,
quiet = FALSE){
page <- 1
baseUrl <- "user/records"
Expand Down Expand Up @@ -1210,24 +1210,35 @@ ZenodoManager <- R6Class("ZenodoManager",
#' @param exact object of class \code{logical} indicating if exact matching has to be applied. Default is \code{TRUE}
#' @param quiet object of class \code{logical} indicating if logs have to skipped. Default is \code{FALSE}
#' @return a list of \code{ZenodoRecord}
getRecords = function(q = "", size = 10, all_versions = FALSE, exact = FALSE){
getRecords = function(q = "", size = 10, all_versions = FALSE, exact = TRUE){
page <- 1
req <- sprintf("records/?q=%s&size=%s&page=%s", URLencode(q), size, page)
req <- sprintf("records?q=%s&size=10page=%s", URLencode(q), page)
if(all_versions) req <- paste0(req, "&allversions=1")
zenReq <- ZenodoRequest$new(private$url, "GET_WITH_CURL", req,
zenReq <- ZenodoRequest$new(private$url, "GET", req,
token = self$getToken(),
logger = self$loggerType)
logger = NULL)
zenReq$execute()
out <- NULL
total = 0
if(zenReq$getStatus() == 200){
resp <- zenReq$getResponse()
records <- resp$hits$hits
total <- resp$hits$total
if(total > 10000){
self$WARN(sprintf("Total of %s records found: the Zenodo API limits to a maximum of 10,000 records!", total))
}
}

req <- sprintf("records?q=%s&size=%s&page=%s", URLencode(q), size, page)
if(all_versions) req <- paste0(req, "&allversions=1")
zenReq <- ZenodoRequest$new(private$url, "GET_WITH_CURL", req,
token = self$getToken(),
logger = self$loggerType)
zenReq$execute()
out <- NULL
if(zenReq$getStatus() == 200){
resp <- zenReq$getResponse()
total_remaining <- total
hasRecords <- length(resp)>0
records = resp
hasRecords <- length(records)>0
while(hasRecords){
out <- c(out, lapply(records, ZenodoRecord$new))
self$INFO(sprintf("Successfully fetched list of published records - page %s", page))
Expand All @@ -1242,7 +1253,7 @@ ZenodoManager <- R6Class("ZenodoManager",
}else{
#next
page <- page+1
nextreq <- sprintf("records/?q=%s&size=%s&page=%s", URLencode(q), size, page)
nextreq <- sprintf("records?q=%s&size=%s&page=%s", URLencode(q), size, page)
if(all_versions) nextreq <- paste0(nextreq, "&allversions=1")
zenReq <- ZenodoRequest$new(private$url, "GET_WITH_CURL", nextreq,
token = self$getToken(),
Expand Down
9 changes: 2 additions & 7 deletions man/ZenodoManager.Rd

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

0 comments on commit 139d4c6

Please sign in to comment.