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 CreateWebhookSubscriptionError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum DeleteWebhookSubscriptionError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum ListWebhookEventTypesError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum ListWebhookSubscriptionsError {
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum RetrieveWebhookSubscriptionError {
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum TestWebhookSubscriptionError {
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum UpdateWebhookSubscriptionError {
64 UnknownValue(serde_json::Value),
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum UpdateWebhookSubscriptionSignatureKeyError {
71 UnknownValue(serde_json::Value),
72}
73
74
75pub async fn create_webhook_subscription(configuration: &configuration::Configuration, create_webhook_subscription_request: models::CreateWebhookSubscriptionRequest) -> Result<models::CreateWebhookSubscriptionResponse, Error<CreateWebhookSubscriptionError>> {
77 let p_create_webhook_subscription_request = create_webhook_subscription_request;
79
80 let uri_str = format!("{}/v2/webhooks/subscriptions", configuration.base_path);
81 let mut req_builder = configuration.client.request(reqwest::Method::POST, &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.oauth_access_token {
87 req_builder = req_builder.bearer_auth(token.to_owned());
88 };
89 req_builder = req_builder.json(&p_create_webhook_subscription_request);
90
91 let req = req_builder.build()?;
92 let resp = configuration.client.execute(req).await?;
93
94 let status = resp.status();
95 let content_type = resp
96 .headers()
97 .get("content-type")
98 .and_then(|v| v.to_str().ok())
99 .unwrap_or("application/octet-stream");
100 let content_type = super::ContentType::from(content_type);
101
102 if !status.is_client_error() && !status.is_server_error() {
103 let content = resp.text().await?;
104 match content_type {
105 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
106 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateWebhookSubscriptionResponse`"))),
107 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::CreateWebhookSubscriptionResponse`")))),
108 }
109 } else {
110 let content = resp.text().await?;
111 let entity: Option<CreateWebhookSubscriptionError> = serde_json::from_str(&content).ok();
112 Err(Error::ResponseError(ResponseContent { status, content, entity }))
113 }
114}
115
116pub async fn delete_webhook_subscription(configuration: &configuration::Configuration, subscription_id: &str) -> Result<models::DeleteWebhookSubscriptionResponse, Error<DeleteWebhookSubscriptionError>> {
118 let p_subscription_id = subscription_id;
120
121 let uri_str = format!("{}/v2/webhooks/subscriptions/{subscription_id}", configuration.base_path, subscription_id=crate::apis::urlencode(p_subscription_id));
122 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
123
124 if let Some(ref user_agent) = configuration.user_agent {
125 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
126 }
127 if let Some(ref token) = configuration.oauth_access_token {
128 req_builder = req_builder.bearer_auth(token.to_owned());
129 };
130
131 let req = req_builder.build()?;
132 let resp = configuration.client.execute(req).await?;
133
134 let status = resp.status();
135 let content_type = resp
136 .headers()
137 .get("content-type")
138 .and_then(|v| v.to_str().ok())
139 .unwrap_or("application/octet-stream");
140 let content_type = super::ContentType::from(content_type);
141
142 if !status.is_client_error() && !status.is_server_error() {
143 let content = resp.text().await?;
144 match content_type {
145 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
146 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteWebhookSubscriptionResponse`"))),
147 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::DeleteWebhookSubscriptionResponse`")))),
148 }
149 } else {
150 let content = resp.text().await?;
151 let entity: Option<DeleteWebhookSubscriptionError> = serde_json::from_str(&content).ok();
152 Err(Error::ResponseError(ResponseContent { status, content, entity }))
153 }
154}
155
156pub async fn list_webhook_event_types(configuration: &configuration::Configuration, api_version: Option<&str>) -> Result<models::ListWebhookEventTypesResponse, Error<ListWebhookEventTypesError>> {
158 let p_api_version = api_version;
160
161 let uri_str = format!("{}/v2/webhooks/event-types", configuration.base_path);
162 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
163
164 if let Some(ref param_value) = p_api_version {
165 req_builder = req_builder.query(&[("api_version", ¶m_value.to_string())]);
166 }
167 if let Some(ref user_agent) = configuration.user_agent {
168 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
169 }
170 if let Some(ref token) = configuration.oauth_access_token {
171 req_builder = req_builder.bearer_auth(token.to_owned());
172 };
173
174 let req = req_builder.build()?;
175 let resp = configuration.client.execute(req).await?;
176
177 let status = resp.status();
178 let content_type = resp
179 .headers()
180 .get("content-type")
181 .and_then(|v| v.to_str().ok())
182 .unwrap_or("application/octet-stream");
183 let content_type = super::ContentType::from(content_type);
184
185 if !status.is_client_error() && !status.is_server_error() {
186 let content = resp.text().await?;
187 match content_type {
188 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
189 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListWebhookEventTypesResponse`"))),
190 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::ListWebhookEventTypesResponse`")))),
191 }
192 } else {
193 let content = resp.text().await?;
194 let entity: Option<ListWebhookEventTypesError> = serde_json::from_str(&content).ok();
195 Err(Error::ResponseError(ResponseContent { status, content, entity }))
196 }
197}
198
199pub async fn list_webhook_subscriptions(configuration: &configuration::Configuration, cursor: Option<&str>, include_disabled: Option<bool>, sort_order: Option<models::SortOrder>, limit: Option<i32>) -> Result<models::ListWebhookSubscriptionsResponse, Error<ListWebhookSubscriptionsError>> {
201 let p_cursor = cursor;
203 let p_include_disabled = include_disabled;
204 let p_sort_order = sort_order;
205 let p_limit = limit;
206
207 let uri_str = format!("{}/v2/webhooks/subscriptions", configuration.base_path);
208 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
209
210 if let Some(ref param_value) = p_cursor {
211 req_builder = req_builder.query(&[("cursor", ¶m_value.to_string())]);
212 }
213 if let Some(ref param_value) = p_include_disabled {
214 req_builder = req_builder.query(&[("include_disabled", ¶m_value.to_string())]);
215 }
216 if let Some(ref param_value) = p_sort_order {
217 req_builder = req_builder.query(&[("sort_order", ¶m_value.to_string())]);
218 }
219 if let Some(ref param_value) = p_limit {
220 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
221 }
222 if let Some(ref user_agent) = configuration.user_agent {
223 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
224 }
225 if let Some(ref token) = configuration.oauth_access_token {
226 req_builder = req_builder.bearer_auth(token.to_owned());
227 };
228
229 let req = req_builder.build()?;
230 let resp = configuration.client.execute(req).await?;
231
232 let status = resp.status();
233 let content_type = resp
234 .headers()
235 .get("content-type")
236 .and_then(|v| v.to_str().ok())
237 .unwrap_or("application/octet-stream");
238 let content_type = super::ContentType::from(content_type);
239
240 if !status.is_client_error() && !status.is_server_error() {
241 let content = resp.text().await?;
242 match content_type {
243 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
244 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListWebhookSubscriptionsResponse`"))),
245 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::ListWebhookSubscriptionsResponse`")))),
246 }
247 } else {
248 let content = resp.text().await?;
249 let entity: Option<ListWebhookSubscriptionsError> = serde_json::from_str(&content).ok();
250 Err(Error::ResponseError(ResponseContent { status, content, entity }))
251 }
252}
253
254pub async fn retrieve_webhook_subscription(configuration: &configuration::Configuration, subscription_id: &str) -> Result<models::RetrieveWebhookSubscriptionResponse, Error<RetrieveWebhookSubscriptionError>> {
256 let p_subscription_id = subscription_id;
258
259 let uri_str = format!("{}/v2/webhooks/subscriptions/{subscription_id}", configuration.base_path, subscription_id=crate::apis::urlencode(p_subscription_id));
260 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
261
262 if let Some(ref user_agent) = configuration.user_agent {
263 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
264 }
265 if let Some(ref token) = configuration.oauth_access_token {
266 req_builder = req_builder.bearer_auth(token.to_owned());
267 };
268
269 let req = req_builder.build()?;
270 let resp = configuration.client.execute(req).await?;
271
272 let status = resp.status();
273 let content_type = resp
274 .headers()
275 .get("content-type")
276 .and_then(|v| v.to_str().ok())
277 .unwrap_or("application/octet-stream");
278 let content_type = super::ContentType::from(content_type);
279
280 if !status.is_client_error() && !status.is_server_error() {
281 let content = resp.text().await?;
282 match content_type {
283 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
284 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RetrieveWebhookSubscriptionResponse`"))),
285 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::RetrieveWebhookSubscriptionResponse`")))),
286 }
287 } else {
288 let content = resp.text().await?;
289 let entity: Option<RetrieveWebhookSubscriptionError> = serde_json::from_str(&content).ok();
290 Err(Error::ResponseError(ResponseContent { status, content, entity }))
291 }
292}
293
294pub async fn test_webhook_subscription(configuration: &configuration::Configuration, subscription_id: &str, test_webhook_subscription_request: models::TestWebhookSubscriptionRequest) -> Result<models::TestWebhookSubscriptionResponse, Error<TestWebhookSubscriptionError>> {
296 let p_subscription_id = subscription_id;
298 let p_test_webhook_subscription_request = test_webhook_subscription_request;
299
300 let uri_str = format!("{}/v2/webhooks/subscriptions/{subscription_id}/test", configuration.base_path, subscription_id=crate::apis::urlencode(p_subscription_id));
301 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
302
303 if let Some(ref user_agent) = configuration.user_agent {
304 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
305 }
306 if let Some(ref token) = configuration.oauth_access_token {
307 req_builder = req_builder.bearer_auth(token.to_owned());
308 };
309 req_builder = req_builder.json(&p_test_webhook_subscription_request);
310
311 let req = req_builder.build()?;
312 let resp = configuration.client.execute(req).await?;
313
314 let status = resp.status();
315 let content_type = resp
316 .headers()
317 .get("content-type")
318 .and_then(|v| v.to_str().ok())
319 .unwrap_or("application/octet-stream");
320 let content_type = super::ContentType::from(content_type);
321
322 if !status.is_client_error() && !status.is_server_error() {
323 let content = resp.text().await?;
324 match content_type {
325 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
326 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TestWebhookSubscriptionResponse`"))),
327 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::TestWebhookSubscriptionResponse`")))),
328 }
329 } else {
330 let content = resp.text().await?;
331 let entity: Option<TestWebhookSubscriptionError> = serde_json::from_str(&content).ok();
332 Err(Error::ResponseError(ResponseContent { status, content, entity }))
333 }
334}
335
336pub async fn update_webhook_subscription(configuration: &configuration::Configuration, subscription_id: &str, update_webhook_subscription_request: models::UpdateWebhookSubscriptionRequest) -> Result<models::UpdateWebhookSubscriptionResponse, Error<UpdateWebhookSubscriptionError>> {
338 let p_subscription_id = subscription_id;
340 let p_update_webhook_subscription_request = update_webhook_subscription_request;
341
342 let uri_str = format!("{}/v2/webhooks/subscriptions/{subscription_id}", configuration.base_path, subscription_id=crate::apis::urlencode(p_subscription_id));
343 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
344
345 if let Some(ref user_agent) = configuration.user_agent {
346 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
347 }
348 if let Some(ref token) = configuration.oauth_access_token {
349 req_builder = req_builder.bearer_auth(token.to_owned());
350 };
351 req_builder = req_builder.json(&p_update_webhook_subscription_request);
352
353 let req = req_builder.build()?;
354 let resp = configuration.client.execute(req).await?;
355
356 let status = resp.status();
357 let content_type = resp
358 .headers()
359 .get("content-type")
360 .and_then(|v| v.to_str().ok())
361 .unwrap_or("application/octet-stream");
362 let content_type = super::ContentType::from(content_type);
363
364 if !status.is_client_error() && !status.is_server_error() {
365 let content = resp.text().await?;
366 match content_type {
367 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
368 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UpdateWebhookSubscriptionResponse`"))),
369 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::UpdateWebhookSubscriptionResponse`")))),
370 }
371 } else {
372 let content = resp.text().await?;
373 let entity: Option<UpdateWebhookSubscriptionError> = serde_json::from_str(&content).ok();
374 Err(Error::ResponseError(ResponseContent { status, content, entity }))
375 }
376}
377
378pub async fn update_webhook_subscription_signature_key(configuration: &configuration::Configuration, subscription_id: &str, update_webhook_subscription_signature_key_request: models::UpdateWebhookSubscriptionSignatureKeyRequest) -> Result<models::UpdateWebhookSubscriptionSignatureKeyResponse, Error<UpdateWebhookSubscriptionSignatureKeyError>> {
380 let p_subscription_id = subscription_id;
382 let p_update_webhook_subscription_signature_key_request = update_webhook_subscription_signature_key_request;
383
384 let uri_str = format!("{}/v2/webhooks/subscriptions/{subscription_id}/signature-key", configuration.base_path, subscription_id=crate::apis::urlencode(p_subscription_id));
385 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
386
387 if let Some(ref user_agent) = configuration.user_agent {
388 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
389 }
390 if let Some(ref token) = configuration.oauth_access_token {
391 req_builder = req_builder.bearer_auth(token.to_owned());
392 };
393 req_builder = req_builder.json(&p_update_webhook_subscription_signature_key_request);
394
395 let req = req_builder.build()?;
396 let resp = configuration.client.execute(req).await?;
397
398 let status = resp.status();
399 let content_type = resp
400 .headers()
401 .get("content-type")
402 .and_then(|v| v.to_str().ok())
403 .unwrap_or("application/octet-stream");
404 let content_type = super::ContentType::from(content_type);
405
406 if !status.is_client_error() && !status.is_server_error() {
407 let content = resp.text().await?;
408 match content_type {
409 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
410 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UpdateWebhookSubscriptionSignatureKeyResponse`"))),
411 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::UpdateWebhookSubscriptionSignatureKeyResponse`")))),
412 }
413 } else {
414 let content = resp.text().await?;
415 let entity: Option<UpdateWebhookSubscriptionSignatureKeyError> = serde_json::from_str(&content).ok();
416 Err(Error::ResponseError(ResponseContent { status, content, entity }))
417 }
418}
419