#[cfg(feature = "modrinth-write")]
use super::models::ModifyUserRequest;
use super::models::{PayoutHistory, Project, User};
use super::{Authed, ModrinthClient, encode_id_or_slug};
use crate::error::Result;
impl ModrinthClient {
pub async fn user(&self, id_or_username: &str) -> Result<User> {
let seg = encode_id_or_slug(id_or_username)?;
self.get_json(&format!("/user/{seg}")).await
}
pub async fn users(&self, ids: &[impl AsRef<str>]) -> Result<Vec<User>> {
self.get_by_ids("/users", ids).await
}
pub async fn user_projects(&self, id_or_username: &str) -> Result<Vec<Project>> {
let seg = encode_id_or_slug(id_or_username)?;
self.get_json(&format!("/user/{seg}/projects")).await
}
}
impl<'a> Authed<'a> {
pub async fn current_user(&self) -> Result<User> {
self.get_authed_json("/user").await
}
pub async fn followed_projects(&self, id_or_username: &str) -> Result<Vec<Project>> {
let seg = encode_id_or_slug(id_or_username)?;
self.get_authed_json(&format!("/user/{seg}/follows")).await
}
pub async fn user_payouts(&self, id_or_username: &str) -> Result<PayoutHistory> {
let seg = encode_id_or_slug(id_or_username)?;
self.get_authed_json(&format!("/user/{seg}/payouts")).await
}
}
#[cfg(feature = "modrinth-write")]
#[cfg_attr(docsrs, doc(cfg(feature = "modrinth-write")))]
impl<'a> Authed<'a> {
pub async fn modify_user(&self, id_or_username: &str, req: &ModifyUserRequest) -> Result<()> {
let seg = encode_id_or_slug(id_or_username)?;
self.patch_authed_json(&format!("/user/{seg}"), req).await
}
pub async fn change_user_icon(
&self,
id_or_username: &str,
ext: &str,
bytes: Vec<u8>,
content_type: &str,
) -> Result<()> {
let seg = encode_id_or_slug(id_or_username)?;
self.upload_icon(&format!("/user/{seg}/icon"), ext, bytes, content_type)
.await
}
pub async fn withdraw_payout(&self, id_or_username: &str, amount: f64) -> Result<()> {
let seg = encode_id_or_slug(id_or_username)?;
self.send_authed(&format!("/user/{seg}/payouts"), |c, t| {
c.post(t).query(&[("amount", amount)])
})
.await?;
Ok(())
}
}