pub struct FtClient { /* private fields */ }
Expand description
The client struct, used to make requests to the API.
You can create a client with the from_app
method.
Implementations§
Source§impl FtClient
impl FtClient
Sourcepub fn from_app<U: Into<String>, S: Into<String>>(
app_uid: U,
app_secret: S,
) -> Result<Self>
pub fn from_app<U: Into<String>, S: Into<String>>( app_uid: U, app_secret: S, ) -> Result<Self>
Creates a new client for a v2 application, providing the application’s UID and secret.
use ft_rs::FtClient;
let client = FtClient::from_app("my_uid", "my_super_secret_secret");
§Errors
This method will return an error if the reqwest client could not be built, or if the UID or secret are invalid.
Sourcepub async fn fetch_token(&self) -> Result<AccessToken>
pub async fn fetch_token(&self) -> Result<AccessToken>
Fetches a new access token from the API.
This method will return the last valid token if it is still valid, as per the API’s documentation.
Note that the API Client will automatically fetch a new token if the last one is expired, so there is no need to call this method manually.
§Example
use ft_rs::FtClient;
#[tokio::main]
async fn main() -> ft_rs::Result<()> {
let client = FtClient::from_app("my_uid", "my_super_secret_secret")?;
let token = client.fetch_token().await?;
println!("Token: {:?}", token);
Ok(())
}
Sourcepub async fn ensure_valid_token(&mut self) -> Result<()>
pub async fn ensure_valid_token(&mut self) -> Result<()>
Ensures that the last valid token is still valid, and fetches a new one if it is not.
This method is called automatically by the API Client when making a request, so there is no need to call it manually.