Title: | Secure and Intuitive Access to 'Plug' Interface |
---|---|
Description: | Provides a secure and user-friendly interface to interact with the 'Plug' <https://plugbytpf.com.br> 'API'. It enables developers to store and manage tokens securely using the 'keyring' package, retrieve data from 'API' endpoints with the 'httr2' package, and handle large datasets with chunked data fetching. Designed for simplicity and security, the package facilitates seamless integration with 'Plug' ecosystem. |
Authors: | Andre Leite [aut, cre], Felipe Ferreira [aut], Hugo Vaconcelos [aut], Diogo Bezerra [aut], Roger Azevedo [aut] |
Maintainer: | Andre Leite <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2025-01-14 12:36:11 UTC |
Source: | https://github.com/strategicprojects/plug |
This function downloads all data from a specified base using the query SELECT * FROM base_name
.
plug_download_base( base_name, endpoint = "https://plug.der.pe.gov.br/MadrixApi/executeQuery", verbosity = 0 )
plug_download_base( base_name, endpoint = "https://plug.der.pe.gov.br/MadrixApi/executeQuery", verbosity = 0 )
base_name |
The name of the base from which to download all data. |
endpoint |
The endpoint URL for executing queries. |
verbosity |
The verbosity level of the API request (0 = none, 1 = minimal, 2 = detailed). |
A tibble containing all data from the specified base.
## Not run: data <- plug_download_base( base_name = "Contratos_VIEW" ) ## End(Not run)
## Not run: data <- plug_download_base( base_name = "Contratos_VIEW" ) ## End(Not run)
This function executes a user-defined SQL query on the Plug database, with safe query construction
using glue_sql
.
plug_execute_query( sql_template, endpoint = "https://plug.der.pe.gov.br/MadrixApi/executeQuery", verbosity = 0, ... )
plug_execute_query( sql_template, endpoint = "https://plug.der.pe.gov.br/MadrixApi/executeQuery", verbosity = 0, ... )
sql_template |
A SQL query template with placeholders for variables. |
endpoint |
The endpoint URL for executing queries. |
verbosity |
The verbosity level of the API request (0 = none, 1 = minimal, 2 = detailed). |
... |
Named arguments to replace placeholders in the SQL template. |
A tibble containing the query results.
## Not run: data <- plug_execute_query(sql_template = "SELECT TOP 1 * FROM Contratos_VIEW") ## End(Not run)
## Not run: data <- plug_execute_query(sql_template = "SELECT TOP 1 * FROM Contratos_VIEW") ## End(Not run)
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 in English ("No valid credentials found.") and return NULL
.
plug_get_valid_token( validity_time = 3600, endpoint = "https://plug.der.pe.gov.br/MadrixApi/authenticate/" )
plug_get_valid_token( validity_time = 3600, endpoint = "https://plug.der.pe.gov.br/MadrixApi/authenticate/" )
validity_time |
The validity period of the token in seconds. Default is 3600 (1 hour). |
endpoint |
The endpoint URL for generating the token. |
The valid token as a string, or NULL
if no valid credentials were found or an error occurred.
## Not run: token <- plug_get_valid_token(validity_time = 3600) ## End(Not run)
## Not run: token <- plug_get_valid_token(validity_time = 3600) ## End(Not run)
This function lists all globally stored credentials (username and password) for the Plug API. If none are found or an error occurs, it displays a message in English ("No credentials found for Plug API.") and returns an empty list.
plug_list_credentials()
plug_list_credentials()
A named list with username
and password
fields if credentials are found,
or an empty list if no credentials are stored.
## Not run: plug_list_credentials() ## End(Not run)
## Not run: plug_list_credentials() ## End(Not run)
This function lists the stored API token and its expiration time for the Plug API. If none are found or an error occurs, it displays a message in English ("No token found for Plug API.") and returns an empty list.
plug_list_tokens()
plug_list_tokens()
A named list with token
and expiration
fields if a token is found,
or an empty list if no token is stored.
## Not run: plug_list_tokens() ## End(Not run)
## Not run: plug_list_tokens() ## End(Not run)
This function securely stores the global username and password required to authenticate with the Plug application.
plug_store_credentials(username, password)
plug_store_credentials(username, password)
username |
The username for the Plug. |
password |
The password for the Plug. |
No return value. The credentials are securely stored.
plug_store_credentials("myusername", "mypassword")
plug_store_credentials("myusername", "mypassword")