libpixiv 0.2.1

pixiv.net API client library
Documentation
use reqwest_middleware::reqwest::StatusCode;
use std::{error::Error, fmt::Display};

/// Core client functionality
pub mod client;
/// Illustration endpoints for the client
pub mod illusts;
/// API data models
pub mod models;
/// Search endpoints for the client
pub mod search;
/// Token store for the client
pub mod tokens;
/// Ugora (GIF) endpoints for the client
pub mod ugoira;
/// User endpoints for the client
pub mod users;

#[cfg(feature = "clap")]
pub use clap;
pub use reqwest_middleware::reqwest;
#[cfg(feature = "sqlx")]
pub use sqlx;

/// Pixiv application errors
#[derive(Debug, Clone)]
pub enum PixivAppError {
    /// (404) the requested content does not exist
    TargetNotFound,
    /// (400) the request failed, probably because it is malformed
    RequestFailed,
    /// (403) the request is not authorized and we need to log in
    MissingLogin,
    /// (429) we've hit the rate limit and need to wait a bit (no, we do not get headers that tell
    /// us how long we should wait)
    RateLimitReached,
    /// (everything else) the request was sent and the server responded, but we dont know what
    /// exactly the issue is
    UnhandledStatus(StatusCode),
    /// no one knows what went wrong
    Unknown,
}

impl Error for PixivAppError {}
impl Display for PixivAppError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "{}",
            match self {
                PixivAppError::TargetNotFound => "Requested endpoint not found",
                PixivAppError::RequestFailed => "Request failed, check request parameters!",
                PixivAppError::MissingLogin => "Request failed because of missing authorization!",
                PixivAppError::RateLimitReached => "Too many requests, try again later",
                PixivAppError::UnhandledStatus(s) => s.as_str(),
                PixivAppError::Unknown => "An unknown error happened and no data was returned.",
            }
        )
    }
}