brawl-rs 0.1.0

A Rust wrapper for the Brawl Stars API
Documentation
use crate::client::endpoints::Endpoint;
use crate::client::BrawlClient;
use crate::errors::BrawlError;
use serde::Deserialize;

/// Represents a Brawl Stars club.
///
/// A club is a group of players that can compete together and share rewards.
/// This struct contains information about the club, its members, and settings.
///
/// # Examples
///
/// ```no_run
/// use brawl_rs::prelude::*;
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
///     let client = BrawlClient::new(std::env::var("BRAWL_TOKEN")?);
///     let club = Club::get(&client, "82Y2QCCCQ").await?;
///     println!("Club: {}", club.name);
///     println!("Members: {}", club.members.len());
///     Ok(())
/// }
/// ```
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Club {
    pub tag: String,
    pub name: String,
    pub description: Option<String>,
    #[serde(rename = "type")]
    pub kind: String,
    pub badge_id: u64,
    pub required_trophies: u64,
    pub trophies: u64,
    pub members: Vec<ClubMember>,
    #[serde(rename = "isFamilyFriendly")]
    pub family_friendly: bool,
}

/// Information about a member of a club.
///
/// Represents a single player that is a member of a club, including their role
/// and personal statistics within the game.
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ClubMember {
    pub tag: String,
    pub name: String,
    pub name_color: String,
    pub role: String,
    pub trophies: u64,
}

impl Club {
    /// Fetches club information by its tag.
    ///
    /// Retrieves complete club data including all members and club settings.
    ///
    /// # Arguments
    ///
    /// * `client` - The [`BrawlClient`] to use for the request
    /// * `tag` - The club's tag (format: XXXX...)
    ///
    /// # Errors
    ///
    /// Returns [`BrawlError`] if:
    /// - The club tag is invalid
    /// - The club does not exist
    /// - Network communication fails
    ///
    /// # Examples
    ///
    /// ```no_run
    /// use brawl_rs::prelude::*;
    ///
    /// #[tokio::main]
    /// async fn main() -> Result<(), Box<dyn std::error::Error>> {
    ///     let client = BrawlClient::new(std::env::var("BRAWL_TOKEN")?);
    ///     let club = Club::get(&client, "82Y2QCCCQ").await?;
    ///     println!("Club: {} has {} members", club.name, club.members.len());
    ///     Ok(())
    /// }
    /// ```
    pub async fn get(client: &BrawlClient, tag: &str) -> Result<Self, BrawlError> {
        let endpoint = Endpoint::Club(tag.to_string());

        client.fetch::<Self>(endpoint).await
    }
}