lichess_api/api/
external_engine.rs

1use async_std::stream::StreamExt;
2
3use crate::client::LichessApi;
4use crate::error::Result;
5use crate::model::external_engine::*;
6
7impl LichessApi<reqwest::Client> {
8    pub async fn list_external_engines(&self) -> Result<Vec<ExternalEngine>> {
9        self.get_single_model(list::GetRequest::new()).await
10    }
11
12    pub async fn create_external_engine(
13        &self,
14        request: impl Into<create::PostRequest>,
15    ) -> Result<ExternalEngine> {
16        self.get_single_model(request.into()).await
17    }
18
19    pub async fn get_external_engine(
20        &self,
21        request: impl Into<id::GetRequest>,
22    ) -> Result<ExternalEngine> {
23        self.get_single_model(request.into()).await
24    }
25
26    pub async fn update_external_engine(
27        &self,
28        request: impl Into<update::PutRequest>,
29    ) -> Result<ExternalEngine> {
30        self.get_single_model(request.into()).await
31    }
32
33    pub async fn delete_external_engine(
34        &self,
35        request: impl Into<delete::DeleteRequest>,
36    ) -> Result<bool> {
37        self.get_ok(request.into()).await
38    }
39
40    /// This method currently returns a 503 error (Service Unavailable) from the Lichess API
41    pub async fn analyse_with_external_engine(
42        &self,
43        request: impl Into<analyse::PostRequest>,
44    ) -> Result<impl StreamExt<Item = Result<analyse::AnalysisResponse>>> {
45        self.get_streamed_models(request.into()).await
46    }
47
48    pub async fn acquire_analysis_request(
49        &self,
50        request: impl Into<acquire_analysis::PostRequest>,
51    ) -> Result<Option<acquire_analysis::AcquireAnalysisResponse>> {
52        let mut stream = self.get_streamed_models(request.into()).await?;
53        // The response is a stream of 0 or 1 items, so we can just take the first item
54        Ok((stream.next().await).transpose()?)
55    }
56}