use super::*;
#[derive(Deserialize, Serialize, Debug)]
pub struct Token {
pub id: i32,
pub user: i32,
pub created: time::PrimitiveDateTime,
pub name: Option<String>,
}
impl Client {
pub async fn tokens(
&self,
user: i32,
) -> Result<Option<Vec<Token>>, Box<dyn std::error::Error>> {
let res = req()
.get(self.endpoint("/v1/users/{}/tokens", vec![user.to_string()]))
.send()
.await?;
match res.status() {
StatusCode::NOT_FOUND => Ok(None),
StatusCode::OK => Ok(Some(res.json::<Vec<Token>>().await?)),
_ => Err("Unknown Response Status Code".into()),
}
}
}