#![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;
#[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 }
}
pub fn client(&self) -> &'a AccountClient {
self.client
}
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
}
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
}
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
}
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
}
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
}
}