use std::sync::Arc;
use serde::Serialize;
use serde_json::Value;
use crate::client::Inner;
use crate::error::Result;
use crate::params;
#[derive(Clone, Debug)]
pub struct Events {
inner: Arc<Inner>,
}
impl Events {
pub(crate) fn new(inner: Arc<Inner>) -> Self {
Self { inner }
}
pub async fn send(&self, params: impl Serialize) -> Result<Value> {
self.inner
.call("POST", "/v1/events", crate::params::to_body(params)?)
.await
}
pub async fn list(&self, params: impl Serialize) -> Result<Value> {
self.inner
.call(
"GET",
&format!("/v1/events{}", params::query(params)?),
None,
)
.await
}
}
#[derive(Clone, Debug)]
pub struct EventDefinitions {
inner: Arc<Inner>,
}
impl EventDefinitions {
pub(crate) fn new(inner: Arc<Inner>) -> Self {
Self { inner }
}
pub async fn create(&self, params: impl Serialize) -> Result<Value> {
self.inner
.call(
"POST",
"/v1/event-definitions",
crate::params::to_body(params)?,
)
.await
}
pub async fn list(&self, params: impl Serialize) -> Result<Value> {
self.inner
.call(
"GET",
&format!("/v1/event-definitions{}", params::query(params)?),
None,
)
.await
}
pub async fn get(&self, id: &str, params: impl Serialize) -> Result<Value> {
self.inner
.call(
"GET",
&format!(
"/v1/event-definitions/{}{}",
crate::params::encode(id),
crate::params::query(params)?
),
None,
)
.await
}
pub async fn update(&self, id: &str, params: impl Serialize) -> Result<Value> {
let mut payload = crate::params::to_value(params)?;
let publication_id = crate::params::take(&mut payload, "publication_id");
self.inner
.call(
"PATCH",
&format!(
"/v1/event-definitions/{}{}",
crate::params::encode(id),
crate::params::query_of_value(
&serde_json::json!({ "publication_id": 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!(
"/v1/event-definitions/{}{}",
crate::params::encode(id),
crate::params::query(params)?
),
None,
)
.await
}
}