fizzy-sdk 0.2.4

Official Fizzy API client, generated from the Smithy model in spec/
Documentation
// Generated by fizzy-sdk-generator from openapi.json and behavior-model.json. DO NOT EDIT.

use crate::client::Scope;
use crate::error::Error;
use crate::generated::routes;
use crate::generated::types::*;
use crate::pagination::Page;

/// The `Webhooks` operations.
pub struct WebhooksService<'a> {
    scope: Scope<'a>,
}

impl<'a> WebhooksService<'a> {
    pub(crate) fn new(scope: Scope<'a>) -> Self {
        Self { scope }
    }

    /// The client and account these operations send through.
    pub fn scope(&self) -> &Scope<'a> {
        &self.scope
    }

    /// `ActivateWebhook` — `POST /{accountId}/boards/{boardId}/webhooks/{webhookId}/activation.json`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503. Idempotent, so a resend is safe.
    pub async fn activate(&self, board_id: &str, webhook_id: &str) -> Result<(), Error> {
        let mut operation = self
            .scope
            .operation(&routes::ACTIVATE_WEBHOOK, &[&board_id, &webhook_id])?;
        operation.resource_id(board_id);
        self.scope.client().send_unit(operation).await
    }

    /// `CreateWebhook` — `POST /{accountId}/boards/{boardId}/webhooks.json`.
    ///
    /// Sent once and never resent.
    pub async fn create(
        &self,
        board_id: &str,
        body: &CreateWebhookRequestContent,
    ) -> Result<Webhook, Error> {
        let mut operation = self
            .scope
            .operation(&routes::CREATE_WEBHOOK, &[&board_id])?;
        operation.resource_id(board_id);
        operation.json(body)?;
        self.scope.client().send(operation).await
    }

    /// `DeleteWebhook` — `DELETE /{accountId}/boards/{boardId}/webhooks/{webhookId}`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
    pub async fn delete(&self, board_id: &str, webhook_id: &str) -> Result<(), Error> {
        let mut operation = self
            .scope
            .operation(&routes::DELETE_WEBHOOK, &[&board_id, &webhook_id])?;
        operation.resource_id(webhook_id);
        self.scope.client().send_unit(operation).await
    }

    /// `GetWebhook` — `GET /{accountId}/boards/{boardId}/webhooks/{webhookId}`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
    pub async fn get(&self, board_id: &str, webhook_id: &str) -> Result<Webhook, Error> {
        let mut operation = self
            .scope
            .operation(&routes::GET_WEBHOOK, &[&board_id, &webhook_id])?;
        operation.resource_id(webhook_id);
        self.scope.client().send(operation).await
    }

    /// `ListWebhooks` — `GET /{accountId}/boards/{boardId}/webhooks.json`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
    pub async fn list(&self, board_id: &str) -> Result<Vec<Webhook>, Error> {
        let mut operation = self.scope.operation(&routes::LIST_WEBHOOKS, &[&board_id])?;
        operation.resource_id(board_id);
        self.scope.client().send(operation).await
    }

    /// `ListWebhookDeliveries` — `GET /{accountId}/boards/{boardId}/webhooks/{webhookId}/deliveries.json`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
    ///
    /// Paginated: the answer is a page with `page` as its cursor, and the next one is read with `next_page`.
    pub async fn list_webhook_deliveries(
        &self,
        board_id: &str,
        webhook_id: &str,
    ) -> Result<Page<Vec<WebhookDelivery>>, Error> {
        let mut operation = self
            .scope
            .operation(&routes::LIST_WEBHOOK_DELIVERIES, &[&board_id, &webhook_id])?;
        operation.resource_id(board_id);
        self.scope.client().send_page(operation).await
    }

    /// `UpdateWebhook` — `PATCH /{accountId}/boards/{boardId}/webhooks/{webhookId}`.
    ///
    /// Sent up to 3 times, backing off from 1000 ms, when the answer is 429, 500 or 503.
    pub async fn update(
        &self,
        board_id: &str,
        webhook_id: &str,
        body: &UpdateWebhookRequestContent,
    ) -> Result<Webhook, Error> {
        let mut operation = self
            .scope
            .operation(&routes::UPDATE_WEBHOOK, &[&board_id, &webhook_id])?;
        operation.resource_id(webhook_id);
        operation.json(body)?;
        self.scope.client().send(operation).await
    }
}