-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add auth functions and add arg to covidcast #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a221b31
27fef14
4e33de1
5c40309
8062be1
5bccc8e
558008e
4feaade
ba86c69
88e3479
21d66b2
17e9f1d
a745d6f
960988d
a445a3c
05f36b7
d50ad40
4eed5f2
6d22ede
5a96125
1c67308
2fa0cfa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#' Get the API key | ||
#' | ||
#' Get the API key from the environment variable DELPHI_EPIDATA_KEY or getOption("delphi.epidata.key") | ||
#' | ||
#' @param verbose Will print the source of the key if TRUE (e.g. options, environment, or config file) | ||
#' @return The API key | ||
#' | ||
#' @export | ||
get_auth_key <- function() { | ||
key <- Sys.getenv("DELPHI_EPIDATA_KEY", unset = "") | ||
if (key != "") { | ||
return(key) | ||
} | ||
|
||
key <- getOption("delphi.epidata.key", default = "") | ||
if (key != "") { | ||
return(key) | ||
} | ||
|
||
rlang::warn( | ||
c( | ||
"No API key found. You will be limited to non-complex queries and encounter rate limits if you proceed.", | ||
"To avoid this, you can get your key [here] and then:", | ||
"i" = "set the environment variable DELPHI_EPIDATA_KEY", | ||
"i" = "set the option 'delphi.epidata.key'", | ||
"", | ||
"To save your key for later sessions (and hide it from your code), you can edit your .Renviron file with:", | ||
"i" = "usethis::edit_r_environ()" | ||
), | ||
use_cli_format = TRUE, | ||
.frequency = "regularly", | ||
.frequency_id = "delphi.epidata.key" | ||
) | ||
return("") | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
test_that("get_auth_key", { | ||
options(delphi.epidata.key = "epidata") | ||
expect_equal(get_auth_key(), "epidata") | ||
options(delphi.epidata.key = NULL) | ||
Sys.setenv(DELPHI_EPIDATA_KEY = "epidata") | ||
expect_equal(get_auth_key(), "epidata") | ||
Sys.setenv(DELPHI_EPIDATA_KEY = "") | ||
}) | ||
|
||
test_that("authenticate", { | ||
response <- httr::RETRY("GET", "https://httpbin.org/headers", httr::authenticate("epidata", get_auth_key())) | ||
expect_equal( | ||
content(response)$headers$Authorization, | ||
paste0("Basic ", base64enc::base64encode(charToRaw("epidata:"))) | ||
) | ||
response <- httr::RETRY("GET", "https://httpbin.org/headers", httr::authenticate("epidata", "epidata")) | ||
expect_equal( | ||
content(response)$headers$Authorization, | ||
paste0("Basic ", base64enc::base64encode(charToRaw("epidata:epidata"))) | ||
) | ||
}) |
Uh oh!
There was an error while loading. Please reload this page.