1use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum AddBroadcastRecipientsError {
20 Status401(models::InlineObject),
21 Status404(models::InlineObject1),
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum CancelBroadcastError {
29 Status400(),
30 Status401(models::InlineObject),
31 Status404(models::InlineObject1),
32 UnknownValue(serde_json::Value),
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum CreateBroadcastError {
39 Status401(models::InlineObject),
40 UnknownValue(serde_json::Value),
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
45#[serde(untagged)]
46pub enum DeleteBroadcastError {
47 Status401(models::InlineObject),
48 Status404(models::InlineObject1),
49 UnknownValue(serde_json::Value),
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum GetBroadcastError {
56 Status401(models::InlineObject),
57 Status404(models::InlineObject1),
58 UnknownValue(serde_json::Value),
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum ListBroadcastRecipientsError {
65 Status401(models::InlineObject),
66 Status404(models::InlineObject1),
67 UnknownValue(serde_json::Value),
68}
69
70#[derive(Debug, Clone, Serialize, Deserialize)]
72#[serde(untagged)]
73pub enum ListBroadcastsError {
74 Status401(models::InlineObject),
75 UnknownValue(serde_json::Value),
76}
77
78#[derive(Debug, Clone, Serialize, Deserialize)]
80#[serde(untagged)]
81pub enum ScheduleBroadcastError {
82 Status400(),
83 Status401(models::InlineObject),
84 Status404(models::InlineObject1),
85 UnknownValue(serde_json::Value),
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum SendBroadcastError {
92 Status400(),
93 Status401(models::InlineObject),
94 Status404(models::InlineObject1),
95 UnknownValue(serde_json::Value),
96}
97
98#[derive(Debug, Clone, Serialize, Deserialize)]
100#[serde(untagged)]
101pub enum UpdateBroadcastError {
102 Status401(models::InlineObject),
103 Status404(models::InlineObject1),
104 UnknownValue(serde_json::Value),
105}
106
107pub async fn add_broadcast_recipients(
109 configuration: &configuration::Configuration,
110 broadcast_id: &str,
111 add_broadcast_recipients_request: models::AddBroadcastRecipientsRequest,
112) -> Result<models::AddBroadcastRecipients200Response, Error<AddBroadcastRecipientsError>> {
113 let p_path_broadcast_id = broadcast_id;
115 let p_body_add_broadcast_recipients_request = add_broadcast_recipients_request;
116
117 let uri_str = format!(
118 "{}/v1/broadcasts/{broadcastId}/recipients",
119 configuration.base_path,
120 broadcastId = crate::apis::urlencode(p_path_broadcast_id)
121 );
122 let mut req_builder = configuration
123 .client
124 .request(reqwest::Method::POST, &uri_str);
125
126 if let Some(ref user_agent) = configuration.user_agent {
127 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
128 }
129 if let Some(ref token) = configuration.bearer_access_token {
130 req_builder = req_builder.bearer_auth(token.to_owned());
131 };
132 req_builder = req_builder.json(&p_body_add_broadcast_recipients_request);
133
134 let req = req_builder.build()?;
135 let resp = configuration.client.execute(req).await?;
136
137 let status = resp.status();
138 let content_type = resp
139 .headers()
140 .get("content-type")
141 .and_then(|v| v.to_str().ok())
142 .unwrap_or("application/octet-stream");
143 let content_type = super::ContentType::from(content_type);
144
145 if !status.is_client_error() && !status.is_server_error() {
146 let content = resp.text().await?;
147 match content_type {
148 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
149 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AddBroadcastRecipients200Response`"))),
150 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::AddBroadcastRecipients200Response`")))),
151 }
152 } else {
153 let content = resp.text().await?;
154 let entity: Option<AddBroadcastRecipientsError> = serde_json::from_str(&content).ok();
155 Err(Error::ResponseError(ResponseContent {
156 status,
157 content,
158 entity,
159 }))
160 }
161}
162
163pub async fn cancel_broadcast(
165 configuration: &configuration::Configuration,
166 broadcast_id: &str,
167) -> Result<models::CancelBroadcast200Response, Error<CancelBroadcastError>> {
168 let p_path_broadcast_id = broadcast_id;
170
171 let uri_str = format!(
172 "{}/v1/broadcasts/{broadcastId}/cancel",
173 configuration.base_path,
174 broadcastId = crate::apis::urlencode(p_path_broadcast_id)
175 );
176 let mut req_builder = configuration
177 .client
178 .request(reqwest::Method::POST, &uri_str);
179
180 if let Some(ref user_agent) = configuration.user_agent {
181 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
182 }
183 if let Some(ref token) = configuration.bearer_access_token {
184 req_builder = req_builder.bearer_auth(token.to_owned());
185 };
186
187 let req = req_builder.build()?;
188 let resp = configuration.client.execute(req).await?;
189
190 let status = resp.status();
191 let content_type = resp
192 .headers()
193 .get("content-type")
194 .and_then(|v| v.to_str().ok())
195 .unwrap_or("application/octet-stream");
196 let content_type = super::ContentType::from(content_type);
197
198 if !status.is_client_error() && !status.is_server_error() {
199 let content = resp.text().await?;
200 match content_type {
201 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
202 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CancelBroadcast200Response`"))),
203 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::CancelBroadcast200Response`")))),
204 }
205 } else {
206 let content = resp.text().await?;
207 let entity: Option<CancelBroadcastError> = serde_json::from_str(&content).ok();
208 Err(Error::ResponseError(ResponseContent {
209 status,
210 content,
211 entity,
212 }))
213 }
214}
215
216pub async fn create_broadcast(
218 configuration: &configuration::Configuration,
219 create_broadcast_request: models::CreateBroadcastRequest,
220) -> Result<models::CreateBroadcast200Response, Error<CreateBroadcastError>> {
221 let p_body_create_broadcast_request = create_broadcast_request;
223
224 let uri_str = format!("{}/v1/broadcasts", configuration.base_path);
225 let mut req_builder = configuration
226 .client
227 .request(reqwest::Method::POST, &uri_str);
228
229 if let Some(ref user_agent) = configuration.user_agent {
230 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
231 }
232 if let Some(ref token) = configuration.bearer_access_token {
233 req_builder = req_builder.bearer_auth(token.to_owned());
234 };
235 req_builder = req_builder.json(&p_body_create_broadcast_request);
236
237 let req = req_builder.build()?;
238 let resp = configuration.client.execute(req).await?;
239
240 let status = resp.status();
241 let content_type = resp
242 .headers()
243 .get("content-type")
244 .and_then(|v| v.to_str().ok())
245 .unwrap_or("application/octet-stream");
246 let content_type = super::ContentType::from(content_type);
247
248 if !status.is_client_error() && !status.is_server_error() {
249 let content = resp.text().await?;
250 match content_type {
251 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
252 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateBroadcast200Response`"))),
253 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::CreateBroadcast200Response`")))),
254 }
255 } else {
256 let content = resp.text().await?;
257 let entity: Option<CreateBroadcastError> = serde_json::from_str(&content).ok();
258 Err(Error::ResponseError(ResponseContent {
259 status,
260 content,
261 entity,
262 }))
263 }
264}
265
266pub async fn delete_broadcast(
268 configuration: &configuration::Configuration,
269 broadcast_id: &str,
270) -> Result<(), Error<DeleteBroadcastError>> {
271 let p_path_broadcast_id = broadcast_id;
273
274 let uri_str = format!(
275 "{}/v1/broadcasts/{broadcastId}",
276 configuration.base_path,
277 broadcastId = crate::apis::urlencode(p_path_broadcast_id)
278 );
279 let mut req_builder = configuration
280 .client
281 .request(reqwest::Method::DELETE, &uri_str);
282
283 if let Some(ref user_agent) = configuration.user_agent {
284 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
285 }
286 if let Some(ref token) = configuration.bearer_access_token {
287 req_builder = req_builder.bearer_auth(token.to_owned());
288 };
289
290 let req = req_builder.build()?;
291 let resp = configuration.client.execute(req).await?;
292
293 let status = resp.status();
294
295 if !status.is_client_error() && !status.is_server_error() {
296 Ok(())
297 } else {
298 let content = resp.text().await?;
299 let entity: Option<DeleteBroadcastError> = serde_json::from_str(&content).ok();
300 Err(Error::ResponseError(ResponseContent {
301 status,
302 content,
303 entity,
304 }))
305 }
306}
307
308pub async fn get_broadcast(
310 configuration: &configuration::Configuration,
311 broadcast_id: &str,
312) -> Result<models::GetBroadcast200Response, Error<GetBroadcastError>> {
313 let p_path_broadcast_id = broadcast_id;
315
316 let uri_str = format!(
317 "{}/v1/broadcasts/{broadcastId}",
318 configuration.base_path,
319 broadcastId = crate::apis::urlencode(p_path_broadcast_id)
320 );
321 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
322
323 if let Some(ref user_agent) = configuration.user_agent {
324 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
325 }
326 if let Some(ref token) = configuration.bearer_access_token {
327 req_builder = req_builder.bearer_auth(token.to_owned());
328 };
329
330 let req = req_builder.build()?;
331 let resp = configuration.client.execute(req).await?;
332
333 let status = resp.status();
334 let content_type = resp
335 .headers()
336 .get("content-type")
337 .and_then(|v| v.to_str().ok())
338 .unwrap_or("application/octet-stream");
339 let content_type = super::ContentType::from(content_type);
340
341 if !status.is_client_error() && !status.is_server_error() {
342 let content = resp.text().await?;
343 match content_type {
344 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
345 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetBroadcast200Response`"))),
346 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::GetBroadcast200Response`")))),
347 }
348 } else {
349 let content = resp.text().await?;
350 let entity: Option<GetBroadcastError> = serde_json::from_str(&content).ok();
351 Err(Error::ResponseError(ResponseContent {
352 status,
353 content,
354 entity,
355 }))
356 }
357}
358
359pub async fn list_broadcast_recipients(
361 configuration: &configuration::Configuration,
362 broadcast_id: &str,
363 status: Option<&str>,
364 limit: Option<i32>,
365 skip: Option<i32>,
366) -> Result<models::ListBroadcastRecipients200Response, Error<ListBroadcastRecipientsError>> {
367 let p_path_broadcast_id = broadcast_id;
369 let p_query_status = status;
370 let p_query_limit = limit;
371 let p_query_skip = skip;
372
373 let uri_str = format!(
374 "{}/v1/broadcasts/{broadcastId}/recipients",
375 configuration.base_path,
376 broadcastId = crate::apis::urlencode(p_path_broadcast_id)
377 );
378 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
379
380 if let Some(ref param_value) = p_query_status {
381 req_builder = req_builder.query(&[("status", ¶m_value.to_string())]);
382 }
383 if let Some(ref param_value) = p_query_limit {
384 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
385 }
386 if let Some(ref param_value) = p_query_skip {
387 req_builder = req_builder.query(&[("skip", ¶m_value.to_string())]);
388 }
389 if let Some(ref user_agent) = configuration.user_agent {
390 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
391 }
392 if let Some(ref token) = configuration.bearer_access_token {
393 req_builder = req_builder.bearer_auth(token.to_owned());
394 };
395
396 let req = req_builder.build()?;
397 let resp = configuration.client.execute(req).await?;
398
399 let status = resp.status();
400 let content_type = resp
401 .headers()
402 .get("content-type")
403 .and_then(|v| v.to_str().ok())
404 .unwrap_or("application/octet-stream");
405 let content_type = super::ContentType::from(content_type);
406
407 if !status.is_client_error() && !status.is_server_error() {
408 let content = resp.text().await?;
409 match content_type {
410 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
411 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListBroadcastRecipients200Response`"))),
412 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::ListBroadcastRecipients200Response`")))),
413 }
414 } else {
415 let content = resp.text().await?;
416 let entity: Option<ListBroadcastRecipientsError> = serde_json::from_str(&content).ok();
417 Err(Error::ResponseError(ResponseContent {
418 status,
419 content,
420 entity,
421 }))
422 }
423}
424
425pub async fn list_broadcasts(
427 configuration: &configuration::Configuration,
428 profile_id: Option<&str>,
429 status: Option<&str>,
430 platform: Option<&str>,
431 limit: Option<i32>,
432 skip: Option<i32>,
433) -> Result<models::ListBroadcasts200Response, Error<ListBroadcastsError>> {
434 let p_query_profile_id = profile_id;
436 let p_query_status = status;
437 let p_query_platform = platform;
438 let p_query_limit = limit;
439 let p_query_skip = skip;
440
441 let uri_str = format!("{}/v1/broadcasts", configuration.base_path);
442 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
443
444 if let Some(ref param_value) = p_query_profile_id {
445 req_builder = req_builder.query(&[("profileId", ¶m_value.to_string())]);
446 }
447 if let Some(ref param_value) = p_query_status {
448 req_builder = req_builder.query(&[("status", ¶m_value.to_string())]);
449 }
450 if let Some(ref param_value) = p_query_platform {
451 req_builder = req_builder.query(&[("platform", ¶m_value.to_string())]);
452 }
453 if let Some(ref param_value) = p_query_limit {
454 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
455 }
456 if let Some(ref param_value) = p_query_skip {
457 req_builder = req_builder.query(&[("skip", ¶m_value.to_string())]);
458 }
459 if let Some(ref user_agent) = configuration.user_agent {
460 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
461 }
462 if let Some(ref token) = configuration.bearer_access_token {
463 req_builder = req_builder.bearer_auth(token.to_owned());
464 };
465
466 let req = req_builder.build()?;
467 let resp = configuration.client.execute(req).await?;
468
469 let status = resp.status();
470 let content_type = resp
471 .headers()
472 .get("content-type")
473 .and_then(|v| v.to_str().ok())
474 .unwrap_or("application/octet-stream");
475 let content_type = super::ContentType::from(content_type);
476
477 if !status.is_client_error() && !status.is_server_error() {
478 let content = resp.text().await?;
479 match content_type {
480 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
481 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListBroadcasts200Response`"))),
482 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::ListBroadcasts200Response`")))),
483 }
484 } else {
485 let content = resp.text().await?;
486 let entity: Option<ListBroadcastsError> = serde_json::from_str(&content).ok();
487 Err(Error::ResponseError(ResponseContent {
488 status,
489 content,
490 entity,
491 }))
492 }
493}
494
495pub async fn schedule_broadcast(
497 configuration: &configuration::Configuration,
498 broadcast_id: &str,
499 schedule_broadcast_request: models::ScheduleBroadcastRequest,
500) -> Result<models::ScheduleBroadcast200Response, Error<ScheduleBroadcastError>> {
501 let p_path_broadcast_id = broadcast_id;
503 let p_body_schedule_broadcast_request = schedule_broadcast_request;
504
505 let uri_str = format!(
506 "{}/v1/broadcasts/{broadcastId}/schedule",
507 configuration.base_path,
508 broadcastId = crate::apis::urlencode(p_path_broadcast_id)
509 );
510 let mut req_builder = configuration
511 .client
512 .request(reqwest::Method::POST, &uri_str);
513
514 if let Some(ref user_agent) = configuration.user_agent {
515 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
516 }
517 if let Some(ref token) = configuration.bearer_access_token {
518 req_builder = req_builder.bearer_auth(token.to_owned());
519 };
520 req_builder = req_builder.json(&p_body_schedule_broadcast_request);
521
522 let req = req_builder.build()?;
523 let resp = configuration.client.execute(req).await?;
524
525 let status = resp.status();
526 let content_type = resp
527 .headers()
528 .get("content-type")
529 .and_then(|v| v.to_str().ok())
530 .unwrap_or("application/octet-stream");
531 let content_type = super::ContentType::from(content_type);
532
533 if !status.is_client_error() && !status.is_server_error() {
534 let content = resp.text().await?;
535 match content_type {
536 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
537 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ScheduleBroadcast200Response`"))),
538 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::ScheduleBroadcast200Response`")))),
539 }
540 } else {
541 let content = resp.text().await?;
542 let entity: Option<ScheduleBroadcastError> = serde_json::from_str(&content).ok();
543 Err(Error::ResponseError(ResponseContent {
544 status,
545 content,
546 entity,
547 }))
548 }
549}
550
551pub async fn send_broadcast(
553 configuration: &configuration::Configuration,
554 broadcast_id: &str,
555) -> Result<models::SendBroadcast200Response, Error<SendBroadcastError>> {
556 let p_path_broadcast_id = broadcast_id;
558
559 let uri_str = format!(
560 "{}/v1/broadcasts/{broadcastId}/send",
561 configuration.base_path,
562 broadcastId = crate::apis::urlencode(p_path_broadcast_id)
563 );
564 let mut req_builder = configuration
565 .client
566 .request(reqwest::Method::POST, &uri_str);
567
568 if let Some(ref user_agent) = configuration.user_agent {
569 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
570 }
571 if let Some(ref token) = configuration.bearer_access_token {
572 req_builder = req_builder.bearer_auth(token.to_owned());
573 };
574
575 let req = req_builder.build()?;
576 let resp = configuration.client.execute(req).await?;
577
578 let status = resp.status();
579 let content_type = resp
580 .headers()
581 .get("content-type")
582 .and_then(|v| v.to_str().ok())
583 .unwrap_or("application/octet-stream");
584 let content_type = super::ContentType::from(content_type);
585
586 if !status.is_client_error() && !status.is_server_error() {
587 let content = resp.text().await?;
588 match content_type {
589 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
590 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SendBroadcast200Response`"))),
591 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::SendBroadcast200Response`")))),
592 }
593 } else {
594 let content = resp.text().await?;
595 let entity: Option<SendBroadcastError> = serde_json::from_str(&content).ok();
596 Err(Error::ResponseError(ResponseContent {
597 status,
598 content,
599 entity,
600 }))
601 }
602}
603
604pub async fn update_broadcast(
606 configuration: &configuration::Configuration,
607 broadcast_id: &str,
608 update_broadcast_request: Option<models::UpdateBroadcastRequest>,
609) -> Result<models::UpdateBroadcast200Response, Error<UpdateBroadcastError>> {
610 let p_path_broadcast_id = broadcast_id;
612 let p_body_update_broadcast_request = update_broadcast_request;
613
614 let uri_str = format!(
615 "{}/v1/broadcasts/{broadcastId}",
616 configuration.base_path,
617 broadcastId = crate::apis::urlencode(p_path_broadcast_id)
618 );
619 let mut req_builder = configuration
620 .client
621 .request(reqwest::Method::PATCH, &uri_str);
622
623 if let Some(ref user_agent) = configuration.user_agent {
624 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
625 }
626 if let Some(ref token) = configuration.bearer_access_token {
627 req_builder = req_builder.bearer_auth(token.to_owned());
628 };
629 req_builder = req_builder.json(&p_body_update_broadcast_request);
630
631 let req = req_builder.build()?;
632 let resp = configuration.client.execute(req).await?;
633
634 let status = resp.status();
635 let content_type = resp
636 .headers()
637 .get("content-type")
638 .and_then(|v| v.to_str().ok())
639 .unwrap_or("application/octet-stream");
640 let content_type = super::ContentType::from(content_type);
641
642 if !status.is_client_error() && !status.is_server_error() {
643 let content = resp.text().await?;
644 match content_type {
645 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
646 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UpdateBroadcast200Response`"))),
647 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::UpdateBroadcast200Response`")))),
648 }
649 } else {
650 let content = resp.text().await?;
651 let entity: Option<UpdateBroadcastError> = serde_json::from_str(&content).ok();
652 Err(Error::ResponseError(ResponseContent {
653 status,
654 content,
655 entity,
656 }))
657 }
658}