This package maintains an internal set of API keys which
users can set using setAPIKey()
. These keys will be remembered for
the duration of an R session. In functions that accept an API key argument,
if the passed in API key is NULL
, code will look up an appropriate
named API key to see if that key has been set globally. Setting keys globally
is a convenience that simplifies scripts written by end users.
Currently supported API keys include:
"PurpleAir-read"
-- PurpleAir API_READ_KEY
"PurpleAir-write"
-- PurpleAir API_WRITE_KEY
"Clarity-read"
-- Clarity API_READ_KEY
Character string used to identify an API key. Used as the
first argument to setAPIKey()
and getAPIKey()
.
Character API key. Used as the second argument to setAPIKey()
.
An API key string or a list of provider:key
pairs.
Three API key support functions are imported from the MazamaCoreUtils package where they are described in more detail:
MazamaCoreUtils::getAPIKey
MazamaCoreUtils::setAPIKey
MazamaCoreUtils::showAPIKeys
library(AirSensor2)
# Start out with no keys (unless the user has set them)
showAPIKeys()
#> list()
getAPIKey("PurpleAir-read")
#> NULL
# Set specific keys
setAPIKey("PurpleAir-read", "********-2A00-11EB-A8CD-42010A800126")
setAPIKey("PurpleAir-write", "********-2A00-11EB-A8CD-42010A800126")
showAPIKeys()
#> List of 2
#> $ PurpleAir-read : chr "********-2A00-11EB-A8CD-42010A800126"
#> $ PurpleAir-write: chr "********-2A00-11EB-A8CD-42010A800126"
getAPIKey("PurpleAir-read")
#> [1] "********-2A00-11EB-A8CD-42010A800126"
# Reset the read key
setAPIKey("PurpleAir-read", NULL)
showAPIKeys()
#> List of 1
#> $ PurpleAir-write: chr "********-2A00-11EB-A8CD-42010A800126"
getAPIKey("PurpleAir-read")
#> NULL
# Reset the write key
setAPIKey("PurpleAir-write", NULL)
showAPIKeys()
#> Named list()