mal/api/
user.rs

1use super::model::*;
2use super::Error;
3use super::{get, handle_response, API_URL};
4use crate::auth::OAuth;
5use serde::Serialize;
6
7#[derive(Clone, Debug, Serialize)]
8pub struct GetUserInformationQuery {
9    pub fields: Option<String>,
10}
11
12pub async fn get_my_user_information<U: ToString>(
13    user: U,
14    query: &GetUserInformationQuery,
15    auth: &OAuth,
16) -> Result<UserInfo, Error> {
17    let response = get(
18        &format!(
19            "{}/users/{}?{}",
20            API_URL,
21            user.to_string(),
22            serde_urlencoded::to_string(query)?
23        ),
24        auth,
25    )
26    .await?;
27    handle_response(&response)
28}
29
30#[cfg(test)]
31mod tests {
32    use super::*;
33
34    #[tokio::test]
35    async fn test_get_user_information() {
36        let auth = crate::auth::tests::get_auth();
37        let query = GetUserInformationQuery {
38            fields: Some(ALL_USER_FIELDS.to_string()),
39        };
40        let result = get_my_user_information("@me", &query, &auth).await.unwrap();
41        println!("{:#?}", result);
42    }
43}