mcsr_ranked_api/user/
requests.rs

1use serde::Serialize;
2
3#[cfg(feature = "blocking")]
4use crate::helpers::make_request_blocking;
5use crate::{helpers::make_request, types::Season, Result};
6
7use super::{
8	identifier::UserIdentifier,
9	info::{all_seasons::AllSeasonUserInfo, UserInfo},
10};
11
12const BASE_URL: &str = "https://api.mcsrranked.com/users/{}";
13const ALL_SEASONS_URL: &str = "https://api.mcsrranked.com/users/{}/seasons";
14
15/// Parameters for [`UserIdentifier::get_user`]
16#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize)]
17#[serde(rename_all = "lowercase")]
18pub struct GetUserParams {
19	/// Season to get the user info for
20	///
21	/// Default is the current season
22	pub season: Option<Season>,
23}
24impl GetUserParams {
25	pub fn new(season: Season) -> Self {
26		Self {
27			season: Some(season),
28		}
29	}
30}
31
32impl UserIdentifier<'_> {
33	/// GET the user by identifier using given `params`
34	pub async fn get_user(&self, params: Option<&GetUserParams>) -> Result<UserInfo> {
35		make_request(BASE_URL, [&self.to_string()], Some(&params)).await
36	}
37	/// GET the user's info with data from all seasons
38	pub async fn get_user_all_seasons(&self) -> Result<AllSeasonUserInfo> {
39		make_request(ALL_SEASONS_URL, &[&self.to_string()], None::<&()>).await
40	}
41}
42
43#[cfg(feature = "blocking")]
44impl UserIdentifier<'_> {
45	/// Synchronously GET the user by identifier using given `params`
46	pub fn get_user_blocking(&self, params: Option<&GetUserParams>) -> Result<UserInfo> {
47		make_request_blocking(BASE_URL, [&self.to_string()], Some(&params))
48	}
49	/// Synchronously GET the user's info with data from all seasons
50	pub fn get_user_all_seasons_blocking(&self) -> Result<AllSeasonUserInfo> {
51		make_request_blocking(ALL_SEASONS_URL, &[&self.to_string()], None::<&()>)
52	}
53}