Struct factorio_mod_api::ModPortalClient
source · pub struct ModPortalClient { /* private fields */ }
Expand description
A simple caching client for the Factorio mod portal API.
Implementations§
source§impl ModPortalClient
impl ModPortalClient
sourcepub fn new() -> Result<ModPortalClient>
pub fn new() -> Result<ModPortalClient>
Creates a new client with default configuration.
sourcepub fn with_client(client: Client) -> Result<ModPortalClient>
pub fn with_client(client: Client) -> Result<ModPortalClient>
Creates a new client with a pre-configured reqwest::Client
.
sourcepub async fn get_mod_spec(&self, name: &str) -> Result<&FullModSpec>
pub async fn get_mod_spec(&self, name: &str) -> Result<&FullModSpec>
Get the full spec of a Factorio mod. Request results are cached in memory.
Example
use factorio_mod_api::ModPortalClient;
let client = ModPortalClient::new()?;
let spec = client.get_mod_spec("my_mod").await?;
println!("{}", spec.created_at);
sourcepub async fn login(&self, user_name: &str, password: &str) -> Result<ApiToken>
pub async fn login(&self, user_name: &str, password: &str) -> Result<ApiToken>
Get a login token needed to invoke authenticated APIs.
Example
use factorio_mod_api::ModPortalClient;
use semver::Version;
let client = ModPortalClient::new()?;
let token = client.login("my_user", "my_password").await?;
client.download_mod("my_mod", &Version::parse("1.0.0")?, &token);
sourcepub async fn download_mod(
&self,
mod_name: &str,
version: &Version,
api_token: &ApiToken
) -> Result<Bytes>
pub async fn download_mod(
&self,
mod_name: &str,
version: &Version,
api_token: &ApiToken
) -> Result<Bytes>
Download a mod from the mod portal.
This is an authenticated endpoint that needs a login token to be
obtained with ModPortalClient::login
first.
Example
use factorio_mod_api::ModPortalClient;
use semver::Version;
let client = ModPortalClient::new()?;
let token = client.login("my_user", "my_password").await?;
let bytes = client.download_mod("my_mod", &Version::parse("1.0.0")?, &token).await?;
std::fs::write("my_mod_1.0.0.zip", bytes)?;