foru_ms_sdk 0.0.40

SDK for the Foru.ms API
Documentation
use crate::api::*;
use crate::{ApiError, ClientConfig, HttpClient, QueryBuilder, RequestOptions};
use reqwest::Method;

pub struct WebhooksClient {
    pub http_client: HttpClient,
}

impl WebhooksClient {
    pub fn new(config: ClientConfig) -> Result<Self, ApiError> {
        Ok(Self {
            http_client: HttpClient::new(config.clone())?,
        })
    }

    pub async fn list_all_webhooks(
        &self,
        request: &ListAllWebhooksQueryRequest,
        options: Option<RequestOptions>,
    ) -> Result<GetWebhooksResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::GET,
                "webhooks",
                None,
                QueryBuilder::new()
                    .int("page", request.page.clone())
                    .int("limit", request.limit.clone())
                    .string("search", request.search.clone())
                    .build(),
                options,
            )
            .await
    }

    pub async fn create_a_webhook(
        &self,
        request: &PostWebhooksRequest,
        options: Option<RequestOptions>,
    ) -> Result<PostWebhooksResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::POST,
                "webhooks",
                Some(serde_json::to_value(request).unwrap_or_default()),
                None,
                options,
            )
            .await
    }

    pub async fn get_a_webhook(
        &self,
        id: &String,
        options: Option<RequestOptions>,
    ) -> Result<GetWebhooksIDResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::GET,
                &format!("webhooks/{}", id),
                None,
                None,
                options,
            )
            .await
    }

    pub async fn delete_a_webhook(
        &self,
        id: &String,
        options: Option<RequestOptions>,
    ) -> Result<DeleteWebhooksIDResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::DELETE,
                &format!("webhooks/{}", id),
                None,
                None,
                options,
            )
            .await
    }

    pub async fn list_webhook_deliveries(
        &self,
        id: &String,
        request: &ListWebhookDeliveriesQueryRequest,
        options: Option<RequestOptions>,
    ) -> Result<GetWebhooksIDDeliveriesResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::GET,
                &format!("webhooks/{}/deliveries", id),
                None,
                QueryBuilder::new()
                    .string("cursor", request.cursor.clone())
                    .int("limit", request.limit.clone())
                    .build(),
                options,
            )
            .await
    }

    pub async fn get_a_delivery_from_webhook(
        &self,
        id: &String,
        sub_id: &String,
        options: Option<RequestOptions>,
    ) -> Result<GetWebhooksIDDeliveriesSubIDResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::GET,
                &format!("webhooks/{}/deliveries/{}", id, sub_id),
                None,
                None,
                options,
            )
            .await
    }

    pub async fn delete_a_delivery_from_webhook(
        &self,
        id: &String,
        sub_id: &String,
        options: Option<RequestOptions>,
    ) -> Result<DeleteWebhooksIDDeliveriesSubIDResponse, ApiError> {
        self.http_client
            .execute_request(
                Method::DELETE,
                &format!("webhooks/{}/deliveries/{}", id, sub_id),
                None,
                None,
                options,
            )
            .await
    }
}