R/caffeinater.R

Defines functions caff

caff <- function(type) {
  airtable_url <- "https://api.airtable.com/v0/app0OL9RLDepolg5k/caffeine_events"
  request <- httr::POST(
    url = airtable_url,
    httr::add_headers(Authorization = paste("Bearer",
                                            keyring::key_get("airtable-api"))),
    httr::content_type_json(),
    body = list("fields" = list("caffeine_string" = type)),
    encode = "json"
  )
  status <- httr::http_status(request)[["reason"]]
  notify_send <- "C:\\Users\\dlbride\\notify-send.exe"
  substr(type, 1, 1) <- toupper(substr(type, 1, 1))
  ns_args <- c(paste(type, "Status:"), status)
  ps <- sys::exec_background(notify_send, ns_args, std_out = FALSE, std_err = FALSE)
  on.exit(Sys.sleep(1), add = TRUE)
  invisible(ps)
}
danielbride/dfunc documentation built on Jan. 1, 2020, 12:54 a.m.