use crate::{error::Result, models::*, Configuration};
#[derive(Default)]
pub struct ApplicationListOptions {
pub exclude_apps_with_no_endpoints: Option<bool>,
pub exclude_apps_with_disabled_endpoints: Option<bool>,
pub exclude_apps_with_svix_play_endpoints: Option<bool>,
pub limit: Option<i32>,
pub iterator: Option<String>,
pub order: Option<Ordering>,
}
#[derive(Default)]
pub struct ApplicationCreateOptions {
pub idempotency_key: Option<String>,
}
pub struct Application<'a> {
cfg: &'a Configuration,
}
impl<'a> Application<'a> {
pub(super) fn new(cfg: &'a Configuration) -> Self {
Self { cfg }
}
pub async fn list(
&self,
options: Option<ApplicationListOptions>,
) -> Result<ListResponseApplicationOut> {
let ApplicationListOptions {
exclude_apps_with_no_endpoints,
exclude_apps_with_disabled_endpoints,
exclude_apps_with_svix_play_endpoints,
limit,
iterator,
order,
} = options.unwrap_or_default();
crate::request::Request::new(http1::Method::GET, "/api/v1/app")
.with_optional_query_param(
"exclude_apps_with_no_endpoints",
exclude_apps_with_no_endpoints,
)
.with_optional_query_param(
"exclude_apps_with_disabled_endpoints",
exclude_apps_with_disabled_endpoints,
)
.with_optional_query_param(
"exclude_apps_with_svix_play_endpoints",
exclude_apps_with_svix_play_endpoints,
)
.with_optional_query_param("limit", limit)
.with_optional_query_param("iterator", iterator)
.with_optional_query_param("order", order)
.execute(self.cfg)
.await
}
pub async fn create(
&self,
application_in: ApplicationIn,
options: Option<ApplicationCreateOptions>,
) -> Result<ApplicationOut> {
let ApplicationCreateOptions { idempotency_key } = options.unwrap_or_default();
crate::request::Request::new(http1::Method::POST, "/api/v1/app")
.with_optional_header_param("idempotency-key", idempotency_key)
.with_body_param(application_in)
.execute(self.cfg)
.await
}
pub async fn get_or_create(
&self,
application_in: ApplicationIn,
options: Option<ApplicationCreateOptions>,
) -> Result<ApplicationOut> {
let ApplicationCreateOptions { idempotency_key } = options.unwrap_or_default();
crate::request::Request::new(http1::Method::POST, "/api/v1/app")
.with_query_param("get_if_exists", true)
.with_optional_header_param("idempotency-key", idempotency_key)
.with_body_param(application_in)
.execute(self.cfg)
.await
}
pub async fn get(&self, app_id: String) -> Result<ApplicationOut> {
crate::request::Request::new(http1::Method::GET, "/api/v1/app/{app_id}")
.with_path_param("app_id", app_id)
.execute(self.cfg)
.await
}
pub async fn update(
&self,
app_id: String,
application_in: ApplicationIn,
) -> Result<ApplicationOut> {
crate::request::Request::new(http1::Method::PUT, "/api/v1/app/{app_id}")
.with_path_param("app_id", app_id)
.with_body_param(application_in)
.execute(self.cfg)
.await
}
pub async fn delete(&self, app_id: String) -> Result<()> {
crate::request::Request::new(http1::Method::DELETE, "/api/v1/app/{app_id}")
.with_path_param("app_id", app_id)
.returns_nothing()
.execute(self.cfg)
.await
}
pub async fn patch(
&self,
app_id: String,
application_patch: ApplicationPatch,
) -> Result<ApplicationOut> {
crate::request::Request::new(http1::Method::PATCH, "/api/v1/app/{app_id}")
.with_path_param("app_id", app_id)
.with_body_param(application_patch)
.execute(self.cfg)
.await
}
}