Skip to main content

lichess_api/api/
relations.rs

1//! Follow, unfollow, and block other Lichess players.
2//!
3//! [`LichessApi::get_following`] streams the users the authenticated account
4//! follows; the request/response types live in [`crate::model::relations`].
5//! All operations here act on behalf of the authenticated user and require
6//! the `follow:read` or `follow:write` OAuth scope, as appropriate.
7
8use futures::stream::StreamExt;
9
10use crate::client::LichessApi;
11use crate::error::Result;
12use crate::model::relations::*;
13use crate::model::users::UserExtended;
14
15impl LichessApi<reqwest::Client> {
16    pub async fn get_following(
17        &self,
18        request: impl Into<following::GetRequest>,
19    ) -> Result<impl StreamExt<Item = Result<UserExtended>>> {
20        self.get_streamed_models(request.into()).await
21    }
22
23    pub async fn follow_user(&self, request: impl Into<follow::PostRequest>) -> Result<bool> {
24        self.get_ok(request.into()).await
25    }
26
27    pub async fn unfollow_user(&self, request: impl Into<unfollow::PostRequest>) -> Result<bool> {
28        self.get_ok(request.into()).await
29    }
30
31    pub async fn block_user(&self, request: impl Into<block::PostRequest>) -> Result<bool> {
32        self.get_ok(request.into()).await
33    }
34
35    pub async fn unblock_user(&self, request: impl Into<unblock::PostRequest>) -> Result<bool> {
36        self.get_ok(request.into()).await
37    }
38}