Skip to main content

mcsr_ranked_api/user/
requests.rs

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