svix_webhook_with_clone/api/
application.rs

1use super::PostOptions;
2use crate::{apis::application_api, error::Result, models::*, Configuration};
3
4#[derive(Default)]
5pub struct ApplicationListOptions {
6    /// Limit the number of returned items
7    pub limit: Option<i32>,
8
9    /// The iterator returned from a prior invocation
10    pub iterator: Option<String>,
11
12    /// The sorting order of the returned items
13    pub order: Option<Ordering>,
14}
15
16pub struct Application<'a> {
17    cfg: &'a Configuration,
18}
19
20impl<'a> Application<'a> {
21    pub(super) fn new(cfg: &'a Configuration) -> Self {
22        Self { cfg }
23    }
24
25    /// List of all the organization's applications.
26    pub async fn list(
27        &self,
28        options: Option<ApplicationListOptions>,
29    ) -> Result<ListResponseApplicationOut> {
30        let ApplicationListOptions {
31            limit,
32            iterator,
33            order,
34        } = options.unwrap_or_default();
35
36        application_api::v1_period_application_period_list(
37            self.cfg,
38            application_api::V1PeriodApplicationPeriodListParams {
39                limit,
40                iterator,
41                order,
42            },
43        )
44        .await
45    }
46
47    /// Create a new application.
48    pub async fn create(
49        &self,
50        application_in: ApplicationIn,
51        options: Option<PostOptions>,
52    ) -> Result<ApplicationOut> {
53        let PostOptions { idempotency_key } = options.unwrap_or_default();
54        application_api::v1_period_application_period_create(
55            self.cfg,
56            application_api::V1PeriodApplicationPeriodCreateParams {
57                application_in,
58                idempotency_key,
59                get_if_exists: None,
60            },
61        )
62        .await
63    }
64
65    /// Create the application with the given ID, or create a new one if it
66    /// doesn't exist yet.
67    pub async fn get_or_create(
68        &self,
69        application_in: ApplicationIn,
70        options: Option<PostOptions>,
71    ) -> Result<ApplicationOut> {
72        let PostOptions { idempotency_key } = options.unwrap_or_default();
73        application_api::v1_period_application_period_create(
74            self.cfg,
75            application_api::V1PeriodApplicationPeriodCreateParams {
76                application_in,
77                idempotency_key,
78                get_if_exists: Some(true),
79            },
80        )
81        .await
82    }
83
84    /// Get an application.
85    pub async fn get(&self, app_id: String) -> Result<ApplicationOut> {
86        application_api::v1_period_application_period_get(
87            self.cfg,
88            application_api::V1PeriodApplicationPeriodGetParams { app_id },
89        )
90        .await
91    }
92
93    /// Update an application.
94    pub async fn update(
95        &self,
96        app_id: String,
97        application_in: ApplicationIn,
98    ) -> Result<ApplicationOut> {
99        application_api::v1_period_application_period_update(
100            self.cfg,
101            application_api::V1PeriodApplicationPeriodUpdateParams {
102                app_id,
103                application_in,
104            },
105        )
106        .await
107    }
108
109    /// Delete an application.
110    pub async fn delete(&self, app_id: String) -> Result<()> {
111        application_api::v1_period_application_period_delete(
112            self.cfg,
113            application_api::V1PeriodApplicationPeriodDeleteParams { app_id },
114        )
115        .await
116    }
117
118    /// Partially update an application.
119    pub async fn patch(
120        &self,
121        app_id: String,
122        application_patch: ApplicationPatch,
123    ) -> Result<ApplicationOut> {
124        application_api::v1_period_application_period_patch(
125            self.cfg,
126            application_api::V1PeriodApplicationPeriodPatchParams {
127                app_id,
128                application_patch,
129            },
130        )
131        .await
132    }
133}