Learn R Programming

plug (version 0.2.0)

plug_get_valid_token: Get a valid token for Plug API

Description

This function checks if a valid global token exists for the Plug API. If no valid token is found, it generates a new token using the stored global credentials by sending a properly formatted request. If it fails to retrieve the token (for example, due to missing credentials or network issues), it will not throw an error but will display a message explaining the problem and return NULL.

Usage

plug_get_valid_token(
  validity_time = 3600,
  endpoint = "https://plug.der.pe.gov.br/MadrixApi/authenticate/",
  force = FALSE
)

Value

The valid token as a string, or NULL if no valid credentials were found or an error occurred.

Arguments

validity_time

The validity period of the token in seconds. Default is 3600 (1 hour).

endpoint

The endpoint URL for generating the token.

force

If TRUE, ignores the cached token and always requests a new one.

Examples

Run this code
if (FALSE) {
token <- plug_get_valid_token(validity_time = 3600)
}

Run the code above in your browser using DataLab