Skip to main content

lichess_api/api/
teams.rs

1//! Team info, membership, and team-only tournament listings.
2//!
3//! Lookups such as [`LichessApi::get_team`], [`LichessApi::search_teams`],
4//! [`LichessApi::get_team_members`], and the team's arena/swiss tournament
5//! listings are public. Joining and quitting a team need a token with
6//! `team:write`; reading your team updates needs `team:read`. Everything
7//! else here — viewing join requests, accepting or declining them, kicking a
8//! member, and sending a team update — acts on a team you lead and needs a
9//! token with `team:lead`.
10
11use futures::stream::StreamExt;
12
13use crate::client::LichessApi;
14use crate::error::Result;
15use crate::model::teams::*;
16use crate::model::{ArenaTournament, SwissTournament};
17
18impl LichessApi<reqwest::Client> {
19    pub async fn get_popular_teams(
20        &self,
21        request: impl Into<all::GetRequest>,
22    ) -> Result<TeamPaginatorJson> {
23        self.get_single_model(request.into()).await
24    }
25
26    pub async fn search_teams(
27        &self,
28        request: impl Into<search::GetRequest>,
29    ) -> Result<TeamPaginatorJson> {
30        self.get_single_model(request.into()).await
31    }
32
33    pub async fn get_teams_of_player(
34        &self,
35        request: impl Into<of_username::GetRequest>,
36    ) -> Result<Vec<Team>> {
37        self.get_single_model(request.into()).await
38    }
39
40    pub async fn get_team(&self, request: impl Into<show::GetRequest>) -> Result<Team> {
41        self.get_single_model(request.into()).await
42    }
43
44    pub async fn get_team_members(
45        &self,
46        request: impl Into<users::GetRequest>,
47    ) -> Result<impl StreamExt<Item = Result<users::TeamMember>>> {
48        self.get_streamed_models(request.into()).await
49    }
50
51    pub async fn get_team_arena_tournaments(
52        &self,
53        request: impl Into<arena::GetRequest>,
54    ) -> Result<impl StreamExt<Item = Result<ArenaTournament>>> {
55        self.get_streamed_models(request.into()).await
56    }
57
58    pub async fn get_team_swiss_tournaments(
59        &self,
60        request: impl Into<swiss::GetRequest>,
61    ) -> Result<impl StreamExt<Item = Result<SwissTournament>>> {
62        self.get_streamed_models(request.into()).await
63    }
64
65    pub async fn get_team_join_requests(
66        &self,
67        request: impl Into<requests::GetRequest>,
68    ) -> Result<Vec<TeamRequestWithUser>> {
69        self.get_single_model(request.into()).await
70    }
71
72    pub async fn accept_team_join_request(
73        &self,
74        request: impl Into<request_accept::PostRequest>,
75    ) -> Result<bool> {
76        self.get_ok(request.into()).await
77    }
78
79    pub async fn decline_team_join_request(
80        &self,
81        request: impl Into<request_decline::PostRequest>,
82    ) -> Result<bool> {
83        self.get_ok(request.into()).await
84    }
85
86    pub async fn kick_team_member(&self, request: impl Into<kick::PostRequest>) -> Result<bool> {
87        self.get_ok(request.into()).await
88    }
89
90    pub async fn join_team(&self, request: impl Into<join::PostRequest>) -> Result<bool> {
91        self.get_ok(request.into()).await
92    }
93
94    pub async fn quit_team(&self, request: impl Into<quit::PostRequest>) -> Result<bool> {
95        self.get_ok(request.into()).await
96    }
97
98    pub async fn send_team_update(&self, request: impl Into<pm_all::PostRequest>) -> Result<bool> {
99        self.get_ok(request.into()).await
100    }
101
102    pub async fn get_team_updates(
103        &self,
104        request: impl Into<updates::GetRequest>,
105    ) -> Result<TeamUpdates> {
106        self.get_single_model(request.into()).await
107    }
108
109    pub async fn get_team_updates_of_team(
110        &self,
111        request: impl Into<updates_of_team::GetRequest>,
112    ) -> Result<TeamUpdatesOfTeam> {
113        self.get_single_model(request.into()).await
114    }
115}