Commit 650972db authored by Matija Obreza's avatar Matija Obreza

Stop if HTTP response <> 200

parent 56b7e794
Package: genesysr
Version: 0.9.1
Title: Genesys PGR Client
Encoding: UTF8
Description: Access data on plant genetic resources from genebanks around the world published on Genesys (<https://www.genesys-pgr.org>).
Your use of data is subject to terms and conditions available at <https://www.genesys-pgr.org/content/legal/terms>.
Authors@R: c(person(family = "Global Crop Diversity Trust", role = c("cph")),
person("Matija", "Obreza", email = "matija.obreza@croptrust.org", role = c("aut", "cre")),
person("Nora", "Castañeda", email = "nora.castaneda@croptrust.org", role = c("ctb")))
person("Nora", "Castaneda", email = "nora.castaneda@croptrust.org", role = c("ctb")))
Maintainer: Matija Obreza <matija.obreza@croptrust.org>
Depends: R (>= 3.1.0)
Imports:
......
......@@ -191,6 +191,7 @@ get <- function(path, query = NULL) {
#' @param path API path
#' @param query query string parameters
#' @param body request body (will be serialized to JSON)
#' @param content.type Content-Type of the body
#'
#' @return httr response
post <- function(path, query = NULL, body = NULL, content.type = "application/json") {
......
......@@ -13,8 +13,8 @@
# limitations under the License.
#' Default page size
FETCH_PAGESIZE <- 100
MAX_ALLOWED_PAGES <- 100
FETCH_PAGESIZE <- 1000
MAX_ALLOWED_PAGES <- 500
#' Who am i?
#'
......@@ -41,6 +41,9 @@ me <- function() {
#' @return Paged data structure
fetch_accessions_page <- function(filters = list(), page = 0, size = FETCH_PAGESIZE, selector = NULL) {
resp <- post(path = "/acn/filter", query=list(p = page, s = size), body = filters)
if (httr::status_code(resp) != 200) {
stop("Genesys responded with HTTP status code ", httr::status_code(resp), ". Expected 200.")
}
paged <- jsonlite::fromJSON(httr::content(resp, "text"), simplifyVector = FALSE)
message(paste("Retrieved page", page + 1, "of", paged$totalPages, "with", paged$numberOfElements, "rows"))
......@@ -84,7 +87,7 @@ fetch_accessions <- function(filters = list(), page = NULL, size = FETCH_PAGESIZ
for (page in 1:pages) {
if (page > MAX_ALLOWED_PAGES) {
# Break if over 100 pages
# Break if over max pages
return(page)
}
p <- fetch_accessions_page(filters, page, size, selector)
......
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