R/ona_misc.R

Defines functions ona_configure

Documented in ona_configure

################################################################################
#
#'
#' Configure HTTP headers
#'
#' @param auth_mode Password or token? Default is token.
#'
#' @return An object of class request for HTTP requests
#'
#' @export
#'
#
################################################################################

ona_configure <- function(auth_mode = c("token", "password")) {
  ##
  auth_mode <- match.arg(auth_mode)

  ##
  if (auth_mode == "password") {
    config <- httr::authenticate(
      user = Sys.getenv(x = "ONA_USERNAME"),
      password = Sys.getenv(x = "ONA_PASSWORD")
    )
  } else {
    config <- httr::add_headers(
      "Authorization" = paste("Token", Sys.getenv(x = "ONA_TOKEN"), sep = " ")
    )
  }
}
rapidsurveys/odktools documentation built on Jan. 5, 2025, 9:32 a.m.