From a4a6da0f627d5432bb6fdfa42c2cbe6bfce6dd06 Mon Sep 17 00:00:00 2001 From: dsweber2 Date: Fri, 15 Sep 2023 17:07:44 -0700 Subject: [PATCH 1/2] fix+chore: version bump, fix #177 --- .bumpversion.cfg | 2 +- DESCRIPTION | 2 +- NEWS.md | 6 ++++++ R/constants.R | 2 +- R/request.R | 47 +++++++++++++++++++++++++++++++++------------- man/get_api_key.Rd | 4 ++-- 6 files changed, 45 insertions(+), 18 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index c4459027..23851e7c 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.0.0 +current_version = 1.1.0 commit = False tag = False diff --git a/DESCRIPTION b/DESCRIPTION index 6f00eb30..7f94c34a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: epidatr Type: Package Title: Client for Delphi's 'Epidata' API -Version: 1.0.0 +Version: 1.1.0 Date: 2023-09-11 Authors@R: c( diff --git a/NEWS.md b/NEWS.md index 9dd1990e..661b3340 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# epidatr 1.1.0 +- renamed the mostly internal `get_auth_key` to `get_api_key` +- added `set_api_key` to more easily set the option +- various CRAN submission related doc-fixes +- fixed some errors from passing "" as a key + # epidatr 1.0.0 - Add `set_cache` and other caching functions. diff --git a/R/constants.R b/R/constants.R index b00768ca..1fbc4add 100644 --- a/R/constants.R +++ b/R/constants.R @@ -1,3 +1,3 @@ -version <- "1.0.0" +version <- "1.1.0" http_headers <- httr::add_headers("User-Agent" = paste0("epidatr/", version), "Accept-Encoding" = "gzip") global_base_url <- "https://api.delphi.cmu.edu/epidata/" diff --git a/R/request.R b/R/request.R index d6fd5ea3..1e3be1b4 100644 --- a/R/request.R +++ b/R/request.R @@ -24,23 +24,44 @@ join_url <- function(url, endpoint) { #' @keywords internal do_request <- function(url, params, timeout_seconds = 30) { # don't retry in case of certain status codes - res <- httr::RETRY("GET", - url = url, - query = params, - terminate_on = c(400, 401, 403, 405, 414, 500), - http_headers, - httr::authenticate("epidata", get_api_key()), - httr::timeout(timeout_seconds) - ) - if (res$status_code == 414) { - res <- httr::RETRY("POST", + key <- get_api_key() + if (key != "") { + res <- httr::RETRY("GET", url = url, - body = params, - encode = "form", + query = params, terminate_on = c(400, 401, 403, 405, 414, 500), http_headers, - httr::authenticate("epidata", get_api_key()) + httr::authenticate("epidata", get_api_key()), + httr::timeout(timeout_seconds) ) + } else { + res <- httr::RETRY("GET", + url = url, + query = params, + terminate_on = c(400, 401, 403, 405, 414, 500), + http_headers, + httr::timeout(timeout_seconds) + ) + } + if (res$status_code == 414) { + if (key != "") { + res <- httr::RETRY("POST", + url = url, + body = params, + encode = "form", + terminate_on = c(400, 401, 403, 405, 414, 500), + http_headers, + httr::authenticate("epidata", get_api_key()) + ) + } else { + res <- httr::RETRY("POST", + url = url, + body = params, + encode = "form", + terminate_on = c(400, 401, 403, 405, 414, 500), + http_headers + ) + } } res } diff --git a/man/get_api_key.Rd b/man/get_api_key.Rd index 18f7ae65..40774c66 100644 --- a/man/get_api_key.Rd +++ b/man/get_api_key.Rd @@ -52,7 +52,7 @@ Delphi Epidata API Registration Form. \url{https://api.delphi.cmu.edu/epidata/admin/registration_form} } \seealso{ -\code{\link[usethis:edit_r_environ]{usethis::edit_r_environ()}} to automatically edit the \code{.Renviron} -file; \code{\link[usethis:edit_r_profile]{usethis::edit_r_profile()}} to automatically edit the \code{.Rprofile} +\code{\link[usethis:edit]{usethis::edit_r_environ()}} to automatically edit the \code{.Renviron} +file; \code{\link[usethis:edit]{usethis::edit_r_profile()}} to automatically edit the \code{.Rprofile} file } From afd94adb64b2ee590973785e3f6ad190550efca6 Mon Sep 17 00:00:00 2001 From: dsweber2 Date: Sat, 16 Sep 2023 00:14:03 +0000 Subject: [PATCH 2/2] docs: document (GHA) --- man/get_api_key.Rd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/man/get_api_key.Rd b/man/get_api_key.Rd index 40774c66..18f7ae65 100644 --- a/man/get_api_key.Rd +++ b/man/get_api_key.Rd @@ -52,7 +52,7 @@ Delphi Epidata API Registration Form. \url{https://api.delphi.cmu.edu/epidata/admin/registration_form} } \seealso{ -\code{\link[usethis:edit]{usethis::edit_r_environ()}} to automatically edit the \code{.Renviron} -file; \code{\link[usethis:edit]{usethis::edit_r_profile()}} to automatically edit the \code{.Rprofile} +\code{\link[usethis:edit_r_environ]{usethis::edit_r_environ()}} to automatically edit the \code{.Renviron} +file; \code{\link[usethis:edit_r_profile]{usethis::edit_r_profile()}} to automatically edit the \code{.Rprofile} file }