sendgrid_api/
bounces_api.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct BouncesApi {
5    pub client: Client,
6}
7
8impl BouncesApi {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        BouncesApi { client }
12    }
13
14    /**
15     * Retrieve all bounces.
16     *
17     * This function performs a `GET` to the `/suppression/bounces` endpoint.
18     *
19     * **This endpoint allows you to retrieve all of your bounces.**
20     *
21     * **Parameters:**
22     *
23     * * `start_time: i64` -- Refers start of the time range in unix timestamp when a bounce was created (inclusive).
24     * * `end_time: i64` -- Refers end of the time range in unix timestamp when a bounce was created (inclusive).
25     * * `accept: &str` -- The license key provided with your New Relic account.
26     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
27     */
28    pub async fn get_suppression_bounces(
29        &self,
30        start_time: i64,
31        end_time: i64,
32    ) -> ClientResult<crate::Response<Vec<crate::types::BounceResponse>>> {
33        let mut query_args: Vec<(String, String)> = Default::default();
34        if end_time > 0 {
35            query_args.push(("end_time".to_string(), end_time.to_string()));
36        }
37        if start_time > 0 {
38            query_args.push(("start_time".to_string(), start_time.to_string()));
39        }
40        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
41        let url = self
42            .client
43            .url(&format!("/suppression/bounces?{}", query_), None);
44        self.client
45            .get(
46                &url,
47                crate::Message {
48                    body: None,
49                    content_type: None,
50                },
51            )
52            .await
53    }
54    /**
55     * Retrieve all bounces.
56     *
57     * This function performs a `GET` to the `/suppression/bounces` endpoint.
58     *
59     * As opposed to `get_suppression_bounces`, this function returns all the pages of the request at once.
60     *
61     * **This endpoint allows you to retrieve all of your bounces.**
62     */
63    pub async fn get_all_suppression_bounces(
64        &self,
65        start_time: i64,
66        end_time: i64,
67    ) -> ClientResult<crate::Response<Vec<crate::types::BounceResponse>>> {
68        let mut query_args: Vec<(String, String)> = Default::default();
69        if end_time > 0 {
70            query_args.push(("end_time".to_string(), end_time.to_string()));
71        }
72        if start_time > 0 {
73            query_args.push(("start_time".to_string(), start_time.to_string()));
74        }
75        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
76        let url = self
77            .client
78            .url(&format!("/suppression/bounces?{}", query_), None);
79        self.client
80            .get_all_pages(
81                &url,
82                crate::Message {
83                    body: None,
84                    content_type: None,
85                },
86            )
87            .await
88    }
89    /**
90     * Delete bounces.
91     *
92     * This function performs a `DELETE` to the `/suppression/bounces` endpoint.
93     *
94     * **This endpoint allows you to delete all emails on your bounces list.**
95     *
96     * There are two options for deleting bounced emails:
97     *
98     * 1. You can delete all bounced emails by setting `delete_all` to `true` in the request body.
99     * 2. You can delete a selection of bounced emails by specifying the email addresses in the `emails` array of the request body.
100     *
101     * **Parameters:**
102     *
103     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
104     */
105    pub async fn delete_suppression_bounces(
106        &self,
107        body: &crate::types::DeleteSuppressionBouncesRequest,
108    ) -> ClientResult<crate::Response<()>> {
109        let url = self.client.url("/suppression/bounces", None);
110        self.client
111            .delete(
112                &url,
113                crate::Message {
114                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
115                    content_type: Some("application/json".to_string()),
116                },
117            )
118            .await
119    }
120    /**
121     * Retrieve a Bounce.
122     *
123     * This function performs a `GET` to the `/suppression/bounces/{email}` endpoint.
124     *
125     * **This endpoint allows you to retrieve a specific bounce by email address.**
126     *
127     * **Parameters:**
128     *
129     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
130     */
131    pub async fn get_suppression_bounces_email(
132        &self,
133        email: &str,
134    ) -> ClientResult<crate::Response<Vec<crate::types::BounceResponse>>> {
135        let url = self.client.url(
136            &format!(
137                "/suppression/bounces/{}",
138                crate::progenitor_support::encode_path(email),
139            ),
140            None,
141        );
142        self.client
143            .get(
144                &url,
145                crate::Message {
146                    body: None,
147                    content_type: None,
148                },
149            )
150            .await
151    }
152    /**
153     * Retrieve a Bounce.
154     *
155     * This function performs a `GET` to the `/suppression/bounces/{email}` endpoint.
156     *
157     * As opposed to `get_suppression_bounces_email`, this function returns all the pages of the request at once.
158     *
159     * **This endpoint allows you to retrieve a specific bounce by email address.**
160     */
161    pub async fn get_all_suppression_bounces_email(
162        &self,
163        email: &str,
164    ) -> ClientResult<crate::Response<Vec<crate::types::BounceResponse>>> {
165        let url = self.client.url(
166            &format!(
167                "/suppression/bounces/{}",
168                crate::progenitor_support::encode_path(email),
169            ),
170            None,
171        );
172        self.client
173            .get_all_pages(
174                &url,
175                crate::Message {
176                    body: None,
177                    content_type: None,
178                },
179            )
180            .await
181    }
182    /**
183     * Delete a bounce.
184     *
185     * This function performs a `DELETE` to the `/suppression/bounces/{email}` endpoint.
186     *
187     * **This endpoint allows you to remove an email address from your bounce list.**
188     *
189     * **Parameters:**
190     *
191     * * `email_address: &str` -- The email address you would like to remove from the bounce list.
192     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
193     */
194    pub async fn delete_suppression_bounces_email(
195        &self,
196        email: &str,
197        email_address: &str,
198        body: &serde_json::Value,
199    ) -> ClientResult<crate::Response<crate::types::Help>> {
200        let mut query_args: Vec<(String, String)> = Default::default();
201        if !email_address.is_empty() {
202            query_args.push(("email_address".to_string(), email_address.to_string()));
203        }
204        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
205        let url = self.client.url(
206            &format!(
207                "/suppression/bounces/{}?{}",
208                crate::progenitor_support::encode_path(email),
209                query_
210            ),
211            None,
212        );
213        self.client
214            .delete(
215                &url,
216                crate::Message {
217                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
218                    content_type: None,
219                },
220            )
221            .await
222    }
223}