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)?;Auto Trait Implementations§
impl !Freeze for ModPortalClient
impl !RefUnwindSafe for ModPortalClient
impl Send for ModPortalClient
impl !Sync for ModPortalClient
impl Unpin for ModPortalClient
impl UnsafeUnpin for ModPortalClient
impl !UnwindSafe for ModPortalClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more