#[allow(unused_imports)]
use super::types::*;
#[derive(Clone)]
pub struct DelegatedWebhooksClient {
client: crate::client::Client,
}
impl DelegatedWebhooksClient {
pub fn new(client: crate::client::Client) -> Self {
DelegatedWebhooksClient { 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_init(
&self,
body: CreateWebhookRequest,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = String::from("/webhooks");
let body = serde_json::to_value(&body)?;
self.client
.create_user_action_challenge(reqwest::Method::POST, &path, Some(&body))
.await
}
pub async fn create_webhook_complete(
&self,
body: CreateWebhookRequest,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<CreateWebhookResponse, crate::error::Error> {
let path = String::from("/webhooks");
let body = serde_json::to_value(&body)?;
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<CreateWebhookResponse>(
reqwest::Method::POST,
&path,
Some(&body),
&user_action,
)
.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_init(
&self,
webhook_id: String,
body: UpdateWebhookRequest,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = format!("/webhooks/{}", urlencoding::encode(&webhook_id));
let body = serde_json::to_value(&body)?;
self.client
.create_user_action_challenge(reqwest::Method::PUT, &path, Some(&body))
.await
}
pub async fn update_webhook_complete(
&self,
webhook_id: String,
body: UpdateWebhookRequest,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<UpdateWebhookResponse, crate::error::Error> {
let path = format!("/webhooks/{}", urlencoding::encode(&webhook_id));
let body = serde_json::to_value(&body)?;
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<UpdateWebhookResponse>(
reqwest::Method::PUT,
&path,
Some(&body),
&user_action,
)
.await
}
pub async fn delete_webhook_init(
&self,
webhook_id: String,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = format!("/webhooks/{}", urlencoding::encode(&webhook_id));
self.client
.create_user_action_challenge(reqwest::Method::DELETE, &path, None)
.await
}
pub async fn delete_webhook_complete(
&self,
webhook_id: String,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<DeleteWebhookResponse, crate::error::Error> {
let path = format!("/webhooks/{}", urlencoding::encode(&webhook_id));
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<DeleteWebhookResponse>(
reqwest::Method::DELETE,
&path,
None,
&user_action,
)
.await
}
pub async fn ping_webhook_init(
&self,
webhook_id: String,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = format!("/webhooks/{}/ping", urlencoding::encode(&webhook_id));
self.client
.create_user_action_challenge(reqwest::Method::POST, &path, None)
.await
}
pub async fn ping_webhook_complete(
&self,
webhook_id: String,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<PingWebhookResponse, crate::error::Error> {
let path = format!("/webhooks/{}/ping", urlencoding::encode(&webhook_id));
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<PingWebhookResponse>(
reqwest::Method::POST,
&path,
None,
&user_action,
)
.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
}
}