[−][src]Crate modio
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.
Authentication
To access the API authentication is required and can be done via 4 ways:
- Request an API key (Read-only)
- Manually create an OAuth 2 Access Token (Read + Write)
- Email Authentication Flow to create an OAuth 2 Access Token (Read + Write)
- Encrypted gog user auth ticket to create an OAuth 2 Access Token (Read + Write)
- Encrypted steam user auth ticket to create an OAuth 2 Access Token (Read + Write)
Rate Limiting
For API requests using API key authentication are unlimited and for OAuth 2 authentication requests are limited to 120 requests per hour.
A special error ErrorKind::RateLimit will be return from api operations when the rate limit associated with credentials has been exhausted.
Example: Basic setup
use modio::{Credentials, Error, Modio}; use tokio::runtime::Runtime; fn main() -> Result<(), Error> { let mut rt = Runtime::new().expect("new rt"); let modio = Modio::new( Credentials::ApiKey(String::from("user-or-game-api-key")), )?; // create some tasks and execute them // let result = rt.block_on(task)?; Ok(()) }
For testing purposes use Modio::host
to create a client for the
mod.io test environment.
Example: Chaining api requests
use modio::{Credentials, Error, Modio}; use tokio::prelude::*; use tokio::runtime::Runtime; fn main() -> Result<(), Error> { let mut rt = Runtime::new().expect("new rt"); let modio = Modio::new( Credentials::ApiKey(String::from("user-or-game-api-key")), )?; // OpenXcom: The X-Com Files let modref = modio.mod_(51, 158); // Get mod with its dependencies and all files let mod_ = modref.get(); let deps = modref.dependencies().list(); let files = modref.files().list(&Default::default()); let task = mod_.join(deps).join(files); match rt.block_on(task) { Ok(((m, deps), files)) => { println!("{}", m.name); println!( "deps: {:?}", deps.into_iter().map(|d| d.mod_id).collect::<Vec<_>>() ); for file in files { println!("file id: {} version: {:?}", file.id, file.version); } } Err(e) => println!("{}", e), }; Ok(()) }
Example: Downloading mods
use std::fs::File; use modio::download::ResolvePolicy; use modio::{Credentials, DownloadAction, Error, Modio}; use tokio::runtime::Runtime; fn main() -> Result<(), Error> { let mut rt = Runtime::new().expect("new rt"); let modio = Modio::new( Credentials::ApiKey(String::from("user-or-game-api-key")), )?; let out = File::create("mod.zip").expect("new file"); // 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))?; Ok(()) }
Re-exports
pub use crate::auth::Credentials; |
pub use crate::download::DownloadAction; |
pub use crate::error::Error; |
pub use crate::error::Result; |
Modules
auth | Authentication Flow interface |
client | Re-exports of the used reqwest types. |
comments | Mod comments interface |
download | |
error | Client errors |
files | Modfile interface |
filter | Filtering and sorting |
games | Games interface |
me | Me interface |
metadata | Mod metadata KVP interface |
mods | Mods Interface |
reports | Reports interface |
teams | Team members interface |
users | Users interface |
Structs
Builder | A |
Endpoint | Generic endpoint for sub-resources |
Modio | Endpoint interface to interacting with the mod.io API. |
ModioErrorResponse | See the Error Object docs for more information. |
ModioListResponse | See the Multiple Item Response docs for more information. |
Enums
ModioResult | Result type for editing games, mods and files. |
Traits
AddOptions | |
DeleteOptions | |
QueryString |
Type Definitions
Future | |
List | |
Stream |