use crate::prelude::*;
use rive_models::{
data::{ChangeUsernameData, EditUserData},
user::{User, UserProfile},
};
impl Client {
pub async fn fetch_self(&self) -> Result<User> {
Ok(self
.client
.get(ep!(self, "/users/@me"))
.auth(&self.authentication)
.send()
.await?
.process_error()
.await?
.json()
.await?)
}
pub async fn edit_user(&self, data: EditUserData) -> Result<User> {
Ok(self
.client
.patch(ep!(self, "/users/@me"))
.auth(&self.authentication)
.json(&data)
.send()
.await?
.process_error()
.await?
.json()
.await?)
}
pub async fn fetch_user(&self, id: impl Into<String>) -> Result<User> {
Ok(self
.client
.get(ep!(self, "/users/{}", id.into()))
.auth(&self.authentication)
.send()
.await?
.process_error()
.await?
.json()
.await?)
}
pub async fn change_username(&self, data: ChangeUsernameData) -> Result<User> {
Ok(self
.client
.patch(ep!(self, "/users/@me/username"))
.auth(&self.authentication)
.json(&data)
.send()
.await?
.process_error()
.await?
.json()
.await?)
}
pub async fn fetch_default_avatar(&self, id: impl Into<String>) -> Result<Vec<u8>> {
Ok(self
.client
.get(ep!(self, "/users/{}/default_avatar", id.into()))
.auth(&self.authentication)
.send()
.await?
.process_error()
.await?
.bytes()
.await?
.into())
}
pub async fn fetch_user_profile(&self, id: impl Into<String>) -> Result<UserProfile> {
Ok(self
.client
.get(ep!(self, "/users/{}/profile", id.into()))
.auth(&self.authentication)
.send()
.await?
.process_error()
.await?
.json()
.await?)
}
}