postal_api 0.2.1

A Rust implementation for the Postal mail delivery platform.
Documentation
use derive_more::Display;
use serde::Deserialize;
use thiserror::Error;

/// Any error that can happen when interacting with the Postal Client
#[derive(Debug, Error)]
pub enum PostalClientError {
    #[error(transparent)]
    Api(#[from] PostalApiError),

    #[error(transparent)]
    Reqwest(#[from] reqwest::Error),
}

/// Represents any error that can happen AFTER sending
/// the message to the API
#[derive(Debug, Error, Display, Deserialize)]
pub enum PostalApiError {
    #[display(fmt = "An invalid API Key was given")]
    InvalidServerAPIKey,
    #[display(fmt = "The mail server has been suspended")]
    ServerSuspended,
    #[display(fmt = "The From address is not authorised to send mail from this server")]
    UnauthenticatedFromAddress,
}

/// Any issues that can come up when building a message
///
/// Most of these Errors are modeled after the API Errors.
/// see: <http://apiv1.postalserver.io/controllers/send/message>
#[derive(Debug, Error, Display, PartialEq)]
pub enum MessageBuilderError {
    /// to can take 50 emails at most,
    /// This error signals that you added to many of one
    #[display(fmt = "Too many Email addresses have been added to the 'to' field")]
    TooManyToAddresses,

    /// cc can take 50 emails at most,
    /// This error signals that you added to many of one
    #[display(fmt = "Too many Email addresses have been added to the 'cc' field")]
    TooManyCCAddresses,

    /// bcc can take 50 emails at most,
    /// This error signals that you added to many of one
    #[display(fmt = "Too many Email addresses have been added to the 'bcc' field.")]
    TooManyBCCAddresses,

    /// You need at least one recipient.
    #[display(fmt = "No recipients were added. 
        Please use 'add_to' or 'append_to' to add at least one Recipient.")]
    NoRecipients,

    /// You need to send along some content
    #[display(fmt = "No content has been added.
        Please use 'set_plain_body' ot 'set_html_body' to add content for this Message.")]
    NoContent,

    /// The header field you're trying to set has already been set
    #[display(fmt = "You are trying to add a Header field that has already been added.")]
    HeaderExists,

    /// You must Specify a Source
    #[display(fmt = "You must specify a source address with 'set_from'.")]
    FromAddressMissing,
}