Skip to main content

BrawlClient

Struct BrawlClient 

Source
pub struct BrawlClient { /* private fields */ }
Expand description

Main client for interacting with the Brawl Stars API.

The BrawlClient handles all HTTP communication with the Brawl Stars API, including authentication, error handling, and JSON deserialization.

§Examples

use brawl_rs::prelude::*;

let client = BrawlClient::new("your_api_token_here");

Implementations§

Source§

impl BrawlClient

Source

pub fn new(api_key: impl Into<String>) -> Self

Creates a new BrawlClient with the provided API key.

The API key can be obtained from the Brawl Stars Developer Portal.

§Arguments
  • api_key - Your Brawl Stars API token for authentication
§Examples
use brawl_rs::prelude::*;

let client = BrawlClient::new("eyJ0eXAiOiJKV1QiLCJhbGci...");
Examples found in repository?
examples/player.rs (line 10)
9async fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let client = BrawlClient::new(var("BRAWL_TOKEN")?);
11
12    // Fetch player information
13    // Note: Replace with a valid player tag
14    match Player::get(&client, "20YY0G9L0").await {
15        Ok(mut player) => {
16            println!("=== Player Information ===");
17            println!("Name: {}", player.name);
18            println!("Trophies: {}", player.trophies);
19            println!("Highest Trophies: {}", player.highest_trophies);
20            println!("Level: {}", player.exp_level);
21            println!("Prestige: {}", player.total_prestige_level);
22            println!("Experience Points: {}", player.exp_points);
23            println!("\n=== Victories ===");
24            println!("3v3: {}", player.victories_3v3);
25            println!("Solo: {}", player.solo_victories);
26            println!("Duo: {}", player.duo_victories);
27
28            if let Some(club_name) = &player.club.name {
29                println!("\n=== Club ===");
30                println!("Name: {}", club_name);
31                println!("Tag: {}", player.club.tag.as_deref().unwrap_or("N/A"));
32            }
33
34            println!("\n=== Brawlers ({} total) ===", player.brawlers.len());
35            player
36                .brawlers
37                .sort_by(|x, x1| x1.trophies.cmp(&x.trophies));
38
39            for brawler in player.brawlers.iter().take(10) {
40                println!(
41                    "{}: Power {}, Trophies {}, Rank {}",
42                    brawler.name, brawler.power, brawler.trophies, brawler.rank
43                );
44            }
45        }
46        Err(e) => eprintln!("Error fetching player: {:?}", e),
47    }
48
49    Ok(())
50}
More examples
Hide additional examples
examples/battle_log.rs (line 10)
9async fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let client = BrawlClient::new(var("BRAWL_TOKEN")?);
11
12    // ==========================================
13    // FETCH BATTLE LOG
14    // ==========================================
15
16    println!("=== Battle Log ===\n");
17    match BattleLog::get(&client, "20YY0G9L0").await {
18        Ok(battle_log) => {
19            println!("Found {} battles:\n", battle_log.items.len());
20
21            for (i, battle) in battle_log.items.iter().enumerate().take(3) {
22                println!("=== Battle #{} ===", i + 1);
23
24                // Battle time
25                println!("Battle Time: {}", battle.battle_time);
26
27                // Event information
28                println!("Event ID: {}", battle.event.id);
29                println!("Event Mode ID: {}", battle.event.mode_id);
30                if let Some(map) = &battle.event.map {
31                    println!("Event Map: {}", map);
32                }
33
34                // Battle information
35                println!("Battle Mode: {}", battle.battle.mode);
36                println!("Battle Type: {}", battle.battle.kind);
37
38                if let Some(result) = &battle.battle.result {
39                    println!("Result: {}", result);
40                }
41
42                if let Some(rank) = battle.battle.rank {
43                    println!("Rank: {}", rank);
44                }
45
46                if let Some(trophy_change) = battle.battle.trophy_change {
47                    println!("Trophy Change: {}", trophy_change);
48                }
49
50                // Star player
51                if let Some(star_player) = &battle.battle.star_player {
52                    println!("Star Player:");
53                    println!("  Tag: {}", star_player.tag);
54                    println!("  Name: {}", star_player.name);
55                    println!("  Brawler ID: {}", star_player.brawler.id);
56                    println!("  Brawler Name: {}", star_player.brawler.name);
57                    println!("  Brawler Power: {}", star_player.brawler.power);
58                    println!("  Brawler Trophies: {}", star_player.brawler.trophies);
59                }
60
61                // Players
62                println!("Players ({}):", battle.battle.players.len());
63                for (j, player) in battle.battle.players.iter().enumerate() {
64                    println!("  Player {}:", j + 1);
65                    println!("    Tag: {}", player.tag);
66                    println!("    Name: {}", player.name);
67                    println!("    Brawler ID: {}", player.brawler.id);
68                    println!("    Brawler Name: {}", player.brawler.name);
69                    println!("    Brawler Power: {}", player.brawler.power);
70                    println!("    Brawler Trophies: {}", player.brawler.trophies);
71                }
72
73                // Teams (if available)
74                if let Some(teams) = &battle.battle.teams {
75                    println!("Teams ({} teams):", teams.len());
76                    for (team_idx, team) in teams.iter().enumerate() {
77                        println!("  Team {} ({} players):", team_idx + 1, team.len());
78                        for (player_idx, player) in team.iter().enumerate() {
79                            println!(
80                                "    Player {}: {} ({})",
81                                player_idx + 1,
82                                player.name,
83                                player.brawler.name
84                            );
85                        }
86                    }
87                }
88
89                println!("\n");
90            }
91        }
92        Err(e) => eprintln!("Error fetching battle log: {}", e),
93    }
94
95    Ok(())
96}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more