lichess_api/api/
challenges.rs

1use crate::client::LichessApi;
2use crate::error::Result;
3use crate::model::challenges::*;
4use crate::model::games::stream::moves::Move;
5
6impl LichessApi<reqwest::Client> {
7    pub async fn list_challenges(&self) -> Result<list::Challenges> {
8        self.get_single_model(list::GetRequest::new()).await
9    }
10
11    pub async fn create_challenge(
12        &self,
13        request: impl Into<create::PostRequest>,
14    ) -> Result<ChallengeJson> {
15        self.get_single_model(request.into()).await
16    }
17
18    pub async fn accept_challenge(&self, request: impl Into<accept::PostRequest>) -> Result<bool> {
19        self.get_ok(request.into()).await
20    }
21
22    pub async fn decline_challenge(
23        &self,
24        request: impl Into<decline::PostRequest>,
25    ) -> Result<bool> {
26        self.get_ok(request.into()).await
27    }
28
29    pub async fn cancel_challenge(&self, request: impl Into<cancel::PostRequest>) -> Result<bool> {
30        self.get_ok(request.into()).await
31    }
32
33    pub async fn challenge_ai(&self, request: impl Into<ai::PostRequest>) -> Result<Move> {
34        self.get_single_model(request.into()).await
35    }
36
37    pub async fn create_open_challenge(
38        &self,
39        request: impl Into<open::PostRequest>,
40    ) -> Result<ChallengeOpenJson> {
41        self.get_single_model(request.into()).await
42    }
43
44    pub async fn start_clocks(
45        &self,
46        request: impl Into<start_clocks::PostRequest>,
47    ) -> Result<bool> {
48        self.get_ok(request.into()).await
49    }
50
51    pub async fn add_time_to_opponent_clock(
52        &self,
53        request: impl Into<add_time::PostRequest>,
54    ) -> Result<bool> {
55        self.get_ok(request.into()).await
56    }
57}