Skip to content

Api keys #131

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

Merged
merged 3 commits into from
Jul 7, 2023
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
16 changes: 0 additions & 16 deletions R/epidatacall.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,22 +184,6 @@ fetch_classic <- function(epidata_call, fields = NULL, disable_data_frame_parsin
response <- request_impl(epidata_call, "classic", fields)
response_content <- httr::content(response, as = "text", encoding = "UTF-8")

# TODO Temporary workaround the first row of the response being a comment
# Remove on 2023-06-21
if (grepl("This request exceeded", response_content) && !epidata_call$only_supports_classic) {
response_content <- jsonlite::fromJSON(response_content, simplifyDataFrame = FALSE)
message <- response_content$epidata[[1L]]
cli::cli_abort(c(
"epidata warning, promoted to error: {message}",
"i" = "Either:",
"*" = "set the environment variable DELPHI_EPIDATA_KEY, or",
"*" = 'set the option "delphi.epidata.key":',
" " = '{.code options(delphi.epidata.key = "YOUR_KEY_OR_TEMP_KEY")}',
"To save your key for later sessions (and hide it from your code), you can edit your .Renviron file with:",
"*" = "usethis::edit_r_environ()"
))
}

response_content <- jsonlite::fromJSON(response_content, simplifyDataFrame = !disable_data_frame_parsing)

# success is 1, no results is -2, truncated is 2, -1 is generic error
Expand Down
27 changes: 13 additions & 14 deletions tests/testthat/test-epidatacall.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,20 @@ test_that("fetch_tbl warns on non-success", {
.package = "httr"
)
# TODO: Turn these tests back on, when the API is fully online
# Remove on 2023-06-21
# artificial_warning <- "* This is a warning with a leading asterisk and {braces} to make sure we don't have bulleting/glue bugs."
# debug_triplet <- readRDS(testthat::test_path("data/test-classic.rds")) %>%
# jsonlite::fromJSON() %>%
# `[[<-`("message", artificial_warning)
# local_mocked_bindings(
# # see generation code above
# fromJSON = function(...) debug_triplet,
# .package = "jsonlite"
# )
artificial_warning <- "* This is a warning with a leading asterisk and {braces} to make sure we don't have bulleting/glue bugs."
debug_triplet <- readRDS(testthat::test_path("data/test-classic.rds")) %>%
jsonlite::fromJSON() %>%
`[[<-`("message", artificial_warning)
local_mocked_bindings(
# see generation code above
fromJSON = function(...) debug_triplet,
.package = "jsonlite"
)

# expect_warning(epidata_call %>% fetch_tbl(),
# regexp = paste0("epidata warning: ", artificial_warning),
# fixed = TRUE
# )
expect_warning(epidata_call %>% fetch_tbl(),
regexp = paste0("epidata warning: ", artificial_warning),
fixed = TRUE
)
})

test_that("classic only fetch", {
Expand Down
2 changes: 1 addition & 1 deletion vignettes/endpoints.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Example call:

```{r}
del <- delphi(system = "ec", epiweek = 201501) %>% fetch()
names(del[[1L]]$forecast)
names(del$forecast)
```

### FluSurv hospitalization data
Expand Down