Skip to main content

lichess_api/api/
bulk_pairings.rs

1//! Bulk pairings let a broadcaster or tournament organizer schedule many
2//! games between paired players at once, up to a week in advance, rather than
3//! creating challenges one by one.
4//!
5//! Creating a pairing ([`LichessApi::create_bulk_pairing`]) requires an OAuth
6//! token with the `challenge:bulk` scope for the caller, plus a
7//! `challenge:write` token for each player being paired. Once created, a
8//! pairing can be looked up, canceled before it fires, or have its clocks
9//! started immediately instead of waiting for the scheduled time.
10//!
11//! [`LichessApi::create_bulk_pairing`]: crate::client::LichessApi::create_bulk_pairing
12
13use futures::stream::StreamExt;
14
15use crate::client::LichessApi;
16use crate::error::Result;
17use crate::model::bulk_pairings::*;
18use crate::model::games::GameJson;
19
20impl LichessApi<reqwest::Client> {
21    pub async fn get_bulk_pairings(&self) -> Result<Vec<BulkPairing>> {
22        self.get_single_model(list::GetRequest::new()).await
23    }
24
25    pub async fn create_bulk_pairing(
26        &self,
27        form: create::CreateBulkPairingForm,
28    ) -> Result<BulkPairing> {
29        self.get_single_model(create::PostRequest::new(form)).await
30    }
31
32    pub async fn get_bulk_pairing(
33        &self,
34        request: impl Into<show::GetRequest>,
35    ) -> Result<BulkPairing> {
36        self.get_single_model(request.into()).await
37    }
38
39    pub async fn cancel_bulk_pairing(
40        &self,
41        request: impl Into<remove::DeleteRequest>,
42    ) -> Result<bool> {
43        self.get_ok(request.into()).await
44    }
45
46    pub async fn export_bulk_pairing_games(
47        &self,
48        id: &str,
49        query: games::GetQuery,
50    ) -> Result<impl StreamExt<Item = Result<GameJson>>> {
51        self.get_streamed_models(games::GetRequest::new(id, query))
52            .await
53    }
54
55    pub async fn start_bulk_pairing_clocks(
56        &self,
57        request: impl Into<start_clocks::PostRequest>,
58    ) -> Result<bool> {
59        self.get_ok(request.into()).await
60    }
61}