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 serde::{Deserialize, Serialize};

pub use crate::profile::{
    ProfileProperty, TextureEntry, TextureMetadata, TextureType, TexturesPayload,
};

use crate::error::{Error, Result};
use crate::profile::decode_textures_property;
use crate::uuid::McUuid;

/// Name-to-UUID entry returned by Mojang username lookup endpoints.
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct NameUuidEntry {
    pub id: McUuid,
    pub name: String,
}

/// Public session profile returned by `sessionserver.mojang.com/session/minecraft/profile/{uuid}`.
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct SessionProfile {
    pub id: McUuid,
    pub name: String,
    #[serde(default)]
    pub properties: Vec<ProfileProperty>,
    #[serde(default)]
    pub profile_actions: Vec<String>,
}

impl SessionProfile {
    /// Decodes the Base64 `textures` property payload when present.
    pub fn decode_textures(&self) -> Result<TexturesPayload> {
        decode_textures_property(&self.properties)?.ok_or(Error::MissingTexturesProperty)
    }
}

/// Mojang RSA public keys returned by `GET /publickeys`.
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct PublicKeysResponse {
    #[serde(default)]
    pub player_certificate_keys: Vec<PublicKeyItem>,
    #[serde(default)]
    pub profile_property_keys: Vec<PublicKeyItem>,
}

/// Single RSA key entry in [`PublicKeysResponse`].
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct PublicKeyItem {
    pub public_key: String,
}