Commit 36843751 authored by Dorchies David's avatar Dorchies David
Browse files

feat(doApiQuery): add check for the limitation of 20000 records

- add functionnality and test

Closes ##5
parent 40960f46
Pipeline #26097 passed with stages
in 1 minute and 44 seconds
......@@ -17,3 +17,6 @@ Imports:
urltools
RoxygenNote: 7.1.1
Roxygen: list(markdown = TRUE)
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
......@@ -86,6 +86,10 @@ doApiQuery <- function(api,
}
} else {
l <- httr::content(resp, "parsed")
if (as.numeric(l$count) > 20000) {
stop("The request reach the API limitation of 20000 records.\n",
"Use filter arguments to reduce the number of records of your request.")
}
data <- c(data, l$data)
if (resp$status_code == 206) {
query <- l$`next`
......
......@@ -38,7 +38,7 @@ Pagination of the queries is handled automatically and the returned \link{list}
\details{
The function \code{get_available_params} returns the list of available query parameters for a given operation in an API.
The functions \verb{get_[api]_[operation]} call the function \code{doQueryApi} and convert the response in a convenient format for the user (\link{data.frame} or \link{tibble})
The functions \verb{get_[api]_[operation]} call the function \code{doQueryApi} and convert the response in a convenient format for the user (\link{data.frame} or \link[tibble:tibble]{tibble::tibble})
}
\examples{
# To get the available APIs in the package
......
library(testthat)
library(hubeau)
test_check("hubeau")
test_that("A query of more than 20000 records", {
expect_error(doApiQuery("indicateurs_services", "communes", params = list()),
regexp = "The request reach the API limitation of 20000 records")
})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment