valorant_api 0.0.4

A library for interacting with the ingame Valorant-API.
Documentation
use std::env;
use valorant_api::utils::credentials_manager::CredentialsManager;
use valorant_api::utils::network::http_client::{HttpClient, HttpClientError, SimpleHttpClient};

pub fn get_http_client() -> Result<SimpleHttpClient, HttpClientError> {
    SimpleHttpClient::new()
}

pub async fn get_credentials_manager<T: HttpClient>(
    http_client: &T,
) -> Result<CredentialsManager, String> {
    let username = env::var("valo_user").map_err(|_| {
        "Error while getting username. Please define a env variable called 'valo_user'"
    })?;
    let password = env::var("valo_pass").map_err(|_| {
        "Error while getting password. Please define a env variable called 'valo_pass'"
    })?;
    let username = username.as_str();
    let password = password.as_str();
    let mut credentials_manager = CredentialsManager::new();
    match credentials_manager
        .authenticate(http_client, username, password)
        .await
    {
        Ok(_) => Ok(credentials_manager),
        Err(e) => Err(format!("Error while authenticating: {}", e)),
    }
}