use serde_json::Value;
use crate::client::{encode_path_segment, Client};
use crate::error::Error;
use crate::types::{CreateWebhookParams, UpdateWebhookParams};
#[derive(Debug, Clone, Copy)]
pub struct Webhooks<'a> {
pub(crate) client: &'a Client,
}
impl Webhooks<'_> {
pub async fn list(&self) -> Result<Value, Error> {
self.client.get("/webhooks", Vec::new()).await
}
pub async fn get(&self, id: &str) -> Result<Value, Error> {
self.client
.get(&format!("/webhooks/{}", encode_path_segment(id)), Vec::new())
.await
}
pub async fn create(&self, params: CreateWebhookParams) -> Result<Value, Error> {
self.client.post_json("/webhooks", ¶ms).await
}
pub async fn update(&self, id: &str, params: UpdateWebhookParams) -> Result<Value, Error> {
self.client
.patch_json(&format!("/webhooks/{}", encode_path_segment(id)), ¶ms)
.await
}
pub async fn delete(&self, id: &str) -> Result<Value, Error> {
self.client
.delete(&format!("/webhooks/{}", encode_path_segment(id)))
.await
}
pub async fn rotate_secret(&self, id: &str) -> Result<Value, Error> {
self.client
.post_empty(&format!("/webhooks/{}/rotate-secret", encode_path_segment(id)))
.await
}
}