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 }