mangadex-api 4.2.1

SDK for the MangaDex API
Documentation
use crate::{error::Error, Result};
use reqwest::{Client, Response};
use serde::Serialize;
use url::Url;

/// Send a report to `https://api.mangadex.network/report`.
///
/// More details at : https://api.mangadex.org/docs/retrieving-chapter/#the-mangadexhome-report-endpoint
#[derive(Serialize, Clone)]
#[non_exhaustive]
pub struct AtHomeReport {
    pub url: Url,
    pub success: bool,
    pub cached: bool,
    pub bytes: usize,
    pub duration: u128,
}

impl AtHomeReport {
    pub async fn send(&self, client: &Client) -> Result<Response> {
        if !self.url.as_str().contains("mangadex.org") {
            match client
                .post("https://api.mangadex.network/report")
                .json(self)
                .timeout(std::time::Duration::from_secs(2))
                .send()
                .await
            {
                Ok(d) => Result::Ok(d),
                Err(e) => Result::Err(Error::RequestError(e)),
            }
        } else {
            Result::Err(Error::unknow("the mangadex.org pattern found!"))
        }
    }
}