Skip to content

Commit

Permalink
Merge pull request #112 from generable/use-httpcache
Browse files Browse the repository at this point in the history
use httpcache
  • Loading branch information
jburos authored Sep 29, 2023
2 parents 286ffe1 + 7b44deb commit 08710fe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ Imports:
table1,
reticulate,
boot,
cli
cli,
httpcache
Suggests:
testthat,
knitr,
Expand Down
5 changes: 3 additions & 2 deletions R/geco_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ get_auth <- function() {
}

#' @import httr
#' @importFrom httpcache GET POST
#' @importFrom RJSONIO fromJSON
geco_api <- function(path, ..., method = c('GET', 'POST'), project = NULL, project_version_id = NULL, run_id=NULL, type=NULL, parameter=NULL, filters=NULL, url_query_parameters=NULL) {
url <- geco_api_url(path, project = project, project_version_id = project_version_id, run_id=run_id, type=type, parameter=parameter, filters=filters, url_query_parameters=url_query_parameters)
Expand All @@ -103,9 +104,9 @@ geco_api <- function(path, ..., method = c('GET', 'POST'), project = NULL, proje

method <- match.arg(method, several.ok = FALSE)
if (method == 'GET')
resp <- try(httr::GET(url, ..., get_auth(), ua))
resp <- try(httpcache::GET(url, ..., get_auth(), ua))
else if (method == 'POST')
resp <- try(httr::POST(url, ..., ua))
resp <- try(httpcache::POST(url, ..., ua))
#if (httr::http_type(resp) != "application/json") {
# stop("API did not return json", call. = FALSE)
#}
Expand Down

0 comments on commit 08710fe

Please sign in to comment.