mcapi 0.3.1

Unified async Rust client for the Minecraft ecosystem (Mojang, Modrinth, CurseForge, Yggdrasil, Blessing Skin, Loaders, BMCLAPI, and Java Runtimes)
Documentation
use super::models::piston::{
    AssetIndex, AssetIndexReference, GameVersionMetadata, VersionManifestEntry, VersionManifestV2,
};
use super::{DEFAULT_PISTON_META_URL, MojangClient};
use crate::error::Result;

impl MojangClient {
    /// Fetches Mojang's `version_manifest_v2.json` via Piston Meta (with configured mirror).
    pub async fn version_manifest(&self) -> Result<VersionManifestV2> {
        let url = self.url(DEFAULT_PISTON_META_URL, "/mc/game/version_manifest_v2.json");
        self.http.get_json(&url).await
    }

    /// Fetches detailed [`GameVersionMetadata`] for a [`VersionManifestEntry`].
    pub async fn version_metadata(
        &self,
        entry: &VersionManifestEntry,
    ) -> Result<GameVersionMetadata> {
        self.version_metadata_from_url(entry.url.as_str()).await
    }

    /// Fetches detailed [`GameVersionMetadata`] from an explicit manifest URL (rewritten via mirror).
    pub async fn version_metadata_from_url(&self, url: &str) -> Result<GameVersionMetadata> {
        self.http.get_json(url).await
    }

    /// Fetches the [`AssetIndex`] referenced by [`AssetIndexReference`].
    pub async fn asset_index(&self, asset_index: &AssetIndexReference) -> Result<AssetIndex> {
        self.asset_index_from_url(asset_index.url.as_str()).await
    }

    /// Fetches an [`AssetIndex`] from an explicit URL (rewritten via mirror).
    pub async fn asset_index_from_url(&self, url: &str) -> Result<AssetIndex> {
        self.http.get_json(url).await
    }
}