1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use async_std::stream::StreamExt;

use crate::client::LichessApi;
use crate::error::Result;
use crate::model::games::*;

impl LichessApi<reqwest::Client> {
    pub async fn export_one_game(&self, request: export::one::GetRequest) -> Result<GameJson> {
        self.get_single_model(request).await
    }

    pub async fn export_ongoing_game(
        &self,
        request: export::ongoing::GetRequest,
    ) -> Result<GameJson> {
        self.get_single_model(request).await
    }

    pub async fn export_games_of_user(
        &self,
        request: export::by_user::GetRequest,
    ) -> Result<impl StreamExt<Item = Result<GameJson>>> {
        self.get_streamed_models(request).await
    }

    pub async fn export_games_by_ids(
        &self,
        request: export::by_ids::PostRequest,
    ) -> Result<impl StreamExt<Item = Result<GameJson>>> {
        self.get_streamed_models(request).await
    }

    pub async fn stream_games_of_users(
        &self,
        request: stream::by_users::PostRequest,
    ) -> Result<impl StreamExt<Item = Result<GameStream>>> {
        self.get_streamed_models(request).await
    }

    pub async fn stream_games_by_ids(
        &self,
        request: stream::by_ids::PostRequest,
    ) -> Result<impl StreamExt<Item = Result<GameStream>>> {
        self.get_streamed_models(request).await
    }

    pub async fn add_game_ids_to_stream(
        &self,
        request: stream::add_ids::PostRequest,
    ) -> Result<bool> {
        self.get_ok(request).await
    }

    pub async fn get_my_ongoing_games(
        &self,
        request: ongoing::GetRequest,
    ) -> Result<ongoing::Games> {
        self.get_single_model(request).await
    }

    pub async fn stream_game_moves(
        &self,
        request: stream::moves::GetRequest,
    ) -> Result<impl StreamExt<Item = Result<stream::moves::Move>>> {
        self.get_streamed_models(request).await
    }

    pub async fn import_game(&self, request: import::PostRequest) -> Result<import::ImportData> {
        self.get_single_model(request).await
    }
}