pub struct Modio { /* private fields */ }
Expand description
Endpoint interface to interacting with the mod.io API.
Implementations§
source§impl Modio
impl Modio
sourcepub fn builder<C: Into<Credentials>>(credentials: C) -> Builder
pub fn builder<C: Into<Credentials>>(credentials: C) -> Builder
Constructs a new Builder
to configure a Modio
client.
This is the same as Builder::new(credentials)
.
sourcepub fn new<C>(credentials: C) -> Result<Self>where
C: Into<Credentials>,
pub fn new<C>(credentials: C) -> Result<Self>where
C: Into<Credentials>,
Create an endpoint to https://api.mod.io/v1.
sourcepub fn host<H, C>(host: H, credentials: C) -> Result<Self>
pub fn host<H, C>(host: H, credentials: C) -> Result<Self>
Create an endpoint to a different host.
sourcepub fn with_credentials<CR>(&self, credentials: CR) -> Selfwhere
CR: Into<Credentials>,
pub fn with_credentials<CR>(&self, credentials: CR) -> Selfwhere
CR: Into<Credentials>,
Return an endpoint with new credentials.
sourcepub fn with_token<T>(&self, token: T) -> Self
pub fn with_token<T>(&self, token: T) -> Self
Return an endpoint with a new token.
sourcepub fn games(&self) -> Games
pub fn games(&self) -> Games
Return a reference to an interface that provides access to game information.
sourcepub async fn download<A>(&self, action: A) -> Result<Downloader>where
DownloadAction: From<A>,
pub async fn download<A>(&self, action: A) -> Result<Downloader>where
DownloadAction: From<A>,
Returns Downloader
for saving to file or retrieving
the data via Stream
.
The download fails with modio::download::Error
as source
if a primary file, a specific file or a specific version is not found.
§Example
use futures_util::{future, TryStreamExt};
use modio::download::{DownloadAction, ResolvePolicy};
use modio::types::id::Id;
// Download the primary file of a mod.
let action = DownloadAction::Primary {
game_id: Id::new(5),
mod_id: Id::new(19),
};
modio
.download(action)
.await?
.save_to_file("mod.zip")
.await?;
// Download the specific file of a mod.
let action = DownloadAction::File {
game_id: Id::new(5),
mod_id: Id::new(19),
file_id: Id::new(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: Id::new(5),
mod_id: Id::new(19),
version: "0.1".to_string(),
policy: ResolvePolicy::Latest,
};
modio
.download(action)
.await?
.stream()
.try_for_each(|bytes| {
println!("Bytes: {:?}", bytes);
future::ok(())
})
.await?;
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Modio
impl !RefUnwindSafe for Modio
impl Send for Modio
impl Sync for Modio
impl Unpin for Modio
impl !UnwindSafe for Modio
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