pub mod interface;
#[cfg(test)]
mod test;
use crate::{DlsiteClient, DlsiteError, Result};
use self::interface::ProductApiContent;
impl DlsiteClient {
pub async fn get_product_api(&self, id: &str) -> Result<ProductApiContent> {
let json = self
.get(&format!("/api/=/product.json?workno={}", id))
.await?;
let jd = &mut serde_json::Deserializer::from_str(&json);
#[cfg(feature = "unknown-field-log")]
let result: std::result::Result<Vec<ProductApiContent>, _> = serde_ignored::deserialize(
jd,
|path| {
tracing::error!("Ignored path: '{}' for '{id}'. Please report this to https://github.com/ozonezone/dlsite-rs", path.to_string());
},
);
#[cfg(not(feature = "unknown-field-log"))]
let result: std::result::Result<Vec<ProductApiContent>, _> =
serde_path_to_error::deserialize(jd);
match result {
Ok(result) => {
let Some(json) = result.into_iter().next() else {
return Err(DlsiteError::ParseError("No product found".to_string()));
};
Ok(json)
}
Err(e) => Err(DlsiteError::ParseError(format!(
"Failed to parse json: {}",
e
))),
}
}
}