casdoor_sdk/apis/
webhook_api.rs1
2
3use reqwest;
4
5use crate::{apis::ResponseContent, models};
6use super::{Error, configuration};
7
8#[derive(Clone, Debug)]
10pub struct ApiControllerAddWebhookParams {
11 pub body: models::Webhook
13}
14
15#[derive(Clone, Debug)]
17pub struct ApiControllerDeleteWebhookParams {
18 pub body: models::Webhook
20}
21
22#[derive(Clone, Debug)]
24pub struct ApiControllerGetWebhookParams {
25 pub id: String
27}
28
29#[derive(Clone, Debug)]
31pub struct ApiControllerGetWebhooksParams {
32 pub owner: String
34}
35
36#[derive(Clone, Debug)]
38pub struct ApiControllerUpdateWebhookParams {
39 pub id: String,
41 pub body: models::Webhook
43}
44
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum ApiControllerAddWebhookError {
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum ApiControllerDeleteWebhookError {
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum ApiControllerGetWebhookError {
64 UnknownValue(serde_json::Value),
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum ApiControllerGetWebhooksError {
71 UnknownValue(serde_json::Value),
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum ApiControllerUpdateWebhookError {
78 UnknownValue(serde_json::Value),
79}
80
81
82pub async fn add_webhook(configuration: &configuration::Configuration, params: ApiControllerAddWebhookParams) -> Result<models::ControllersResponse, Error<ApiControllerAddWebhookError>> {
84 let local_var_configuration = configuration;
85
86 let body = params.body;
88
89
90 let local_var_client = &local_var_configuration.client;
91
92 let local_var_uri_str = format!("{}/api/add-webhook", local_var_configuration.base_path);
93 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
94
95 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
96 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
97 }
98 local_var_req_builder = local_var_req_builder.json(&body);
99
100 let local_var_req = local_var_req_builder.build()?;
101 let local_var_resp = local_var_client.execute(local_var_req).await?;
102
103 let local_var_status = local_var_resp.status();
104 let local_var_content = local_var_resp.text().await?;
105
106 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
107 serde_json::from_str(&local_var_content).map_err(Error::from)
108 } else {
109 let local_var_entity: Option<ApiControllerAddWebhookError> = serde_json::from_str(&local_var_content).ok();
110 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
111 Err(Error::ResponseError(local_var_error))
112 }
113}
114
115pub async fn delete_webhook(configuration: &configuration::Configuration, params: ApiControllerDeleteWebhookParams) -> Result<models::ControllersResponse, Error<ApiControllerDeleteWebhookError>> {
117 let local_var_configuration = configuration;
118
119 let body = params.body;
121
122
123 let local_var_client = &local_var_configuration.client;
124
125 let local_var_uri_str = format!("{}/api/delete-webhook", local_var_configuration.base_path);
126 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
127
128 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
129 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
130 }
131 local_var_req_builder = local_var_req_builder.json(&body);
132
133 let local_var_req = local_var_req_builder.build()?;
134 let local_var_resp = local_var_client.execute(local_var_req).await?;
135
136 let local_var_status = local_var_resp.status();
137 let local_var_content = local_var_resp.text().await?;
138
139 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
140 serde_json::from_str(&local_var_content).map_err(Error::from)
141 } else {
142 let local_var_entity: Option<ApiControllerDeleteWebhookError> = serde_json::from_str(&local_var_content).ok();
143 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
144 Err(Error::ResponseError(local_var_error))
145 }
146}
147
148pub async fn get_webhook(configuration: &configuration::Configuration, params: ApiControllerGetWebhookParams) -> Result<models::Webhook, Error<ApiControllerGetWebhookError>> {
150 let local_var_configuration = configuration;
151
152 let id = params.id;
154
155
156 let local_var_client = &local_var_configuration.client;
157
158 let local_var_uri_str = format!("{}/api/get-webhook", local_var_configuration.base_path);
159 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
160
161 local_var_req_builder = local_var_req_builder.query(&[("id", &id.to_string())]);
162 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
163 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
164 }
165
166 let local_var_req = local_var_req_builder.build()?;
167 let local_var_resp = local_var_client.execute(local_var_req).await?;
168
169 let local_var_status = local_var_resp.status();
170 let local_var_content = local_var_resp.text().await?;
171
172 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
173 serde_json::from_str(&local_var_content).map_err(Error::from)
174 } else {
175 let local_var_entity: Option<ApiControllerGetWebhookError> = serde_json::from_str(&local_var_content).ok();
176 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
177 Err(Error::ResponseError(local_var_error))
178 }
179}
180
181pub async fn get_webhooks(configuration: &configuration::Configuration, params: ApiControllerGetWebhooksParams) -> Result<Vec<models::Webhook>, Error<ApiControllerGetWebhooksError>> {
183 let local_var_configuration = configuration;
184
185 let owner = params.owner;
187
188
189 let local_var_client = &local_var_configuration.client;
190
191 let local_var_uri_str = format!("{}/api/get-webhooks", local_var_configuration.base_path);
192 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
193
194 local_var_req_builder = local_var_req_builder.query(&[("owner", &owner.to_string())]);
195 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
196 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
197 }
198
199 let local_var_req = local_var_req_builder.build()?;
200 let local_var_resp = local_var_client.execute(local_var_req).await?;
201
202 let local_var_status = local_var_resp.status();
203 let local_var_content = local_var_resp.text().await?;
204
205 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
206 serde_json::from_str(&local_var_content).map_err(Error::from)
207 } else {
208 let local_var_entity: Option<ApiControllerGetWebhooksError> = serde_json::from_str(&local_var_content).ok();
209 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
210 Err(Error::ResponseError(local_var_error))
211 }
212}
213
214pub async fn update_webhook(configuration: &configuration::Configuration, params: ApiControllerUpdateWebhookParams) -> Result<models::ControllersResponse, Error<ApiControllerUpdateWebhookError>> {
216 let local_var_configuration = configuration;
217
218 let id = params.id;
220 let body = params.body;
221
222
223 let local_var_client = &local_var_configuration.client;
224
225 let local_var_uri_str = format!("{}/api/update-webhook", local_var_configuration.base_path);
226 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
227
228 local_var_req_builder = local_var_req_builder.query(&[("id", &id.to_string())]);
229 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
230 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
231 }
232 local_var_req_builder = local_var_req_builder.json(&body);
233
234 let local_var_req = local_var_req_builder.build()?;
235 let local_var_resp = local_var_client.execute(local_var_req).await?;
236
237 let local_var_status = local_var_resp.status();
238 let local_var_content = local_var_resp.text().await?;
239
240 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
241 serde_json::from_str(&local_var_content).map_err(Error::from)
242 } else {
243 let local_var_entity: Option<ApiControllerUpdateWebhookError> = serde_json::from_str(&local_var_content).ok();
244 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
245 Err(Error::ResponseError(local_var_error))
246 }
247}
248