-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated package with new NixtlaClient class.
- Loading branch information
Showing
47 changed files
with
98,822 additions
and
39,919 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Version: 1.0.0 | ||
Date: 2024-02-02 04:29:49 UTC | ||
SHA: 16e8099d0af53baa187225d9bc33efad76e1cbca | ||
Date: 2024-02-03 19:44:30 UTC | ||
SHA: a80013ab126ba73c3c0a809177f4ad168e5365dd |
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,27 @@ | ||
#' Get NIXTLA_API_KEY from options or from .Renviron | ||
#' This is a private function of nixtlar | ||
#' | ||
#' @return If available, the NIXTLA_API_KEY. Otherwise it returns an error and a message asking the user to set the API key. | ||
#' @export | ||
#' @keywords internal | ||
#' @examples | ||
#' \dontrun{ | ||
#' .get_api_key() | ||
#' } | ||
#' | ||
.get_api_key <- function(){ | ||
|
||
# Get API key from options | ||
api_key <- Sys.getenv("NIXTLA_API_KEY", unset = NA) | ||
# If not available, get it from .Renviron | ||
if(is.na(api_key)) { | ||
api_key <- getOption("NIXTLA_API_KEY", default = NA) | ||
} | ||
|
||
# Return API key or, if not available, stop | ||
if(!is.na(api_key)){ | ||
return(api_key) | ||
}else{ | ||
stop("Please set NIXTLA_API_KEY. Use nixtla_set_api_key() or set it as an environment variable in .Renviron") | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
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,16 @@ | ||
#' Set API key in global environment | ||
#' | ||
#' @param api_key The user's API key. Get yours here: https://dashboard.nixtla.io/ | ||
#' | ||
#' @return A message indicating the API key has been set in the global environment. | ||
#' @export | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' nixtlar::nixtla_set_api_key("YOUR_API_KEY") | ||
#' } | ||
#' | ||
nixtla_set_api_key <- function(api_key) { | ||
options("NIXTLA_API_KEY"=api_key) | ||
message("API key has been set for the current session.") | ||
} |
This file was deleted.
Oops, something went wrong.
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,30 @@ | ||
#' Validate API key | ||
#' | ||
#' @return A status code and a message indicating whether the API key is valid. | ||
#' @export | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' nixtlar::nixtla_set_api_key("YOUR_API_KEY") | ||
#' nixtlar::nixtla_validate_api_key | ||
#' } | ||
#' | ||
nixtla_validate_api_key <- function(){ | ||
|
||
api_key <- .get_api_key() | ||
|
||
url <- "https://dashboard.nixtla.io/api/forecast" | ||
resp <- httr2::request(url) |> | ||
httr2::req_headers( | ||
Authorization = paste("Bearer", api_key) | ||
) |> | ||
httr2::req_user_agent("nixtla-r") |> | ||
httr2::req_perform() | ||
|
||
status_code <- httr2::resp_status(resp) | ||
if(status_code >= 200 & status_code < 300){ | ||
message("API key validation successful. Happy forecasting! :) \nIf you have questions or need support, please email [email protected]") | ||
}else{ | ||
message("API key validation failed. Please go https://dashboard.nixtla.io/ to get a valid API key.") | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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.