btcpay-client 0.1.0

A client library for BTCPay Server.
Documentation
use std::error;
use std::fmt;

#[derive(Debug, Clone)]
pub struct ResponseContent<T> {
    pub status: reqwest::StatusCode,
    pub content: String,
    pub entity: Option<T>,
}

#[derive(Debug)]
pub enum Error<T> {
    Reqwest(reqwest::Error),
    Serde(serde_json::Error),
    Io(std::io::Error),
    ResponseError(ResponseContent<T>),
}

impl <T> fmt::Display for Error<T> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let (module, e) = match self {
            Error::Reqwest(e) => ("reqwest", e.to_string()),
            Error::Serde(e) => ("serde", e.to_string()),
            Error::Io(e) => ("IO", e.to_string()),
            Error::ResponseError(e) => ("response", format!("status code {}", e.status)),
        };
        write!(f, "error in {}: {}", module, e)
    }
}

impl <T: fmt::Debug> error::Error for Error<T> {
    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        Some(match self {
            Error::Reqwest(e) => e,
            Error::Serde(e) => e,
            Error::Io(e) => e,
            Error::ResponseError(_) => return None,
        })
    }
}

impl <T> From<reqwest::Error> for Error<T> {
    fn from(e: reqwest::Error) -> Self {
        Error::Reqwest(e)
    }
}

impl <T> From<serde_json::Error> for Error<T> {
    fn from(e: serde_json::Error) -> Self {
        Error::Serde(e)
    }
}

impl <T> From<std::io::Error> for Error<T> {
    fn from(e: std::io::Error) -> Self {
        Error::Io(e)
    }
}

pub fn urlencode<T: AsRef<str>>(s: T) -> String {
    ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect()
}

pub mod api_keys_api;
pub mod apps_api;
pub mod authorization_api;
pub mod custodians_api;
pub mod health_api;
pub mod invoices_api;
pub mod lightning_internal_node_api;
pub mod lightning_store_api;
pub mod miscelleneous_api;
pub mod notifications_current_user_api;
pub mod payment_requests_api;
pub mod payout_processors_api;
pub mod pull_payments_management_api;
pub mod pull_payments_payout_public_api;
pub mod pull_payments_public_api;
pub mod server_info_api;
pub mod store_payment_methods_api;
pub mod store_payment_methods_lnurl_pay_api;
pub mod store_payment_methods_lightning_network_api;
pub mod store_payment_methods_on_chain_api;
pub mod store_wallet_on_chain_api;
pub mod stores_api;
pub mod stores_email_api;
pub mod stores_payout_processors_api;
pub mod stores_payouts_api;
pub mod stores_users_api;
pub mod users_api;
pub mod webhooks_api;

pub mod configuration;