#mod #io #async-io #client #api-client #modding #api-bindings

modio

Rust interface for integrating https://mod.io - a modding API for game developers

27 releases

0.10.1 Apr 11, 2024
0.10.0 Mar 21, 2024
0.9.1 Nov 12, 2023
0.8.0 Jun 26, 2023
0.3.0 Oct 4, 2018

#45 in HTTP client

Download history 13/week @ 2024-01-06 32/week @ 2024-01-13 4/week @ 2024-01-27 71/week @ 2024-02-10 8/week @ 2024-02-17 31/week @ 2024-02-24 38/week @ 2024-03-02 9/week @ 2024-03-09 162/week @ 2024-03-16 18/week @ 2024-03-23 64/week @ 2024-03-30 84/week @ 2024-04-06

329 downloads per month
Used in modbot

MIT/Apache

275KB
7K SLoC

mod.io

Crates.io Released API docs Master API docs Rust version License Workflow Status

modio provides a set of building blocks for interacting with the mod.io API.

The client uses asynchronous I/O, backed by the futures and tokio crates, and requires both to be used alongside.

mod.io

mod.io is a drop-in modding solution from the founders of ModDB.com, that facilitates the upload, search, browsing, downloading and trading of mods in-game.

Usage

To use modio, execute cargo add modio.

Basic Setup

use modio::{Credentials, Modio, Result};

#[tokio::main]
async fn main() -> Result<()> {
    let modio = Modio::new(
        Credentials::new("user-or-game-apikey"),
    )?;

    // create some tasks and execute them
    // let result = task.await?;
    Ok(())
}

Authentication

// Request a security code be sent to the email address.
modio.auth().request_code("john@example.com").await?;

// Wait for the 5-digit security code
let token = modio.auth().security_code("QWERT").await?;

// Create an endpoint with the new credentials
let modio = modio.with_credentials(token);

See full example.

Games

use modio::filter::prelude::*;

// List games with filter `name_id = "0ad"`
let games = modio.games().search(NameId::eq("0ad")).collect().await?;

Mods

use modio::filter::prelude::*;

// List all mods for 0 A.D.
let mods = modio.game(5).mods().search(Filter::default()).collect().await?;

// Get the details of the `balancing-mod` mod
let balancing_mod = modio.mod_(5, 110).get().await?;

Streaming search result

use futures::TryStreamExt;

let filter = Fulltext::eq("tftd").limit(10);
let mut st = modio.game(51).mods().search(filter).paged().await?;
let (_page_count, _) = st.size_hint();

// Stream of paged results `Page<Mod>` with page size = 10
while let Some(page) = st.try_next().await? {
    println!("Page {}/{} - Items #{}", page.current(), page.page_count(), page.len());
    for item in page {
        println!("  {}. {}", item.id, item.name);
    }
}

let filter = Fulltext::eq("soldier");
let mut st = modio.game(51).mods().search(filter).iter().await?;
let (_total, _) = st.size_hint();

// Stream of `Mod`
while let Some(mod_) = st.try_next().await? {
    println!("{}. {}", mod_.id, mod_.name);
}

Download

use future_util::{future, TryStreamExt};
use modio::download::{ResolvePolicy, DownloadAction};

// Download the primary file of a mod.
let action = DownloadAction::Primary {
    game_id: 5,
    mod_id: 19,
};
modio
    .download(action)
    .await?
    .save_to_file("mod.zip")
    .await?;

// Download the specific file of a mod.
let action = DownloadAction::File {
    game_id: 5,
    mod_id: 19,
    file_id: 101,
};
modio
    .download(action)
    .await?.save_to_file("mod.zip")
    .await?;

// Download the specific version of a mod.
// if multiple files are found then the latest file is downloaded.
// Set policy to `ResolvePolicy::Fail` to return with `modio::download::Error::MultipleFilesFound`
// as source error.
let action = DownloadAction::Version {
    game_id: 5,
    mod_id: 19,
    version: "0.1".to_string(),
    policy: ResolvePolicy::Latest,
};
modio
    .download(action)
    .await?
    .stream()
    .try_for_each(|bytes| {
        println!("bytes: {:?}")
        future::ok(())
    })
    .await?;

Examples

See examples directory for some getting started examples.

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~7–20MB
~276K SLoC