Skip to main content

lichess_api/api/
users.rs

1//! Public user profiles, ratings, and activity.
2//!
3//! Covers looking up one or many users ([`LichessApi::get_public_user_data`],
4//! [`LichessApi::get_users_by_id`], [`LichessApi::autocomplete_users`]),
5//! ratings and leaderboards ([`LichessApi::get_one_leaderboard`],
6//! [`LichessApi::get_all_top_10`], [`LichessApi::get_rating_history`],
7//! [`LichessApi::get_user_performance_statistics`],
8//! [`LichessApi::get_crosstable`]), online/playing/streaming status
9//! ([`LichessApi::get_status_of_users`], [`LichessApi::get_live_streamers`]),
10//! and a user's activity feed ([`LichessApi::get_user_activity`]).
11//!
12//! Most of these endpoints are public and work without a token. The private
13//! note endpoints ([`LichessApi::add_note_to_user`],
14//! [`LichessApi::get_user_notes`]) are the exception — they read and write
15//! notes that only your own account can see, so they require a token.
16
17use crate::client::LichessApi;
18use crate::error::Result;
19use crate::model::users::*;
20
21impl LichessApi<reqwest::Client> {
22    pub async fn get_all_top_10(&self) -> Result<Top10s> {
23        self.get_single_model(top_10::GetRequest::default()).await
24    }
25
26    pub async fn get_one_leaderboard(
27        &self,
28        request: impl Into<leaderboard::GetRequest>,
29    ) -> Result<Leaderboard> {
30        self.get_single_model(request.into()).await
31    }
32
33    pub async fn get_public_user_data(
34        &self,
35        request: impl Into<public::GetRequest>,
36    ) -> Result<UserExtended> {
37        self.get_single_model(request.into()).await
38    }
39
40    pub async fn get_status_of_users(
41        &self,
42        request: impl Into<status::GetRequest>,
43    ) -> Result<Vec<status::User>> {
44        self.get_single_model(request.into()).await
45    }
46
47    pub async fn get_rating_history(
48        &self,
49        request: impl Into<rating_history::GetRequest>,
50    ) -> Result<rating_history::RatingHistory> {
51        self.get_single_model(request.into()).await
52    }
53
54    pub async fn get_user_performance_statistics(
55        &self,
56        request: impl Into<performance::GetRequest>,
57    ) -> Result<performance::PerfStat> {
58        self.get_single_model(request.into()).await
59    }
60
61    pub async fn get_users_by_id(
62        &self,
63        request: impl Into<by_id::PostRequest>,
64    ) -> Result<Vec<User>> {
65        self.get_single_model(request.into()).await
66    }
67
68    pub async fn get_live_streamers(&self) -> Result<Vec<StreamingUser>> {
69        self.get_single_model(live_streamers::GetRequest::new())
70            .await
71    }
72
73    pub async fn get_crosstable(
74        &self,
75        request: impl Into<crosstable::GetRequest>,
76    ) -> Result<Crosstable> {
77        self.get_single_model(request.into()).await
78    }
79
80    pub async fn autocomplete_users(
81        &self,
82        request: impl Into<autocomplete::GetRequest>,
83    ) -> Result<autocomplete::Autocompletions> {
84        self.get_single_model(request.into()).await
85    }
86
87    pub async fn add_note_to_user(
88        &self,
89        request: impl Into<note::PostRequest>,
90    ) -> Result<crate::model::Ok> {
91        self.get_single_model(request.into()).await
92    }
93
94    pub async fn get_user_notes(
95        &self,
96        request: impl Into<note::GetRequest>,
97    ) -> Result<Vec<UserNote>> {
98        self.get_single_model(request.into()).await
99    }
100
101    pub async fn get_user_activity(
102        &self,
103        request: impl Into<activity::GetRequest>,
104    ) -> Result<Vec<activity::UserActivity>> {
105        self.get_single_model(request.into()).await
106    }
107}