enbbox 1.0.1

Notification infrastructure API — open-source alternative to Novu/Courier
Documentation
/*
 * enbbox API
 *
 * Notification infrastructure API — open-source alternative to Novu/Courier
 *
 * The version of the OpenAPI document: 1.0.0
 * 
 * Generated by: https://openapi-generator.tech
 */


use async_trait::async_trait;
#[cfg(feature = "mockall")]
use mockall::automock;
use reqwest;
use std::sync::Arc;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration};
use crate::apis::ContentType;

#[cfg_attr(feature = "mockall", automock)]
#[async_trait]
pub trait InboundParseApi: Send + Sync {

    /// POST /v1/inbound-parse/webhook/
    ///
    /// This endpoint receives inbound emails (e.g., replies to notification threads) from email service providers like SendGrid, Postmark, etc.
    async fn inbound_parse_webhook<'body>(&self, body: Option<serde_json::Value>) -> Result<(), Error<InboundParseWebhookError>>;
}

pub struct InboundParseApiClient {
    configuration: Arc<configuration::Configuration>
}

impl InboundParseApiClient {
    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
        Self { configuration }
    }
}



#[async_trait]
impl InboundParseApi for InboundParseApiClient {
    /// This endpoint receives inbound emails (e.g., replies to notification threads) from email service providers like SendGrid, Postmark, etc.
    async fn inbound_parse_webhook<'body>(&self, body: Option<serde_json::Value>) -> Result<(), Error<InboundParseWebhookError>> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!("{}/v1/inbound-parse/webhook/", local_var_configuration.base_path);
        let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
            local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
        }
        local_var_req_builder = local_var_req_builder.json(&body);

        let local_var_req = local_var_req_builder.build()?;
        let local_var_resp = local_var_client.execute(local_var_req).await?;

        let local_var_status = local_var_resp.status();
        let local_var_content = local_var_resp.text().await?;

        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
            Ok(())
        } else {
            let local_var_entity: Option<InboundParseWebhookError> = serde_json::from_str(&local_var_content).ok();
            let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
            Err(Error::ResponseError(local_var_error))
        }
    }

}

/// struct for typed errors of method [`InboundParseApi::inbound_parse_webhook`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum InboundParseWebhookError {
    UnknownValue(serde_json::Value),
}