1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteWebhookByIdError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetWebhookError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetWebhookByIdError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetWebhookByIdDeliveriesError {
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum PostWebhookError {
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum PostWebhookByIdSecretError {
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum PostWebhookByIdTestError {
64 UnknownValue(serde_json::Value),
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum PutWebhookByIdError {
71 UnknownValue(serde_json::Value),
72}
73
74
75pub async fn delete_webhook_by_id(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteWebhookByIdError>> {
77 let p_id = id;
79
80 let uri_str = format!("{}/v1/webhook/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
81 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
82
83 if let Some(ref user_agent) = configuration.user_agent {
84 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
85 }
86 if let Some(ref token) = configuration.bearer_access_token {
87 req_builder = req_builder.bearer_auth(token.to_owned());
88 };
89
90 let req = req_builder.build()?;
91 let resp = configuration.client.execute(req).await?;
92
93 let status = resp.status();
94
95 if !status.is_client_error() && !status.is_server_error() {
96 Ok(())
97 } else {
98 let content = resp.text().await?;
99 let entity: Option<DeleteWebhookByIdError> = serde_json::from_str(&content).ok();
100 Err(Error::ResponseError(ResponseContent { status, content, entity }))
101 }
102}
103
104pub async fn get_webhook(configuration: &configuration::Configuration, ) -> Result<models::EndpointList, Error<GetWebhookError>> {
106
107 let uri_str = format!("{}/v1/webhook", configuration.base_path);
108 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
109
110 if let Some(ref user_agent) = configuration.user_agent {
111 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
112 }
113 if let Some(ref token) = configuration.bearer_access_token {
114 req_builder = req_builder.bearer_auth(token.to_owned());
115 };
116
117 let req = req_builder.build()?;
118 let resp = configuration.client.execute(req).await?;
119
120 let status = resp.status();
121 let content_type = resp
122 .headers()
123 .get("content-type")
124 .and_then(|v| v.to_str().ok())
125 .unwrap_or("application/octet-stream");
126 let content_type = super::ContentType::from(content_type);
127
128 if !status.is_client_error() && !status.is_server_error() {
129 let content = resp.text().await?;
130 match content_type {
131 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
132 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::EndpointList`"))),
133 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::EndpointList`")))),
134 }
135 } else {
136 let content = resp.text().await?;
137 let entity: Option<GetWebhookError> = serde_json::from_str(&content).ok();
138 Err(Error::ResponseError(ResponseContent { status, content, entity }))
139 }
140}
141
142pub async fn get_webhook_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::Endpoint, Error<GetWebhookByIdError>> {
144 let p_id = id;
146
147 let uri_str = format!("{}/v1/webhook/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
148 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
149
150 if let Some(ref user_agent) = configuration.user_agent {
151 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
152 }
153 if let Some(ref token) = configuration.bearer_access_token {
154 req_builder = req_builder.bearer_auth(token.to_owned());
155 };
156
157 let req = req_builder.build()?;
158 let resp = configuration.client.execute(req).await?;
159
160 let status = resp.status();
161 let content_type = resp
162 .headers()
163 .get("content-type")
164 .and_then(|v| v.to_str().ok())
165 .unwrap_or("application/octet-stream");
166 let content_type = super::ContentType::from(content_type);
167
168 if !status.is_client_error() && !status.is_server_error() {
169 let content = resp.text().await?;
170 match content_type {
171 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
172 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Endpoint`"))),
173 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Endpoint`")))),
174 }
175 } else {
176 let content = resp.text().await?;
177 let entity: Option<GetWebhookByIdError> = serde_json::from_str(&content).ok();
178 Err(Error::ResponseError(ResponseContent { status, content, entity }))
179 }
180}
181
182pub async fn get_webhook_by_id_deliveries(configuration: &configuration::Configuration, id: &str, limit: Option<i32>, status: Option<&str>) -> Result<models::DeliveryList, Error<GetWebhookByIdDeliveriesError>> {
184 let p_id = id;
186 let p_limit = limit;
187 let p_status = status;
188
189 let uri_str = format!("{}/v1/webhook/{id}/deliveries", configuration.base_path, id=crate::apis::urlencode(p_id));
190 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
191
192 if let Some(ref param_value) = p_limit {
193 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
194 }
195 if let Some(ref param_value) = p_status {
196 req_builder = req_builder.query(&[("status", ¶m_value.to_string())]);
197 }
198 if let Some(ref user_agent) = configuration.user_agent {
199 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
200 }
201 if let Some(ref token) = configuration.bearer_access_token {
202 req_builder = req_builder.bearer_auth(token.to_owned());
203 };
204
205 let req = req_builder.build()?;
206 let resp = configuration.client.execute(req).await?;
207
208 let status = resp.status();
209 let content_type = resp
210 .headers()
211 .get("content-type")
212 .and_then(|v| v.to_str().ok())
213 .unwrap_or("application/octet-stream");
214 let content_type = super::ContentType::from(content_type);
215
216 if !status.is_client_error() && !status.is_server_error() {
217 let content = resp.text().await?;
218 match content_type {
219 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
220 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeliveryList`"))),
221 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::DeliveryList`")))),
222 }
223 } else {
224 let content = resp.text().await?;
225 let entity: Option<GetWebhookByIdDeliveriesError> = serde_json::from_str(&content).ok();
226 Err(Error::ResponseError(ResponseContent { status, content, entity }))
227 }
228}
229
230pub async fn post_webhook(configuration: &configuration::Configuration, create_endpoint_in: models::CreateEndpointIn) -> Result<models::Endpoint, Error<PostWebhookError>> {
232 let p_create_endpoint_in = create_endpoint_in;
234
235 let uri_str = format!("{}/v1/webhook", configuration.base_path);
236 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
237
238 if let Some(ref user_agent) = configuration.user_agent {
239 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
240 }
241 if let Some(ref token) = configuration.bearer_access_token {
242 req_builder = req_builder.bearer_auth(token.to_owned());
243 };
244 req_builder = req_builder.json(&p_create_endpoint_in);
245
246 let req = req_builder.build()?;
247 let resp = configuration.client.execute(req).await?;
248
249 let status = resp.status();
250 let content_type = resp
251 .headers()
252 .get("content-type")
253 .and_then(|v| v.to_str().ok())
254 .unwrap_or("application/octet-stream");
255 let content_type = super::ContentType::from(content_type);
256
257 if !status.is_client_error() && !status.is_server_error() {
258 let content = resp.text().await?;
259 match content_type {
260 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
261 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Endpoint`"))),
262 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Endpoint`")))),
263 }
264 } else {
265 let content = resp.text().await?;
266 let entity: Option<PostWebhookError> = serde_json::from_str(&content).ok();
267 Err(Error::ResponseError(ResponseContent { status, content, entity }))
268 }
269}
270
271pub async fn post_webhook_by_id_secret(configuration: &configuration::Configuration, id: &str) -> Result<models::Endpoint, Error<PostWebhookByIdSecretError>> {
273 let p_id = id;
275
276 let uri_str = format!("{}/v1/webhook/{id}/secret", configuration.base_path, id=crate::apis::urlencode(p_id));
277 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
278
279 if let Some(ref user_agent) = configuration.user_agent {
280 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
281 }
282 if let Some(ref token) = configuration.bearer_access_token {
283 req_builder = req_builder.bearer_auth(token.to_owned());
284 };
285
286 let req = req_builder.build()?;
287 let resp = configuration.client.execute(req).await?;
288
289 let status = resp.status();
290 let content_type = resp
291 .headers()
292 .get("content-type")
293 .and_then(|v| v.to_str().ok())
294 .unwrap_or("application/octet-stream");
295 let content_type = super::ContentType::from(content_type);
296
297 if !status.is_client_error() && !status.is_server_error() {
298 let content = resp.text().await?;
299 match content_type {
300 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
301 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Endpoint`"))),
302 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Endpoint`")))),
303 }
304 } else {
305 let content = resp.text().await?;
306 let entity: Option<PostWebhookByIdSecretError> = serde_json::from_str(&content).ok();
307 Err(Error::ResponseError(ResponseContent { status, content, entity }))
308 }
309}
310
311pub async fn post_webhook_by_id_test(configuration: &configuration::Configuration, id: &str) -> Result<models::TestResult, Error<PostWebhookByIdTestError>> {
313 let p_id = id;
315
316 let uri_str = format!("{}/v1/webhook/{id}/test", configuration.base_path, id=crate::apis::urlencode(p_id));
317 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
318
319 if let Some(ref user_agent) = configuration.user_agent {
320 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
321 }
322 if let Some(ref token) = configuration.bearer_access_token {
323 req_builder = req_builder.bearer_auth(token.to_owned());
324 };
325
326 let req = req_builder.build()?;
327 let resp = configuration.client.execute(req).await?;
328
329 let status = resp.status();
330 let content_type = resp
331 .headers()
332 .get("content-type")
333 .and_then(|v| v.to_str().ok())
334 .unwrap_or("application/octet-stream");
335 let content_type = super::ContentType::from(content_type);
336
337 if !status.is_client_error() && !status.is_server_error() {
338 let content = resp.text().await?;
339 match content_type {
340 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
341 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TestResult`"))),
342 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TestResult`")))),
343 }
344 } else {
345 let content = resp.text().await?;
346 let entity: Option<PostWebhookByIdTestError> = serde_json::from_str(&content).ok();
347 Err(Error::ResponseError(ResponseContent { status, content, entity }))
348 }
349}
350
351pub async fn put_webhook_by_id(configuration: &configuration::Configuration, id: &str, update_endpoint_in: models::UpdateEndpointIn) -> Result<models::Endpoint, Error<PutWebhookByIdError>> {
353 let p_id = id;
355 let p_update_endpoint_in = update_endpoint_in;
356
357 let uri_str = format!("{}/v1/webhook/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
358 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
359
360 if let Some(ref user_agent) = configuration.user_agent {
361 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
362 }
363 if let Some(ref token) = configuration.bearer_access_token {
364 req_builder = req_builder.bearer_auth(token.to_owned());
365 };
366 req_builder = req_builder.json(&p_update_endpoint_in);
367
368 let req = req_builder.build()?;
369 let resp = configuration.client.execute(req).await?;
370
371 let status = resp.status();
372 let content_type = resp
373 .headers()
374 .get("content-type")
375 .and_then(|v| v.to_str().ok())
376 .unwrap_or("application/octet-stream");
377 let content_type = super::ContentType::from(content_type);
378
379 if !status.is_client_error() && !status.is_server_error() {
380 let content = resp.text().await?;
381 match content_type {
382 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
383 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Endpoint`"))),
384 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Endpoint`")))),
385 }
386 } else {
387 let content = resp.text().await?;
388 let entity: Option<PutWebhookByIdError> = serde_json::from_str(&content).ok();
389 Err(Error::ResponseError(ResponseContent { status, content, entity }))
390 }
391}
392