pub mod delegated;
pub mod types;
#[allow(unused_imports)]
use types::*;
#[derive(Clone)]
pub struct WebhooksClient {
client: crate::client::Client,
}
impl WebhooksClient {
pub fn new(client: crate::client::Client) -> Self {
WebhooksClient { client }
}
pub async fn list_webhooks(
&self,
query: Option<ListWebhooksQuery>,
) -> Result<ListWebhooksResponse, crate::error::Error> {
let mut path = String::from("/webhooks");
if let Some(query) = &query {
let mut q: Vec<String> = Vec::new();
if let Some(v) = &query.limit {
q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
}
if let Some(v) = &query.pagination_token {
q.push(format!(
"paginationToken={}",
urlencoding::encode(&v.to_string())
));
}
if !q.is_empty() {
path.push('?');
path.push_str(&q.join("&"));
}
}
self.client
.request::<ListWebhooksResponse>(reqwest::Method::GET, &path, None, false)
.await
}
pub async fn create_webhook(
&self,
body: CreateWebhookRequest,
) -> Result<CreateWebhookResponse, crate::error::Error> {
let path = String::from("/webhooks");
let body = serde_json::to_value(&body)?;
self.client
.request::<CreateWebhookResponse>(reqwest::Method::POST, &path, Some(&body), true)
.await
}
pub async fn get_webhook(
&self,
webhook_id: String,
) -> Result<GetWebhookResponse, crate::error::Error> {
let path = format!("/webhooks/{}", urlencoding::encode(&webhook_id));
self.client
.request::<GetWebhookResponse>(reqwest::Method::GET, &path, None, false)
.await
}
pub async fn update_webhook(
&self,
webhook_id: String,
body: UpdateWebhookRequest,
) -> Result<UpdateWebhookResponse, crate::error::Error> {
let path = format!("/webhooks/{}", urlencoding::encode(&webhook_id));
let body = serde_json::to_value(&body)?;
self.client
.request::<UpdateWebhookResponse>(reqwest::Method::PUT, &path, Some(&body), true)
.await
}
pub async fn delete_webhook(
&self,
webhook_id: String,
) -> Result<DeleteWebhookResponse, crate::error::Error> {
let path = format!("/webhooks/{}", urlencoding::encode(&webhook_id));
self.client
.request::<DeleteWebhookResponse>(reqwest::Method::DELETE, &path, None, true)
.await
}
pub async fn ping_webhook(
&self,
webhook_id: String,
) -> Result<PingWebhookResponse, crate::error::Error> {
let path = format!("/webhooks/{}/ping", urlencoding::encode(&webhook_id));
self.client
.request::<PingWebhookResponse>(reqwest::Method::POST, &path, None, true)
.await
}
pub async fn get_webhook_event(
&self,
webhook_id: String,
webhook_event_id: String,
) -> Result<GetWebhookEventResponse, crate::error::Error> {
let path = format!(
"/webhooks/{}/events/{}",
urlencoding::encode(&webhook_id),
urlencoding::encode(&webhook_event_id)
);
self.client
.request::<GetWebhookEventResponse>(reqwest::Method::GET, &path, None, false)
.await
}
pub async fn list_webhook_events(
&self,
webhook_id: String,
query: Option<ListWebhookEventsQuery>,
) -> Result<ListWebhookEventsResponse, crate::error::Error> {
let mut path = format!("/webhooks/{}/events", urlencoding::encode(&webhook_id));
if let Some(query) = &query {
let mut q: Vec<String> = Vec::new();
if let Some(v) = &query.kind {
q.push(format!("kind={}", urlencoding::encode(&v.to_string())));
}
if let Some(v) = &query.delivery_failed {
q.push(format!(
"deliveryFailed={}",
urlencoding::encode(&v.to_string())
));
}
if let Some(v) = &query.limit {
q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
}
if let Some(v) = &query.pagination_token {
q.push(format!(
"paginationToken={}",
urlencoding::encode(&v.to_string())
));
}
if !q.is_empty() {
path.push('?');
path.push_str(&q.join("&"));
}
}
self.client
.request::<ListWebhookEventsResponse>(reqwest::Method::GET, &path, None, false)
.await
}
}