use crate::client::PixivAppClient;
use crate::models::{PixivResult, UgoiraMetadata};
use crate::PixivAppError;
use reqwest::Method;
use std::error::Error;
impl PixivAppClient {
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
.auth_request(Method::GET, url)
.await
.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]
async fn test_ugoira() {
let result = get_client().await.ugoira_metadata(ILLUST_ID).await;
assert!(
result.is_ok(),
"Failed to fetch ugoira metadata: {}",
result.err().unwrap()
);
}
}