Skip to content

Commit

Permalink
Remove mm_authorize()
Browse files Browse the repository at this point in the history
  • Loading branch information
asadow committed Nov 29, 2023
1 parent 0437be2 commit a05848e
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 220 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by roxygen2: do not edit by hand

export(mm_authorize)
export(mm_get)
export(mm_get_col_info)
export(mm_get_criteria)
Expand Down
97 changes: 0 additions & 97 deletions R/authorize.R

This file was deleted.

2 changes: 1 addition & 1 deletion R/env.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ mm_url <- function() {
#' @keywords internal
testing_key <- function() {
httr2::secret_decrypt(
"4E5GlxeUybPJnCQQnwyDGsPIncZI526gyfk",
"A0RezbBRC8_7F2uGNHujFBDfSAy5hukOeWU",
"MEGAMATION_KEY_HTTR2"
)
}
4 changes: 2 additions & 2 deletions R/get.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' @returns A data frame of class [`tbl_df`][tibble::tbl_df-class]
#' containing the endpoint's appendix.
#' @export
#' @examplesIf megamation:::mm_has_creds()
#' @examplesIf megamation:::has_creds()
#' mm_get_col_info("status")
mm_get_col_info <- function(endpoint) {
description <- filter_enabled <- NULL
Expand Down Expand Up @@ -82,7 +82,7 @@ mm_get_labels <- function(endpoint) {
#' @returns A data frame of class [`tbl_df`][tibble::tbl_df-class]
#' containing the requested data.
#' @export
#' @examplesIf megamation:::mm_has_creds()
#' @examplesIf megamation:::has_creds()
#' # Get all work orders from Jan. 2023 containing trades ADMIN and IT:
#'
#' # First create a Date-type vector
Expand Down
4 changes: 2 additions & 2 deletions R/request.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' does the following:
#'
#' * Inserts the base URL using the environment variable `MEGAMATION_URL` from
#' your [.Renviron]. Your key and base URL can be set using [mm_authorize()].
#' your [.Renviron].
#' * Appends the URL with the endpoint defined by parameter `endpoint`.
#' * Sets the user-agent as the GitHub [megamation] package.
#' * Authenticates the request with HTTP basic authentication using
Expand All @@ -21,7 +21,7 @@
#' https://apidocs.megamation.com/.
#' @returns An object of class `httr2_request`.
#' @keywords internal
#' @examplesIf megamation:::mm_has_creds()
#' @examplesIf megamation:::has_creds()
#' megamation:::mm_request("timecard")
#' megamation:::mm_request("trade")
mm_request <- function(endpoint) {
Expand Down
24 changes: 22 additions & 2 deletions R/utils-check.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
#' Are there credentials on hand?
#'
#' @family low-level API functions
#' @keywords internal
#' @returns `TRUE` if user has `MEGAMATION_KEY` and `MEGAMATION_URL` environment
#' variables.
has_creds <- function() {
creds <- c(
key = Sys.getenv("MEGAMATION_KEY"),
url = Sys.getenv("MEGAMATION_URL")
)
!any(creds == "")
}

# Are httr2 parameters well-specified
check_params <- function(x, call = rlang::caller_env()) {
np <- names(x)
Expand Down Expand Up @@ -46,8 +60,14 @@ check_creds <- function() {

if (any(creds == "")) {
cli::cli_abort(c(
"Megamation API key and/or URL need registering:",
i = "Use {.fun mm_authorize}"
"Missing credentials.",
"i" = "Run {.fun usethis::edit_r_environ} to open your `.Renviron` file.
Edit in these lines and restart R to apply your credentials to all
sessions.",
">" = "`MEGAMATION_KEY = <your-key>`",
">" = "`MEGAMATION_URL = <your-URL>`",
"i" = "`Sys.setenv()` is another option that applies only to the current
session."
))
}

Expand Down
14 changes: 6 additions & 8 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ knitr::opts_chunk$set(
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%",
eval = megamation:::mm_has_creds()
eval = megamation:::has_creds()
)
```

```{r eval = !megamation:::mm_has_creds(), echo = FALSE, comment = NA}
message("No credentials available. Code chunks will not be evaluated.")
```{r eval = !megamation:::has_creds(), echo = FALSE, comment = NA}
message("Missing credentials. Code chunks will not be evaluated.")
```

```{r, include = FALSE}
Expand Down Expand Up @@ -59,13 +59,11 @@ library(megamation)

## Authorization

`mm_authorize()` installs your API credentials in your `.Renviron`, a safe place for secrets.
Run `usethis::edit_r_environ()` to install your API credentials in your `.Renviron`, a safe place for secrets.

``` {r, eval = FALSE}
mm_authorize(
key = "<YOUR-MEGAMATION_KEY>",
url = "<YOUR-MEGAMATION_URL>"
)
MEGAMATION_KEY = '<YOUR-MEGAMATION_KEY>'
MEGAMATION_URL = '<YOUR-MEGAMATION_URL>'
```

The following functions will automatically use your credentials, so you don't have to expose them in your code.
Expand Down
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ library(megamation)

## Authorization

`mm_authorize()` installs your API credentials in your `.Renviron`, a
safe place for secrets.
Run `usethis::edit_r_environ()` to install your API credentials in your
`.Renviron`, a safe place for secrets.

``` r
mm_authorize(
key = "<YOUR-MEGAMATION_KEY>",
url = "<YOUR-MEGAMATION_URL>"
)
MEGAMATION_KEY = '<YOUR-MEGAMATION_KEY>'
MEGAMATION_URL = '<YOUR-MEGAMATION_URL>'
```

The following functions will automatically use your credentials, so you
Expand Down
2 changes: 1 addition & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ reference:
- mm_parsed_extract
- mm_resp_extract
- mm_pagebind
- mm_has_creds
- has_creds
- mm_key
- mm_url
- mm_get_appendix
Expand Down
8 changes: 4 additions & 4 deletions man/mm_has_creds.Rd → man/has_creds.Rd

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

44 changes: 0 additions & 44 deletions man/mm_authorize.Rd

This file was deleted.

2 changes: 1 addition & 1 deletion man/mm_get.Rd

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

2 changes: 1 addition & 1 deletion man/mm_get_col_info.Rd

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

4 changes: 2 additions & 2 deletions man/mm_request.Rd

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

Loading

0 comments on commit a05848e

Please sign in to comment.