use reqwest::Method;
use serde::{Deserialize, Serialize};
use crate::client::{Client, Response};
use crate::errors::Result;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct User {
pub id: String,
pub resource: String,
pub resource_path: String,
pub name: Option<String>,
pub username: Option<String>,
pub profile_location: Option<String>,
pub profile_bio: Option<String>,
pub profile_url: Option<String>,
pub avatar_url: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Auth {
pub method: String,
pub scopes: Vec<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct UserUpdate<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
pub time_zone: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
pub native_currency: Option<&'a str>,
}
impl Client {
pub async fn get_user(&self, user_id: &str) -> Result<Response<User>> {
self.send_request(Method::GET, &format!("users/{}", user_id), None::<&()>)
.await
}
pub async fn get_current_user(&self) -> Result<Response<User>> {
self.send_request(Method::GET, "user", None::<&()>).await
}
pub async fn get_auth_info(&self) -> Result<Response<Auth>> {
self.send_request(Method::GET, "user/auth", None::<&()>)
.await
}
pub async fn update_user<'a>(&self, update: &'a UserUpdate<'a>) -> Result<Response<User>> {
self.send_request(Method::PUT, "user", Some(update)).await
}
}