lichess-api 1.0.0

A client library for the Lichess API
Documentation
//! Public user profiles, ratings, and activity.
//!
//! Covers looking up one or many users ([`LichessApi::get_public_user_data`],
//! [`LichessApi::get_users_by_id`], [`LichessApi::autocomplete_users`]),
//! ratings and leaderboards ([`LichessApi::get_one_leaderboard`],
//! [`LichessApi::get_all_top_10`], [`LichessApi::get_rating_history`],
//! [`LichessApi::get_user_performance_statistics`],
//! [`LichessApi::get_crosstable`]), online/playing/streaming status
//! ([`LichessApi::get_status_of_users`], [`LichessApi::get_live_streamers`]),
//! and a user's activity feed ([`LichessApi::get_user_activity`]).
//!
//! Most of these endpoints are public and work without a token. The private
//! note endpoints ([`LichessApi::add_note_to_user`],
//! [`LichessApi::get_user_notes`]) are the exception — they read and write
//! notes that only your own account can see, so they require a token.

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

impl LichessApi<reqwest::Client> {
    pub async fn get_all_top_10(&self) -> Result<Top10s> {
        self.get_single_model(top_10::GetRequest::default()).await
    }

    pub async fn get_one_leaderboard(
        &self,
        request: impl Into<leaderboard::GetRequest>,
    ) -> Result<Leaderboard> {
        self.get_single_model(request.into()).await
    }

    pub async fn get_public_user_data(
        &self,
        request: impl Into<public::GetRequest>,
    ) -> Result<UserExtended> {
        self.get_single_model(request.into()).await
    }

    pub async fn get_status_of_users(
        &self,
        request: impl Into<status::GetRequest>,
    ) -> Result<Vec<status::User>> {
        self.get_single_model(request.into()).await
    }

    pub async fn get_rating_history(
        &self,
        request: impl Into<rating_history::GetRequest>,
    ) -> Result<rating_history::RatingHistory> {
        self.get_single_model(request.into()).await
    }

    pub async fn get_user_performance_statistics(
        &self,
        request: impl Into<performance::GetRequest>,
    ) -> Result<performance::PerfStat> {
        self.get_single_model(request.into()).await
    }

    pub async fn get_users_by_id(
        &self,
        request: impl Into<by_id::PostRequest>,
    ) -> Result<Vec<User>> {
        self.get_single_model(request.into()).await
    }

    pub async fn get_live_streamers(&self) -> Result<Vec<StreamingUser>> {
        self.get_single_model(live_streamers::GetRequest::new())
            .await
    }

    pub async fn get_crosstable(
        &self,
        request: impl Into<crosstable::GetRequest>,
    ) -> Result<Crosstable> {
        self.get_single_model(request.into()).await
    }

    pub async fn autocomplete_users(
        &self,
        request: impl Into<autocomplete::GetRequest>,
    ) -> Result<autocomplete::Autocompletions> {
        self.get_single_model(request.into()).await
    }

    pub async fn add_note_to_user(
        &self,
        request: impl Into<note::PostRequest>,
    ) -> Result<crate::model::Ok> {
        self.get_single_model(request.into()).await
    }

    pub async fn get_user_notes(
        &self,
        request: impl Into<note::GetRequest>,
    ) -> Result<Vec<UserNote>> {
        self.get_single_model(request.into()).await
    }

    pub async fn get_user_activity(
        &self,
        request: impl Into<activity::GetRequest>,
    ) -> Result<Vec<activity::UserActivity>> {
        self.get_single_model(request.into()).await
    }
}