-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from jhudsl/cansavvy/fig.alt-2
Cansavvy's attempts at getting fig.alt's to sync between Google slides and Rmd
- Loading branch information
Showing
34 changed files
with
984 additions
and
143 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,5 @@ tests/testthat/googlesheets_token.rds | |
run_test.R | ||
/doc/ | ||
/Meta/ | ||
.secrets | ||
inst/extdata/tmp/default* |
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 |
---|---|---|
@@ -1,49 +1,50 @@ | ||
Type: Package | ||
Package: ottrpal | ||
Version: 1.1.1 | ||
Title: Companion Tools for Open-Source Tools for Training Resources (OTTR) | ||
Description: Tools for converting Open-Source Tools for Training Resources (OTTR) | ||
courses into Leanpub or Coursera courses. 'ottrpal' is for use with the OTTR Template repository to create courses. | ||
Authors@R: c(person(given = "Candace",family = "Savonen", | ||
email = "[email protected]", | ||
role = c("aut", "cre"), | ||
comment = c(ORCID = "0000-0001-6331-7070")), | ||
person(given = "John",family = "Muschelli", | ||
email = "[email protected]", | ||
role = c("aut"), | ||
comment = c(ORCID = "0000-0001-6469-1750")), | ||
person(given = "Carrie", family = "Wright", | ||
email = "[email protected]", | ||
role = c("ctb")) | ||
Version: 1.1.1 | ||
Authors@R: c( | ||
person("Candace", "Savonen", , "[email protected]", role = c("aut", "cre"), | ||
comment = c(ORCID = "0000-0001-6331-7070")), | ||
person("John", "Muschelli", , "[email protected]", role = "aut", | ||
comment = c(ORCID = "0000-0001-6469-1750")), | ||
person("Carrie", "Wright", , "[email protected]", role = "ctb") | ||
) | ||
Depends: R (>= 3.5.0) | ||
Description: Tools for converting Open-Source Tools for Training Resources | ||
(OTTR) courses into Leanpub or Coursera courses. 'ottrpal' is for use | ||
with the OTTR Template repository to create courses. | ||
License: GPL-3 | ||
Imports: dplyr, | ||
httr, | ||
fs, | ||
rmarkdown (>= 2.10), | ||
xml2, | ||
rvest, | ||
readr, | ||
R.utils, | ||
URL: https://github.com/jhudsl/ottrpal | ||
BugReports: https://github.com/jhudsl/ottrpal/issues | ||
Depends: | ||
R (>= 3.5.0) | ||
Imports: | ||
bookdown, | ||
glue, | ||
curl, | ||
rprojroot, | ||
dplyr, | ||
fs, | ||
glue, | ||
httr, | ||
jsonlite, | ||
knitr (>= 1.33), | ||
magrittr, | ||
yaml, | ||
openssl, | ||
purrr, | ||
R.utils, | ||
readr, | ||
rmarkdown (>= 2.10), | ||
rprojroot, | ||
rvest, | ||
stringr, | ||
knitr (>= 1.33), | ||
purrr | ||
xml2, | ||
yaml | ||
Suggests: | ||
remotes, | ||
testthat, | ||
tibble, | ||
utils | ||
VignetteBuilder: | ||
knitr | ||
ByteCompile: true | ||
Encoding: UTF-8 | ||
LazyData: true | ||
ByteCompile: true | ||
Type: Package | ||
VignetteBuilder: knitr | ||
URL: https://github.com/jhudsl/ottrpal | ||
BugReports: https://github.com/jhudsl/ottrpal/issues | ||
RoxygenNote: 7.2.3 |
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,125 @@ | ||
.tokenEnv <- new.env(parent = emptyenv()) | ||
.tokenEnv$Token <- NULL | ||
|
||
# Set token to environment | ||
set_token <- function(value) { | ||
.tokenEnv$Token <- value | ||
return(value) | ||
} | ||
|
||
# Get token from environment | ||
get_token <- function() { | ||
.tokenEnv$Token | ||
} | ||
|
||
### Declare all the scopes | ||
scopes_list <- c( | ||
"https://www.googleapis.com/auth/drive", | ||
"https://www.googleapis.com/auth/drive.file", | ||
"https://www.googleapis.com/auth/drive.readonly", | ||
"https://www.googleapis.com/auth/presentations", | ||
"https://www.googleapis.com/auth/presentations.readonly" | ||
) | ||
|
||
|
||
#' Authorize R package to access the Google Slides API | ||
#' @description This is a function to authorize the R package to access the Google Slides API interactively. | ||
#' @param token An output from \code{\link{oauth2.0_token}} to set as the authentication token. | ||
#' @param cache Should the token be cached as an .httr-oauth file? | ||
#' @param ... Additional arguments to send to \code{\link{oauth2.0_token}} | ||
#' @return OAuth token saved to the environment so the package can use the users' Google data | ||
#' @importFrom utils menu installed.packages | ||
#' @importFrom httr oauth_app oauth_endpoints oauth2.0_token | ||
#' @export | ||
#' @examples \dontrun{ | ||
#' | ||
#' authorize() | ||
#' } | ||
authorize <- function(token = NULL, cache = FALSE, ...) { | ||
if (!cache) { | ||
cache_it <- menu(c("Yes store credentials as .httr-oauth file", "No do not store credentials, I will re-run this authorize() in my next R session")) | ||
if (cache_it == 1) { | ||
message("You chose to cache your credentials, if you change your mind, just delete the .httr-oauth. Be careful not to push this file to GitHub or share it anywhere.") | ||
} | ||
} else { | ||
cache_it <- 1 | ||
} | ||
if (is.null(token)) { | ||
token <- httr::oauth2.0_token( | ||
endpoint = app_set_up()$endpoint, | ||
app = app_set_up()$app, | ||
cache = cache_it == 1, | ||
scope = scopes_list, | ||
... | ||
) | ||
} | ||
set_token(token) | ||
return(invisible(token)) | ||
} | ||
|
||
#' Use secrets to authorize R package to access Google Slides API | ||
#' @description This is a function to authorize the R package to access the Google Slides API. If no | ||
#' client.id and client.secret is provided, the package would provide predefined values. | ||
#' @param access_token Access token can be obtained from running authorize() interactively: token <-authorize(); token$credentials$access_token | ||
#' @param refresh_token Refresh token can be obtained from running authorize() interactively: token <-authorize(); token$credentials$refresh_token | ||
#' @return OAuth token saved to the environment so the package can use the users' Google data | ||
#' @importFrom utils menu installed.packages | ||
#' @importFrom httr oauth_app oauth_endpoints oauth2.0_token | ||
#' @importFrom openssl aes_cbc_decrypt | ||
#' @export | ||
#' @examples \dontrun{ | ||
#' | ||
#' token <- authorize() | ||
#' | ||
#' auth_from_secret( | ||
#' token$credentials$access_token, | ||
#' token$credentials$refresh_token | ||
#' ) | ||
#' } | ||
#' | ||
auth_from_secret <- function(access_token = NULL, refresh_token = NULL) { | ||
|
||
# If no tokens are specified, we'll grab the default ones. | ||
if (is.null(access_token) | is.null(refresh_token)) { | ||
decrypted <- openssl::aes_cbc_decrypt( | ||
readRDS(encrypt_creds_user_path()), | ||
key = readRDS(key_encrypt_creds_path()) | ||
) | ||
access_token <- unserialize(decrypted)[[1]]$access_token | ||
refresh_token <- unserialize(decrypted)[[1]]$refresh_token | ||
} | ||
|
||
credentials <- list( | ||
access_token = access_token, | ||
expires_in = 3599L, | ||
refresh_token = refresh_token, | ||
scope = scopes_list, | ||
token_type = "Bearer" | ||
) | ||
|
||
token <- httr::oauth2.0_token( | ||
endpoint = app_set_up()$endpoint, | ||
app = app_set_up()$app, | ||
scope = scopes_list, | ||
credentials = credentials | ||
) | ||
|
||
set_token(token) | ||
return(invisible(token)) | ||
} | ||
|
||
# This sets up the app creds no matter which way authorization is called | ||
app_set_up <- function() { | ||
decrypted <- openssl::aes_cbc_decrypt( | ||
readRDS(encrypt_creds_path()), | ||
key = readRDS(key_encrypt_creds_path()) | ||
) | ||
app <- httr::oauth_app( | ||
appname = "ottrpal", | ||
key = unserialize(decrypted)$client_id, | ||
secret = unserialize(decrypted)$client_secret | ||
) | ||
endpoint <- httr::oauth_endpoints("google") | ||
|
||
return(list(app = app, endpoint = endpoint)) | ||
} |
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
Oops, something went wrong.