R/api_key.R

Defines functions save_api_key read_api_key check_saved_api_key

Documented in save_api_key

#' Register an API key to make requests
#'
#' Saves an RDS file in the current working directory to store API credentials.
#' All API-dependent functions will fail until you have done this.
#' Register for a personal API key here: https://admiraltyapi.portal.azure-api.net/
#'
#' @param api_key a valid Admirality API Key
#' @export


save_api_key <- function(api_key) {
  readr::write_rds(api_key, "api_key")
}

read_api_key <- function(){
  readr::read_rds("api_key")
}

check_saved_api_key <- function(){

  if(!file.exists("api_key")){

    stop("No saved API key found. Before requesting data use save_api_key()")

  }

}
simon-tarr/uk.tides documentation built on March 29, 2020, 9:21 p.m.