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
impl BrawlClient
Sourcepub fn new(api_key: impl Into<String>) -> Self
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
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§
impl Freeze for BrawlClient
impl !RefUnwindSafe for BrawlClient
impl Send for BrawlClient
impl Sync for BrawlClient
impl Unpin for BrawlClient
impl UnsafeUnpin for BrawlClient
impl !UnwindSafe for BrawlClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more