mal-cli-rs 0.2.1

CLI tool for myanimelist
Documentation
use super::model::*;
use super::Error;
use super::{get, handle_response, API_URL};
use crate::auth::OAuth;
use serde::Serialize;

#[derive(Clone, Debug, Serialize)]
pub struct GetUserInformationQuery {
    pub fields: Option<String>,
}

pub async fn get_my_user_information<U: ToString>(
    user: U,
    query: &GetUserInformationQuery,
    auth: &OAuth,
) -> Result<UserInfo, Error> {
    let response = get(
        &format!(
            "{}/users/{}?{}",
            API_URL,
            user.to_string(),
            serde_urlencoded::to_string(query)?
        ),
        auth,
    )
    .await?;
    handle_response(&response)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[tokio::test]
    async fn test_get_user_information() {
        let auth = crate::auth::tests::get_auth();
        let query = GetUserInformationQuery {
            fields: Some(ALL_USER_FIELDS.to_string()),
        };
        let result = get_my_user_information("@me", &query, &auth).await.unwrap();
        println!("{:#?}", result);
    }
}