1use crate::{error::Result, models::*, Configuration};
3
4#[derive(Default)]
5pub struct IntegrationListOptions {
6 pub limit: Option<i32>,
8
9 pub iterator: Option<String>,
11
12 pub order: Option<Ordering>,
14}
15
16#[derive(Default)]
17pub struct IntegrationCreateOptions {
18 pub idempotency_key: Option<String>,
19}
20
21#[derive(Default)]
22pub struct IntegrationRotateKeyOptions {
23 pub idempotency_key: Option<String>,
24}
25
26pub struct Integration<'a> {
27 cfg: &'a Configuration,
28}
29
30impl<'a> Integration<'a> {
31 pub(super) fn new(cfg: &'a Configuration) -> Self {
32 Self { cfg }
33 }
34
35 pub async fn list(
37 &self,
38 app_id: String,
39 options: Option<IntegrationListOptions>,
40 ) -> Result<ListResponseIntegrationOut> {
41 let IntegrationListOptions {
42 limit,
43 iterator,
44 order,
45 } = options.unwrap_or_default();
46
47 crate::request::Request::new(http1::Method::GET, "/api/v1/app/{app_id}/integration")
48 .with_path_param("app_id", app_id)
49 .with_optional_query_param("limit", limit)
50 .with_optional_query_param("iterator", iterator)
51 .with_optional_query_param("order", order)
52 .execute(self.cfg)
53 .await
54 }
55
56 pub async fn create(
58 &self,
59 app_id: String,
60 integration_in: IntegrationIn,
61 options: Option<IntegrationCreateOptions>,
62 ) -> Result<IntegrationOut> {
63 let IntegrationCreateOptions { idempotency_key } = options.unwrap_or_default();
64
65 crate::request::Request::new(http1::Method::POST, "/api/v1/app/{app_id}/integration")
66 .with_path_param("app_id", app_id)
67 .with_optional_header_param("idempotency-key", idempotency_key)
68 .with_body_param(integration_in)
69 .execute(self.cfg)
70 .await
71 }
72
73 pub async fn get(&self, app_id: String, integ_id: String) -> Result<IntegrationOut> {
75 crate::request::Request::new(
76 http1::Method::GET,
77 "/api/v1/app/{app_id}/integration/{integ_id}",
78 )
79 .with_path_param("app_id", app_id)
80 .with_path_param("integ_id", integ_id)
81 .execute(self.cfg)
82 .await
83 }
84
85 pub async fn update(
87 &self,
88 app_id: String,
89 integ_id: String,
90 integration_update: IntegrationUpdate,
91 ) -> Result<IntegrationOut> {
92 crate::request::Request::new(
93 http1::Method::PUT,
94 "/api/v1/app/{app_id}/integration/{integ_id}",
95 )
96 .with_path_param("app_id", app_id)
97 .with_path_param("integ_id", integ_id)
98 .with_body_param(integration_update)
99 .execute(self.cfg)
100 .await
101 }
102
103 pub async fn delete(&self, app_id: String, integ_id: String) -> Result<()> {
105 crate::request::Request::new(
106 http1::Method::DELETE,
107 "/api/v1/app/{app_id}/integration/{integ_id}",
108 )
109 .with_path_param("app_id", app_id)
110 .with_path_param("integ_id", integ_id)
111 .returns_nothing()
112 .execute(self.cfg)
113 .await
114 }
115
116 #[deprecated]
118 pub async fn get_key(&self, app_id: String, integ_id: String) -> Result<IntegrationKeyOut> {
119 crate::request::Request::new(
120 http1::Method::GET,
121 "/api/v1/app/{app_id}/integration/{integ_id}/key",
122 )
123 .with_path_param("app_id", app_id)
124 .with_path_param("integ_id", integ_id)
125 .execute(self.cfg)
126 .await
127 }
128
129 pub async fn rotate_key(
132 &self,
133 app_id: String,
134 integ_id: String,
135 options: Option<IntegrationRotateKeyOptions>,
136 ) -> Result<IntegrationKeyOut> {
137 let IntegrationRotateKeyOptions { idempotency_key } = options.unwrap_or_default();
138
139 crate::request::Request::new(
140 http1::Method::POST,
141 "/api/v1/app/{app_id}/integration/{integ_id}/key/rotate",
142 )
143 .with_path_param("app_id", app_id)
144 .with_path_param("integ_id", integ_id)
145 .with_optional_header_param("idempotency-key", idempotency_key)
146 .execute(self.cfg)
147 .await
148 }
149}