Skip to content
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

replaced single-shot HTTP requests with RETRY() #113

Closed
wants to merge 7 commits into from
Closed
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
6 changes: 1 addition & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ export(gh_tree_remote)
export(gh_whoami)
importFrom(cli,cli_status)
importFrom(cli,cli_status_update)
importFrom(httr,DELETE)
importFrom(httr,GET)
importFrom(httr,PATCH)
importFrom(httr,POST)
importFrom(httr,PUT)
importFrom(httr,RETRY)
importFrom(httr,add_headers)
importFrom(httr,content)
importFrom(httr,headers)
Expand Down
3 changes: 1 addition & 2 deletions R/gh-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
# The following block is used by usethis to automatically manage
# roxygen namespace tags. Modify with care!
## usethis namespace: start
#' @importFrom httr content add_headers headers status_code http_type GET POST
#' PATCH PUT DELETE
#' @importFrom httr content add_headers headers status_code http_type RETRY
#' @importFrom jsonlite fromJSON toJSON
#' @importFrom utils URLencode capture.output
#' @importFrom cli cli_status cli_status_update
Expand Down
13 changes: 6 additions & 7 deletions R/gh.R
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,12 @@ gh_response_length <- function(res) {
}

gh_make_request <- function(x) {
valid_http_methods <- c("GET", "POST", "PATCH", "PUT", "DELETE")
http_method <- x$method
if (is.null(http_method) || !(http_method %in% valid_http_methods)) throw(new_error("Unknown HTTP verb"))

method_fun <- list("GET" = GET, "POST" = POST, "PATCH" = PATCH,
"PUT" = PUT, "DELETE" = DELETE)[[x$method]]
if (is.null(method_fun)) throw(new_error("Unknown HTTP verb"))

raw <- do.call(method_fun,
compact(list(url = x$url, query = x$query, body = x$body,
add_headers(x$headers), x$dest)))
raw <- do.call(RETRY,
compact(list(verb = http_method, url = x$url, query = x$query, body = x$body,
add_headers(x$headers), x$dest, terminate_on = c(400, 401, 403, 404))))
raw
}