A Credentials
object has a username, a password and a key.
A Credentials
object can get API data via an API URL.
new()
Initializes a new Credentials object.
Credentials$new(username = NULL, password = NULL)
username
a string for username
password
a string for password
A new Credentials
object
get_api_response()
Get API response
Credentials$get_api_response(url)
url
a character of API URL
An object of class response
\dontrun{ myProfile <- Credentials$new(askme("Enter my username: "), askme()) url <- "https://httpbin.org/json" api_response <- myProfile$get_api_response(url) }
get_api_data()
Get API data
Credentials$get_api_data(url, fromCSV = FALSE, ...)
url
a character ofAPI URL
fromCSV
a logical, defines whether data are returned in .csv format or .json format
...
further arguments and CSV parsing parameters to be passed to read_csv
when fromCSV = TRUE
.
a dataframe (fromCSV = TRUE
) or a list containing a dataframe and its metadata (fromCSV = TRUE
)
\dontrun{ myProfile <- Credentials$new(askme("Enter my username: "), askme()) json_url <- "https://httpbin.org/json" api_data_json <- myProfile$get_api_data(json_url) csv_url <- "https://httpbin.org/robots.txt" api_data_csv <- myProfile$get_api_data(csv_url, fromCSV = TRUE) }
get_api_graph()
Get API graph
Credentials$get_api_graph(url, file_ext = ".png")
url
a character of API URL
file_ext
a non-empty character vector giving the file extension. Default is .png
.
A list containing an api_response object and a path to a time series graph in .png format
\dontrun{ myProfile <- Credentials$new(askme("Enter my username: "), askme()) url <- "<url>" api_data_graph <- myProfile$get_api_graph(url) names(api_data_graph) img <- png::readPNG(api_data_graph$graph) grid::grid.raster(img) }
clone()
The objects of this class are cloneable with this method.
Credentials$clone(deep = FALSE)
deep
Whether to make a deep clone.
## ------------------------------------------------ ## Method `Credentials$get_api_response` ## ------------------------------------------------ if (FALSE) { myProfile <- Credentials$new(askme("Enter my username: "), askme()) url <- "https://httpbin.org/json" api_response <- myProfile$get_api_response(url) } ## ------------------------------------------------ ## Method `Credentials$get_api_data` ## ------------------------------------------------ if (FALSE) { myProfile <- Credentials$new(askme("Enter my username: "), askme()) json_url <- "https://httpbin.org/json" api_data_json <- myProfile$get_api_data(json_url) csv_url <- "https://httpbin.org/robots.txt" api_data_csv <- myProfile$get_api_data(csv_url, fromCSV = TRUE) } ## ------------------------------------------------ ## Method `Credentials$get_api_graph` ## ------------------------------------------------ if (FALSE) { myProfile <- Credentials$new(askme("Enter my username: "), askme()) url <- "<url>" api_data_graph <- myProfile$get_api_graph(url) names(api_data_graph) img <- png::readPNG(api_data_graph$graph) grid::grid.raster(img) }