Skip to main content

lichess_api/api/
arena_tournaments.rs

1//! Arena tournaments: Lichess's continuous-pairing tournament format, where
2//! players score points per game and climb a live leaderboard for the
3//! duration of the event.
4//!
5//! Covers listing current tournaments, creating and updating them, joining,
6//! withdrawing/pausing, terminating, managing team battles, and reading back
7//! standings, results, team standings, and games. Creating or modifying a
8//! tournament ([`create_arena_tournament`](LichessApi::create_arena_tournament),
9//! [`update_arena_tournament`](LichessApi::update_arena_tournament),
10//! [`join_arena_tournament`](LichessApi::join_arena_tournament),
11//! [`withdraw_from_arena_tournament`](LichessApi::withdraw_from_arena_tournament),
12//! [`terminate_arena_tournament`](LichessApi::terminate_arena_tournament), and
13//! [`update_arena_team_battle`](LichessApi::update_arena_team_battle)) requires
14//! a bearer token with the `tournament:write` scope; reading tournament info,
15//! results, team standings, and games is public and needs no token.
16
17use futures::stream::StreamExt;
18
19use crate::client::LichessApi;
20use crate::error::Result;
21use crate::model::arena_tournaments::*;
22use crate::model::games::GameJson;
23
24impl LichessApi<reqwest::Client> {
25    pub async fn get_current_arena_tournaments(&self) -> Result<ArenaTournaments> {
26        self.get_single_model(current::GetRequest::new()).await
27    }
28
29    pub async fn create_arena_tournament(
30        &self,
31        request: impl Into<create::PostRequest>,
32    ) -> Result<ArenaTournamentFull> {
33        self.get_single_model(request.into()).await
34    }
35
36    pub async fn get_arena_tournament(
37        &self,
38        id: &str,
39        query: show::GetQuery,
40    ) -> Result<ArenaTournamentFull> {
41        self.get_single_model(show::GetRequest::new(id, query))
42            .await
43    }
44
45    pub async fn update_arena_tournament(
46        &self,
47        id: &str,
48        form: update::UpdateArenaTournamentForm,
49    ) -> Result<ArenaTournamentFull> {
50        self.get_single_model(update::PostRequest::new(id, form))
51            .await
52    }
53
54    pub async fn export_arena_tournament_games(
55        &self,
56        id: &str,
57        query: games::GetQuery,
58    ) -> Result<impl StreamExt<Item = Result<GameJson>>> {
59        self.get_streamed_models(games::GetRequest::new(id, query))
60            .await
61    }
62
63    pub async fn join_arena_tournament(
64        &self,
65        id: &str,
66        form: join::JoinArenaTournamentForm,
67    ) -> Result<bool> {
68        self.get_ok(join::PostRequest::new(id, form)).await
69    }
70
71    pub async fn get_arena_tournament_results(
72        &self,
73        id: &str,
74        query: results::GetQuery,
75    ) -> Result<impl StreamExt<Item = Result<ArenaResult>>> {
76        self.get_streamed_models(results::GetRequest::new(id, query))
77            .await
78    }
79
80    pub async fn get_arena_tournament_team_standing(
81        &self,
82        request: impl Into<teams::GetRequest>,
83    ) -> Result<ArenaTeamStanding> {
84        self.get_single_model(request.into()).await
85    }
86
87    pub async fn terminate_arena_tournament(
88        &self,
89        request: impl Into<terminate::PostRequest>,
90    ) -> Result<bool> {
91        self.get_ok(request.into()).await
92    }
93
94    pub async fn withdraw_from_arena_tournament(
95        &self,
96        request: impl Into<withdraw::PostRequest>,
97    ) -> Result<bool> {
98        self.get_ok(request.into()).await
99    }
100
101    pub async fn update_arena_team_battle(
102        &self,
103        id: &str,
104        form: team_battle::TeamBattleForm,
105    ) -> Result<ArenaTournamentFull> {
106        self.get_single_model(team_battle::PostRequest::new(id, form))
107            .await
108    }
109
110    pub async fn get_arena_tournaments_created_by_user(
111        &self,
112        username: &str,
113        query: created_by_user::GetQuery,
114    ) -> Result<impl StreamExt<Item = Result<crate::model::ArenaTournament>>> {
115        self.get_streamed_models(created_by_user::GetRequest::new(username, query))
116            .await
117    }
118
119    pub async fn get_arena_tournaments_played_by_user(
120        &self,
121        username: &str,
122        query: played_by_user::GetQuery,
123    ) -> Result<impl StreamExt<Item = Result<ArenaTournamentPlayed>>> {
124        self.get_streamed_models(played_by_user::GetRequest::new(username, query))
125            .await
126    }
127}