Skip to content

Commit

Permalink
Remove key param
Browse files Browse the repository at this point in the history
  • Loading branch information
asadow committed Nov 3, 2023
1 parent a9966f1 commit 1f92bac
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 38 deletions.
3 changes: 1 addition & 2 deletions R/modify.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 1 addition & 5 deletions R/perform.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
17 changes: 7 additions & 10 deletions R/request.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
16 changes: 0 additions & 16 deletions R/utils-check.R
Original file line number Diff line number Diff line change
Expand Up @@ -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' = '<your-key>')`,
and {.emph do not} supply {.arg .key}.",
"i" = 'A typo like `kee = <your-secret>`
will end up in the request URL as a filter.'
))
}
return()
}

# Are credentials present
check_creds <- function() {
creds <- c(
Expand Down
6 changes: 1 addition & 5 deletions man/mm_request.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1f92bac

Please sign in to comment.