sendgrid2/request/
get_suppression_bounces.rs1use serde_json::json;
2use crate::model::*;
3use crate::SendgridClient;
4pub struct GetSuppressionBouncesRequest<'a> {
8 pub(crate) client: &'a SendgridClient,
9 pub start_time: Option<i64>,
10 pub end_time: Option<i64>,
11 pub limit: Option<i64>,
12 pub offset: Option<i64>,
13 pub accept: String,
14 pub on_behalf_of: Option<String>,
15}
16impl<'a> GetSuppressionBouncesRequest<'a> {
17 pub async fn send(self) -> anyhow::Result<Vec<BounceResponse>> {
18 let mut r = self.client.client.get("/v3/suppression/bounces");
19 if let Some(ref unwrapped) = self.start_time {
20 r = r.push_query("start_time", &unwrapped.to_string());
21 }
22 if let Some(ref unwrapped) = self.end_time {
23 r = r.push_query("end_time", &unwrapped.to_string());
24 }
25 if let Some(ref unwrapped) = self.limit {
26 r = r.push_query("limit", &unwrapped.to_string());
27 }
28 if let Some(ref unwrapped) = self.offset {
29 r = r.push_query("offset", &unwrapped.to_string());
30 }
31 r = r.header("Accept", &self.accept.to_string());
32 if let Some(ref unwrapped) = self.on_behalf_of {
33 r = r.header("on-behalf-of", &unwrapped.to_string());
34 }
35 r = self.client.authenticate(r);
36 let res = r.send().await.unwrap().error_for_status();
37 match res {
38 Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
39 Err(res) => {
40 let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
41 Err(anyhow::anyhow!("{:?}", text))
42 }
43 }
44 }
45 pub fn start_time(mut self, start_time: i64) -> Self {
46 self.start_time = Some(start_time);
47 self
48 }
49 pub fn end_time(mut self, end_time: i64) -> Self {
50 self.end_time = Some(end_time);
51 self
52 }
53 pub fn limit(mut self, limit: i64) -> Self {
54 self.limit = Some(limit);
55 self
56 }
57 pub fn offset(mut self, offset: i64) -> Self {
58 self.offset = Some(offset);
59 self
60 }
61 pub fn on_behalf_of(mut self, on_behalf_of: &str) -> Self {
62 self.on_behalf_of = Some(on_behalf_of.to_owned());
63 self
64 }
65}