lichess_api/api/
games.rs

1use async_std::stream::StreamExt;
2
3use crate::client::LichessApi;
4use crate::error::Result;
5use crate::model::games::*;
6
7impl LichessApi<reqwest::Client> {
8    pub async fn export_one_game(
9        &self,
10        request: impl Into<export::one::GetRequest>,
11    ) -> Result<GameJson> {
12        self.get_single_model(request.into()).await
13    }
14
15    pub async fn export_ongoing_game(
16        &self,
17        request: impl Into<export::ongoing::GetRequest>,
18    ) -> Result<GameJson> {
19        self.get_single_model(request.into()).await
20    }
21
22    pub async fn export_games_of_user(
23        &self,
24        request: impl Into<export::by_user::GetRequest>,
25    ) -> Result<impl StreamExt<Item = Result<GameJson>>> {
26        self.get_streamed_models(request.into()).await
27    }
28
29    pub async fn export_games_by_ids(
30        &self,
31        request: impl Into<export::by_ids::PostRequest>,
32    ) -> Result<impl StreamExt<Item = Result<GameJson>>> {
33        self.get_streamed_models(request.into()).await
34    }
35
36    pub async fn stream_games_of_users(
37        &self,
38        request: impl Into<stream::by_users::PostRequest>,
39    ) -> Result<impl StreamExt<Item = Result<GameStream>>> {
40        self.get_streamed_models(request.into()).await
41    }
42
43    pub async fn stream_games_by_ids(
44        &self,
45        request: impl Into<stream::by_ids::PostRequest>,
46    ) -> Result<impl StreamExt<Item = Result<GameStream>>> {
47        self.get_streamed_models(request.into()).await
48    }
49
50    pub async fn add_game_ids_to_stream(
51        &self,
52        request: impl Into<stream::add_ids::PostRequest>,
53    ) -> Result<bool> {
54        self.get_ok(request.into()).await
55    }
56
57    pub async fn get_my_ongoing_games(
58        &self,
59        request: impl Into<ongoing::GetRequest>,
60    ) -> Result<ongoing::Games> {
61        self.get_single_model(request.into()).await
62    }
63
64    pub async fn stream_game_moves(
65        &self,
66        request: impl Into<stream::moves::GetRequest>,
67    ) -> Result<impl StreamExt<Item = Result<stream::moves::Move>>> {
68        self.get_streamed_models(request.into()).await
69    }
70
71    pub async fn import_game(
72        &self,
73        request: impl Into<import::PostRequest>,
74    ) -> Result<import::ImportData> {
75        self.get_single_model(request.into()).await
76    }
77}