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::Serialize;

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

#[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 closet(&self, query: &ClosetQuery) -> Result<PaginatedList<ClosetItem>> {
        self.get_envelope_query("/closet", query).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
    }
}