Skip to content

Commit

Permalink
Switch to HttpClient()$retry() and document related arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
willgearty committed Dec 12, 2024
1 parent 3316062 commit a76f939
Show file tree
Hide file tree
Showing 31 changed files with 320 additions and 20 deletions.
4 changes: 2 additions & 2 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ rr_GET_raw <- function(path, key = NULL, query = list(), ...) {
opts = list(useragent = rredlist_ua()),
headers = list(Authorization = check_key(key))
)
cli$get(query = ct(query), ...)
cli$retry("GET", query = ct(query), ..., retry_only_on = c(429))
}

#' Handle a GET query of the IUCN API
Expand Down Expand Up @@ -83,7 +83,7 @@ check_internet <- function() {
#' code errors are found, an error is thrown.
#' @noRd
status_catcher <- function(res) {
if (res$status_code >= 300) {
if (res$status_code >= 400) {
if (res$status_code == 401) {
stop("Token not valid! (HTTP 401)", call. = FALSE)
} else if (res$status_code == 404) {
Expand Down
14 changes: 12 additions & 2 deletions man-roxygen/curl.R
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
#' @param ... [Curl options][curl::curl_options()] passed to the GET request via
#' [crul][crul::HttpClient()].
#' @param ... Includes the following arguments related to the wait time between
#' request retries if a "Too Many Requests" error is received from the API
#' (see [HttpClient()$retry()][crul::HttpClient()] for more details):
#' \itemize{
#' \item `pause_base`, `pause_cap`, and `pause_min`: basis, maximum, and minimum
#' for calculating wait time for retry
#' \item `times`: the maximum number of times to retry
#' \item `onwait`: a callback function if the request will be retried and a
#' wait time is being applied
#' }
#' Also supports any [curl options][curl::curl_options()] passed to the GET
#' request via [HttpClient][crul::HttpClient()].
10 changes: 10 additions & 0 deletions man-roxygen/filters.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,15 @@
#' Europe). This is similar to the `region` argument of the old Red List
#' API and old versions of rredlist.
#' }
#' Also includes the following arguments related to the wait time between
#' request retries if a "Too Many Requests" error is received from the API
#' (see [HttpClient()$retry()][crul::HttpClient()] for more details):
#' \itemize{
#' \item `pause_base`, `pause_cap`, and `pause_min`: basis, maximum, and minimum
#' for calculating wait time for retry
#' \item `times`: the maximum number of times to retry
#' \item `onwait`: a callback function if the request will be retried and a
#' wait time is being applied
#' }
#' Also supports any [curl options][curl::curl_options()] passed to the GET
#' request via [HttpClient][crul::HttpClient()].
10 changes: 10 additions & 0 deletions man/rl_actions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions man/rl_assessment.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions man/rl_categories.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions man/rl_class.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions man/rl_comp_groups.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions man/rl_countries.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions man/rl_extinct.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions man/rl_extinct_wild.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions man/rl_family.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions man/rl_faos.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions man/rl_green.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions man/rl_growth_forms.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions man/rl_habitats.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions man/rl_kingdom.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions man/rl_order.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions man/rl_phylum.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions man/rl_pop_trends.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions man/rl_realms.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions man/rl_research.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a76f939

Please sign in to comment.