Skip to content

Commit d1d0939

Browse files
authored
Merge pull request #179 from cmu-delphi/fixAPIKey
fix+chore: version bump, fix #177
2 parents d422f56 + afd94ad commit d1d0939

File tree

5 files changed

+43
-16
lines changed

5 files changed

+43
-16
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.0.0
2+
current_version = 1.1.0
33
commit = False
44
tag = False
55

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: epidatr
22
Type: Package
33
Title: Client for Delphi's 'Epidata' API
4-
Version: 1.0.0
4+
Version: 1.1.0
55
Date: 2023-09-11
66
Authors@R:
77
c(

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# epidatr 1.1.0
2+
- renamed the mostly internal `get_auth_key` to `get_api_key`
3+
- added `set_api_key` to more easily set the option
4+
- various CRAN submission related doc-fixes
5+
- fixed some errors from passing "" as a key
6+
17
# epidatr 1.0.0
28

39
- Add `set_cache` and other caching functions.

R/constants.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
version <- "1.0.0"
1+
version <- "1.1.0"
22
http_headers <- httr::add_headers("User-Agent" = paste0("epidatr/", version), "Accept-Encoding" = "gzip")
33
global_base_url <- "https://api.delphi.cmu.edu/epidata/"

R/request.R

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,44 @@ join_url <- function(url, endpoint) {
2424
#' @keywords internal
2525
do_request <- function(url, params, timeout_seconds = 30) {
2626
# don't retry in case of certain status codes
27-
res <- httr::RETRY("GET",
28-
url = url,
29-
query = params,
30-
terminate_on = c(400, 401, 403, 405, 414, 500),
31-
http_headers,
32-
httr::authenticate("epidata", get_api_key()),
33-
httr::timeout(timeout_seconds)
34-
)
35-
if (res$status_code == 414) {
36-
res <- httr::RETRY("POST",
27+
key <- get_api_key()
28+
if (key != "") {
29+
res <- httr::RETRY("GET",
3730
url = url,
38-
body = params,
39-
encode = "form",
31+
query = params,
4032
terminate_on = c(400, 401, 403, 405, 414, 500),
4133
http_headers,
42-
httr::authenticate("epidata", get_api_key())
34+
httr::authenticate("epidata", get_api_key()),
35+
httr::timeout(timeout_seconds)
4336
)
37+
} else {
38+
res <- httr::RETRY("GET",
39+
url = url,
40+
query = params,
41+
terminate_on = c(400, 401, 403, 405, 414, 500),
42+
http_headers,
43+
httr::timeout(timeout_seconds)
44+
)
45+
}
46+
if (res$status_code == 414) {
47+
if (key != "") {
48+
res <- httr::RETRY("POST",
49+
url = url,
50+
body = params,
51+
encode = "form",
52+
terminate_on = c(400, 401, 403, 405, 414, 500),
53+
http_headers,
54+
httr::authenticate("epidata", get_api_key())
55+
)
56+
} else {
57+
res <- httr::RETRY("POST",
58+
url = url,
59+
body = params,
60+
encode = "form",
61+
terminate_on = c(400, 401, 403, 405, 414, 500),
62+
http_headers
63+
)
64+
}
4465
}
4566
res
4667
}

0 commit comments

Comments
 (0)