1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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()),
        }
    }
}