-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Showing
4 changed files
with
112 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# [title] Extract the content of an HTTP response into a different format | ||
# [name] .content | ||
# [description] Mainly here to making mocking easier in testing. | ||
# [references] https://testthat.r-lib.org/reference/local_mocked_bindings.html#namespaced-calls | ||
#' @importFrom httr content | ||
.content <- function(response, as) { | ||
return(httr::content(response, as = as)) | ||
} | ||
|
||
# [title] Execute an HTTP request and return the result | ||
# [name] .request | ||
# [description] Mainly here to making mocking easier in testing, but this | ||
# also centralizes the mechanism for HTTP request exexcution in one place. | ||
# [references] https://testthat.r-lib.org/reference/local_mocked_bindings.html#namespaced-calls | ||
#' @importFrom httr RETRY | ||
.request <- function(verb, url, config, body) { | ||
result <- httr::RETRY( | ||
verb = verb | ||
, url = url | ||
, config = config | ||
, body = body | ||
) | ||
return(result) | ||
} | ||
|
||
# [title] Raise an exception if an HTTP response indicates an error | ||
# [name] .stop_for_status | ||
# [description] Mainly here to making mocking easier in testing. | ||
# [references] https://testthat.r-lib.org/reference/local_mocked_bindings.html#namespaced-calls | ||
#' @importFrom httr stop_for_status | ||
.stop_for_status <- function(response) { | ||
httr::stop_for_status(response) | ||
return(invisible(NULL)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters