lichess-api 1.0.0

A client library for the Lichess API
Documentation
//! Bulk pairings let a broadcaster or tournament organizer schedule many
//! games between paired players at once, up to a week in advance, rather than
//! creating challenges one by one.
//!
//! Creating a pairing ([`LichessApi::create_bulk_pairing`]) requires an OAuth
//! token with the `challenge:bulk` scope for the caller, plus a
//! `challenge:write` token for each player being paired. Once created, a
//! pairing can be looked up, canceled before it fires, or have its clocks
//! started immediately instead of waiting for the scheduled time.
//!
//! [`LichessApi::create_bulk_pairing`]: crate::client::LichessApi::create_bulk_pairing

use futures::stream::StreamExt;

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

impl LichessApi<reqwest::Client> {
    pub async fn get_bulk_pairings(&self) -> Result<Vec<BulkPairing>> {
        self.get_single_model(list::GetRequest::new()).await
    }

    pub async fn create_bulk_pairing(
        &self,
        form: create::CreateBulkPairingForm,
    ) -> Result<BulkPairing> {
        self.get_single_model(create::PostRequest::new(form)).await
    }

    pub async fn get_bulk_pairing(
        &self,
        request: impl Into<show::GetRequest>,
    ) -> Result<BulkPairing> {
        self.get_single_model(request.into()).await
    }

    pub async fn cancel_bulk_pairing(
        &self,
        request: impl Into<remove::DeleteRequest>,
    ) -> Result<bool> {
        self.get_ok(request.into()).await
    }

    pub async fn export_bulk_pairing_games(
        &self,
        id: &str,
        query: games::GetQuery,
    ) -> Result<impl StreamExt<Item = Result<GameJson>>> {
        self.get_streamed_models(games::GetRequest::new(id, query))
            .await
    }

    pub async fn start_bulk_pairing_clocks(
        &self,
        request: impl Into<start_clocks::PostRequest>,
    ) -> Result<bool> {
        self.get_ok(request.into()).await
    }
}