use std::sync::Arc;
use serde::Serialize;
use serde_json::Value;
use crate::client::Inner;
use crate::error::Result;
use crate::params;
const BASE: &str = "/v1/webhooks/endpoints";
#[derive(Clone, Debug)]
pub struct Webhooks {
inner: Arc<Inner>,
}
impl Webhooks {
pub(crate) fn new(inner: Arc<Inner>) -> Self {
Self { inner }
}
pub async fn create(&self, params: impl Serialize) -> Result<Value> {
self.inner
.call("POST", BASE, crate::params::to_body(params)?)
.await
}
pub async fn list(&self, params: impl Serialize) -> Result<Value> {
self.inner
.call("GET", &format!("{BASE}{}", params::query(params)?), None)
.await
}
pub async fn get(&self, id: &str, params: impl Serialize) -> Result<Value> {
self.inner
.call(
"GET",
&format!(
"{BASE}/{}{}",
crate::params::encode(id),
crate::params::query(params)?
),
None,
)
.await
}
pub async fn update(&self, id: &str, params: impl Serialize) -> Result<Value> {
let payload = crate::params::to_value(params)?;
self.inner
.call(
"PATCH",
&format!(
"{BASE}/{}{}",
crate::params::encode(id),
crate::params::query_pick(&payload, &["publication_id"])
),
crate::params::body_from_value(&payload)?,
)
.await
}
pub async fn delete(&self, id: &str, params: impl Serialize) -> Result<Value> {
self.inner
.call(
"DELETE",
&format!(
"{BASE}/{}{}",
crate::params::encode(id),
crate::params::query(params)?
),
None,
)
.await
}
}