diff --git a/DESCRIPTION b/DESCRIPTION index aa23961..634f8ba 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -10,3 +10,6 @@ License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.3 +Imports: + googledrive, + googlesheets4 diff --git a/R/access-files.R b/R/access-files.R index 0a042d1..1ab3f0c 100644 --- a/R/access-files.R +++ b/R/access-files.R @@ -1,19 +1,19 @@ -library("googledrive") +run = FALSE +if (run) +{ + do_auth() -source("api-functions.R") + c4r_drive <- "(C4R) Community for Rigor" -drive_auth(token = decrypt_gdrive_token()) + # get some info about working with google drive + drive_find("Unit Roadmap", shared_drive = c4r_drive) -c4r_drive <- "(C4R) Community for Rigor" + drive_about()$exportFormats -# get some info about working with google drive -drive_find("Unit Roadmap", shared_drive = c4r_drive) - -drive_about()$exportFormats - -# do some stuff -roadmap_file <- drive_find("Unit Roadmap - Sample Size and Power Calculation", - shared_drive = c4r_drive) -downloaded_file <- drive_download(roadmap_file, type = "rtf") + # do some stuff + roadmap_file <- drive_find("Unit Roadmap - Sample Size and Power Calculation", + shared_drive = c4r_drive) + downloaded_file <- drive_download(roadmap_file, type = "rtf") +} diff --git a/R/api-functions.R b/R/api-functions.R index 7aded94..4e37b75 100644 --- a/R/api-functions.R +++ b/R/api-functions.R @@ -1,11 +1,18 @@ +do_auth <- function() +{ + my_token <- decrypt_gdrive_token() + googledrive::drive_auth(token = my_token) + googlesheets4::gs4_auth(token = my_token) +} + decrypt_gdrive_token <- function() { token <- NULL if (gargle:::secret_has_key("GDRIVE_KEY")) { - token <- gargle::secret_read_rds(".secrets/gdrive-token.rds", + token <- gargle::secret_read_rds(".secrets/gdrive-token.rds", key = "GDRIVE_KEY") } - + invisible(token) -} \ No newline at end of file +} diff --git a/R/logging.R b/R/logging.R new file mode 100644 index 0000000..233dd7d --- /dev/null +++ b/R/logging.R @@ -0,0 +1,16 @@ +log_action <- function(action = "", note = "") +{ + my_log <- access_log() + log_row <- data.frame(datetime = format(Sys.time(), "%Y-%M-%d %X %Z"), + action = action, + note = note) + googlesheets4::sheet_append(my_log, log_row) +} + +access_log <- function() +{ + do_auth() + googledrive::drive_get("https://docs.google.com/spreadsheets/d/1n3rmcM94r_RL-QPTEuxP2D2g2BlrB_Hhdw1Ag_FkUsA/edit?usp=sharing") +} + +