Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.0.0
current_version = 1.1.0
commit = False
tag = False

Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion R/constants.R
Original file line number Diff line number Diff line change
@@ -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/"
47 changes: 34 additions & 13 deletions R/request.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}