libpixiv 0.2.5

pixiv.net API client library
Documentation
use crate::client::PixivAppClient;
use crate::models::{PixivResult, UgoiraMetadata};
use crate::PixivAppError;
use reqwest_middleware::reqwest::Method;
use std::error::Error;

impl PixivAppClient {
    /// Fetch metadata for ugoira (GIFs)
    pub async fn ugoira_metadata(
        &self,
        illust_id: u32,
    ) -> Result<UgoiraMetadata, Box<dyn Error + Send + Sync>> {
        let url = format!("{}/v1/ugoira/metadata", self.host);

        let req = self
            .http_client
            .request(Method::GET, url)
            .query(&[("illust_id", illust_id)]);

        let res = self.process_request::<PixivResult>(req).await?;
        res.ugoira_metadata.ok_or(res.error.map_or_else(
            || Box::<dyn Error + Sync + Send>::from(PixivAppError::Unknown),
            |v| Box::new(v),
        ))
    }
}

#[cfg(test)]
mod tests {
    use crate::client::tests::get_client;
    use tokio::test;

    static ILLUST_ID: u32 = 115401474;

    #[test]
    pub(crate) async fn test_ugoira() {
        let result = get_client().ugoira_metadata(ILLUST_ID).await;
        assert!(
            result.is_ok(),
            "Failed to fetch ugoira metadata: {}",
            result.err().unwrap()
        );
    }
}