Coder Social home page Coder Social logo

modio-rs's Introduction

mod.io

modio-rs

Crates.io License Released API docs Master API docs Travis Build 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, add this to your Cargo.toml

[dependencies]
modio = "0.4"

Basic Setup

use modio::{Credentials, Error, Modio};
use tokio::runtime::Runtime;

fn main() -> Result<(), Error> {
    let mut rt = Runtime::new()?;
    let modio = Modio::new(
        Credentials::ApiKey(String::from("user-or-game-apikey")),
    )?;

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

Authentication

// Request a security code be sent to the email address.
rt.block_on(modio.auth().request_code("[email protected]"))?;

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

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

See full example.

Games

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

// List games with filter `name_id = "0ad"`
let task = modio.games().list(&NameId::eq("0ad"));

let games = rt.block_on(task)?;

Mods

// List all mods for 0 A.D.
let mods = rt.block_on(modio.game(5).mods().list(&Default::default))?;

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

Download

use modio::download::{ResolvePolicy, DownloadAction};

// Download the primary file of a mod.
let action = DownloadAction::Primary {
    game_id: 5,
    mod_id: 19,
};
let (len, out) = rt.block_on(modio.download(action, out))?;

// Download the specific file of a mod.
let action = DownloadAction::File {
    game_id: 5,
    mod_id: 19,
    file_id: 101,
};
let (len, out) = rt.block_on(modio.download(action, out))?;

// 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 `ErrorKind::Download(DownloadError::MultipleFilesFound)`.
let action = DownloadAction::Version {
    game_id: 5,
    mod_id: 19,
    version: "0.1".to_string(),
    policy: ResolvePolicy::Latest,
};
let (len, out) = rt.block_on(modio.download(action, out))?;

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.

modio-rs's People

Contributors

intenscia avatar nickelc avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.