Skip to main content

lichess_api/api/
openings.rs

1//! Query move statistics for a position from the Opening Explorer: aggregated
2//! master games ([`openings_masters`](LichessApi::openings_masters)), rated
3//! Lichess games ([`openings_lichess`](LichessApi::openings_lichess)), or a
4//! specific player's games ([`openings_player`](LichessApi::openings_player)),
5//! plus fetching a masters game's PGN by ID
6//! ([`openings_otb`](LichessApi::openings_otb)). All of these are public and
7//! need no token, and are served from a separate host,
8//! [`Domain::Explorer`](crate::model::Domain::Explorer).
9
10use futures::stream::StreamExt;
11
12use crate::client::LichessApi;
13use crate::error::Result;
14use crate::model::openings::*;
15
16impl LichessApi<reqwest::Client> {
17    pub async fn openings_masters(
18        &self,
19        request: impl Into<masters::GetRequest>,
20    ) -> Result<OpeningExplorerJson> {
21        self.get_single_model(request.into()).await
22    }
23
24    pub async fn openings_lichess(
25        &self,
26        request: impl Into<lichess::GetRequest>,
27    ) -> Result<OpeningExplorerJson> {
28        self.get_single_model(request.into()).await
29    }
30
31    pub async fn openings_player(
32        &self,
33        request: impl Into<player::GetRequest>,
34    ) -> Result<OpeningExplorerJson> {
35        self.get_single_model(request.into()).await
36    }
37
38    pub async fn openings_otb(
39        &self,
40        request: impl Into<otb::GetRequest>,
41    ) -> Result<impl StreamExt<Item = Result<String>>> {
42        self.get_pgn(request.into()).await
43    }
44}