R/get.R

Defines functions sr_get

Documented in sr_get

#' Call the speedrun.com API
#'
#' @param path API path.
#' @param ... Optional parameters
#'
#' @return The [httr::content] of the API response.
#' @export
#'
#' @examples
#' \dontrun{
#' # Get all users
#' sr_get(path = "users")
#' }
sr_get <- function(path = "", ...) {
  if (grepl(getOption("speedruncom_base"), path)) {
    url <- path
  } else {
    url <- paste0(getOption("speedruncom_base"), path)
  }

  url <- httr::modify_url(
    url = url,
    query = list(...)
  )

  res <- httr::GET(url)
  httr::warn_for_status(res)
  res <- httr::content(res)

  res
}
jemus42/speedrunr documentation built on March 19, 2024, 2:35 p.m.