mcapi 0.2.0

Unified async Rust client for the Minecraft ecosystem (Mojang, Modrinth, CurseForge, Yggdrasil, Blessing Skin, Loaders, Java Runtimes, and SLP)
Documentation
use serde::Serialize;

use super::models::{ClosetCategory, ClosetItem, PaginatedList};
use super::{Authed, NameBody};
use crate::error::Result;

#[derive(Serialize)]
struct ClosetQuery<'a> {
    category: Option<ClosetCategory>,
    q: Option<&'a str>,
    page: Option<u32>,
}

#[derive(Serialize)]
struct TidBody {
    tid: u64,
}

impl<'a> Authed<'a> {
    /// Lists textures in the authenticated user's closet via `GET /api/closet`.
    pub async fn list_closet(
        &self,
        category: Option<ClosetCategory>,
        q: Option<&str>,
        page: Option<u32>,
    ) -> Result<PaginatedList<ClosetItem>> {
        self.get_envelope_query("/closet", &ClosetQuery { category, q, page })
            .await
    }

    /// Adds a texture from the skin library to the user's closet via `POST /api/closet`.
    pub async fn add_to_closet(&self, tid: u64) -> Result<()> {
        self.post_unit("/closet", &TidBody { tid }).await
    }

    /// Renames a closet texture via `PUT /api/closet/{tid}`.
    pub async fn rename_closet_item(&self, tid: u64, name: &str) -> Result<()> {
        self.put_unit(&format!("/closet/{tid}"), &NameBody { name })
            .await
    }

    /// Removes a texture from the user's closet via `DELETE /api/closet/{tid}`.
    pub async fn remove_from_closet(&self, tid: u64) -> Result<()> {
        self.delete_unit(&format!("/closet/{tid}")).await
    }
}