-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: change spq_init(), spq_perform(), send_sparql() to move req…
…uest control to spq_init()! (#176)
- Loading branch information
Showing
27 changed files
with
795 additions
and
588 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
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,74 @@ | ||
#' Create the request control object for `spq_init()` | ||
#' | ||
#' @param user_agent a string indicating the user agent to send with the query. | ||
#' @param max_tries,max_seconds Cap the maximal number of | ||
#' attemps with `max_tries` or the total elapsed time from the first request | ||
#' with `max_seconds`. | ||
#' @param timeout maximum number of seconds to wait (`httr2::req_timeout()`). | ||
#' @param request_type a string indicating how the query should be sent: in the | ||
#' URL (`url`, default, most common) or as a body form (`body-form`). | ||
#' @inheritParams httr2::req_throttle | ||
#' | ||
#' @return A list to be used in `spq_init()`'s `request_control` argument. | ||
#' @export | ||
#' | ||
#' @examples | ||
#' # Defaults | ||
#' spq_control_request() | ||
#' # Tweaking values | ||
#' spq_control_request( | ||
#' user_agent = "Jane Doe https://example.com", | ||
#' max_tries = 1L, | ||
#' max_seconds = 10L, | ||
#' timeout = 10L, | ||
#' request_type = "url" | ||
#' ) | ||
spq_control_request <- function(user_agent = getOption("glitter.ua", "glitter R package (https://github.com/lvaudor/glitter)"), | ||
max_tries = getOption("glitter.max_tries", 3L), | ||
max_seconds = getOption("glitter.max_seconds", 120L), | ||
timeout = getOption("glitter.timeout", 1000L), | ||
request_type = c("url", "body-form"), | ||
rate = NULL, | ||
realm = NULL) { | ||
|
||
|
||
if (!is.character(user_agent)) { | ||
cli::cli_abort("Must provide a character as {.arg user_agent}.") | ||
} | ||
|
||
if (!is.integer(max_tries)) { | ||
cli::cli_abort(c( | ||
"Must provide an integer as {.arg max_tries}.", | ||
i = "You provided a {.val {typeof(max_tries)}}." | ||
)) | ||
} | ||
|
||
if (!is.integer(max_seconds)) { | ||
cli::cli_abort(c( | ||
"Must provide an integer as {.arg max_seconds}.", | ||
i = "You provided a {.val {typeof(max_seconds)}}." | ||
)) | ||
} | ||
|
||
if (!is.integer(timeout)) { | ||
cli::cli_abort(c( | ||
"Must provide an integer as {.arg timeout}.", | ||
i = "You provided a {.val {typeof(timeout)}}." | ||
)) | ||
} | ||
|
||
request_type = rlang::arg_match(request_type, c("url", "body-form")) | ||
structure( | ||
list( | ||
user_agent = user_agent, | ||
max_tries = max_tries, | ||
max_seconds = max_seconds, | ||
timeout = timeout, | ||
request_type = request_type, | ||
rate = rate, | ||
realm = realm | ||
), | ||
class = "glitter_request_control" | ||
) | ||
|
||
} |
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
Oops, something went wrong.