A Token object has a token string and a key.

Details

A Token object can get API data via an API URL.

Methods

Public methods


Method new()

Initializes a new Credentials object.

Usage

Token$new(token, auth_type = "Bearer")

Arguments

token

a string for token

auth_type

type of HTTP authentication. Should be Bearer or Basic. Default is Bearer

Returns

An object of class Token


Method get_api_response()

Get API response

Usage

Token$get_api_response(url)

Arguments

url

a character of API URL

Returns

An object of class response

Examples

\dontrun{
myProfile <- Token$new("abc1234567890")
url <- "https://httpbin.org/json"
api_response <- myProfile$get_api_response(url)
}


Method get_api_data()

Get API data

Usage

Token$get_api_data(url, fromCSV = FALSE, ...)

Arguments

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.

Returns

a dataframe (fromCSV = TRUE) or a list containing a dataframe and its metadata (fromCSV = TRUE)

Examples

\dontrun{
myProfile <- Token$new("abc1234567890")
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 get_api_graph()

Get API graph

Usage

Token$get_api_graph(url, file_ext = ".png")

Arguments

url

a character of API URL

file_ext

a non-empty character vector giving the file extension. Default is .png.

Returns

A list containing an api_response object and a path to a time series graph in .png format

Examples

\dontrun{
myProfile <- Token$new("abc1234567890")
url <- "https://httpbin.org/image/png"
api_data_graph <- myProfile$get_api_graph(url)
names(api_data_graph)
img <- png::readPNG(api_data_graph$graph)
grid::grid.raster(img)
}


Method clone()

The objects of this class are cloneable with this method.

Usage

Token$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples


## ------------------------------------------------
## Method `Token$get_api_response`
## ------------------------------------------------

if (FALSE) {
myProfile <- Token$new("abc1234567890")
url <- "https://httpbin.org/json"
api_response <- myProfile$get_api_response(url)
}

## ------------------------------------------------
## Method `Token$get_api_data`
## ------------------------------------------------

if (FALSE) {
myProfile <- Token$new("abc1234567890")
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 `Token$get_api_graph`
## ------------------------------------------------

if (FALSE) {
myProfile <- Token$new("abc1234567890")
url <- "https://httpbin.org/image/png"
api_data_graph <- myProfile$get_api_graph(url)
names(api_data_graph)
img <- png::readPNG(api_data_graph$graph)
grid::grid.raster(img)
}