basecamp-sdk 0.38.0

Official client for Basecamp - https://basecamp.com
Documentation
// Generated by basecamp-sdk-generator from openapi.json and behavior-model.json. DO NOT EDIT.

//! Webhooks operations.

#![allow(
    clippy::too_many_arguments,
    clippy::wildcard_imports,
    clippy::doc_markdown
)]

use crate::client::AccountClient;
use crate::error::Error;
use crate::generated::routes;
#[allow(unused_imports)]
use crate::generated::types::*;
use crate::pagination::Page;

/// `Webhooks` operations, sent through one [`AccountClient`].
#[derive(Debug, Clone, Copy)]
pub struct WebhooksService<'a> {
    client: &'a AccountClient,
}

impl<'a> WebhooksService<'a> {
    pub(crate) fn new(client: &'a AccountClient) -> Self {
        Self { client }
    }

    /// The client this service sends through.
    pub fn client(&self) -> &'a AccountClient {
        self.client
    }

    /// Create a new webhook for a project
    ///
    /// `POST /buckets/{bucketId}/webhooks.json` — not idempotent, sent exactly once.
    pub async fn create(
        &self,
        bucket_id: i64,
        body: &CreateWebhookRequestContent,
    ) -> Result<CreateWebhookResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::CREATE_WEBHOOK, &[&bucket_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Delete a webhook
    ///
    /// `DELETE /webhooks/{webhookId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn delete(&self, webhook_id: i64) -> Result<(), Error> {
        let operation = self
            .client
            .operation(&routes::DELETE_WEBHOOK, &[&webhook_id]);
        self.client.send_unit(operation).await
    }

    /// Get a single webhook by id
    ///
    /// `GET /webhooks/{webhookId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn get(&self, webhook_id: i64) -> Result<GetWebhookResponseContent, Error> {
        let operation = self.client.operation(&routes::GET_WEBHOOK, &[&webhook_id]);
        self.client.send(operation).await
    }

    /// List all webhooks for a project
    ///
    /// **Pagination**: Uses Link header (RFC5988). Follow the `next` rel URL
    /// to fetch additional pages. X-Total-Count header provides total count.
    ///
    /// `GET /buckets/{bucketId}/webhooks.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn list(&self, bucket_id: i64) -> Result<Page<ListWebhooksResponseContent>, Error> {
        let operation = self.client.operation(&routes::LIST_WEBHOOKS, &[&bucket_id]);
        self.client.send_page(operation).await
    }

    /// Update an existing webhook
    ///
    /// `PUT /webhooks/{webhookId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn update(
        &self,
        webhook_id: i64,
        body: &UpdateWebhookRequestContent,
    ) -> Result<UpdateWebhookResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::UPDATE_WEBHOOK, &[&webhook_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }
}