diff --git a/R/modify.R b/R/modify.R index ac4180a..30d4f1c 100644 --- a/R/modify.R +++ b/R/modify.R @@ -43,6 +43,5 @@ mm_req_params <- function(req, ..., allfields = TRUE) { check_bool(allfields) params <- format_params(...) if (allfields) params <- c(params, "ALLFIELDS" = 1) - - req <- req |> httr2::req_url_query(!!!params) + httr2::req_url_query(req, !!!params) } diff --git a/R/perform.R b/R/perform.R index fc9e2d4..59389d2 100644 --- a/R/perform.R +++ b/R/perform.R @@ -18,9 +18,5 @@ #' } mm_req_perform <- function(req) { check_request(req) - - req |> - httr2::req_perform_iterative( - next_req = function(resp, req) mm_next_req(resp, req) - ) + httr2::req_perform_iterative(req, next_req = mm_next_req) } diff --git a/R/request.R b/R/request.R index 6985d56..b902229 100644 --- a/R/request.R +++ b/R/request.R @@ -19,23 +19,20 @@ #' `"timecard"` for employee transactions, and `"workorder"` #' for work orders. All endpoints are listed at #' https://apidocs.megamation.com/. -#' @param .url API base URL for request. -#' @param .key API key for request. #' @returns An object of class `httr2_request`. #' @export #' @examplesIf httr2::secret_has_key("HTTR2_KEY_MEGAMATION") #' mm_request("timecard") #' mm_request("trade") -mm_request <- function(endpoint, .url = get_env_url(), .key = get_env_key()) { +mm_request <- function(endpoint) { + check_creds() check_string(endpoint) - check_key(.key) - - httr2::request(.url) |> + agent <- "megamation (https://github.com/asadow/megamation)" + user <- "APIDL" + httr2::request(get_env_url()) |> httr2::req_url_path_append(endpoint) |> - httr2::req_user_agent( - "megamation (https://github.com/asadow/megamation)" - ) |> - httr2::req_auth_basic("APIDL", .key) |> + httr2::req_user_agent(agent) |> + httr2::req_auth_basic(user, get_env_key()) |> httr2::req_error(body = mm_error_body) |> httr2::req_cache(tempdir(), debug = TRUE) } diff --git a/R/utils-check.R b/R/utils-check.R index 279a359..768933f 100644 --- a/R/utils-check.R +++ b/R/utils-check.R @@ -37,22 +37,6 @@ check_request <- function(x, return() } -# Warn when .key is not same as MEGAMATION_KEY -check_key <- function(.key) { - if(.key != get_env_key()) { - cli::cli_warn(c( - "The {.arg .key} you provided is not your - MEGAMATION_KEY environment variable.", - "i" = "It is highly recommended that you run {.fun mm_set_creds}, or - `Sys.setenv('MEGAMATION_KEY' = '')`, - and {.emph do not} supply {.arg .key}.", - "i" = 'A typo like `kee = ` - will end up in the request URL as a filter.' - )) - } - return() -} - # Are credentials present check_creds <- function() { creds <- c( diff --git a/man/mm_request.Rd b/man/mm_request.Rd index 9354af9..ecaf8c0 100644 --- a/man/mm_request.Rd +++ b/man/mm_request.Rd @@ -4,17 +4,13 @@ \alias{mm_request} \title{Create a Megamation API request} \usage{ -mm_request(endpoint, .url = get_env_url(), .key = get_env_key()) +mm_request(endpoint) } \arguments{ \item{endpoint}{The API endpoint. For example, \code{"timecard"} for employee transactions, and \code{"workorder"} for work orders. All endpoints are listed at https://apidocs.megamation.com/.} - -\item{.url}{API base URL for request.} - -\item{.key}{API key for request.} } \value{ An object of class \code{httr2_request}.