sendgrid_api/
suppressions.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct Suppressions {
5    pub client: Client,
6}
7
8impl Suppressions {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        Suppressions { client }
12    }
13
14    /**
15     * Retrieve all suppressions for a suppression group.
16     *
17     * This function performs a `GET` to the `/asm/groups/{group_id}/suppressions` endpoint.
18     *
19     * **This endpoint allows you to retrieve all suppressed email addresses belonging to the given group.**
20     *
21     * **Parameters:**
22     *
23     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
24     */
25    pub async fn get_asm_groups_group(
26        &self,
27        group_id: &str,
28    ) -> ClientResult<crate::Response<Vec<String>>> {
29        let url = self.client.url(
30            &format!(
31                "/asm/groups/{}/suppressions",
32                crate::progenitor_support::encode_path(group_id),
33            ),
34            None,
35        );
36        self.client
37            .get(
38                &url,
39                crate::Message {
40                    body: None,
41                    content_type: None,
42                },
43            )
44            .await
45    }
46    /**
47     * Retrieve all suppressions for a suppression group.
48     *
49     * This function performs a `GET` to the `/asm/groups/{group_id}/suppressions` endpoint.
50     *
51     * As opposed to `get_asm_groups_group`, this function returns all the pages of the request at once.
52     *
53     * **This endpoint allows you to retrieve all suppressed email addresses belonging to the given group.**
54     */
55    pub async fn get_all_asm_groups_group(
56        &self,
57        group_id: &str,
58    ) -> ClientResult<crate::Response<Vec<String>>> {
59        let url = self.client.url(
60            &format!(
61                "/asm/groups/{}/suppressions",
62                crate::progenitor_support::encode_path(group_id),
63            ),
64            None,
65        );
66        self.client
67            .get_all_pages(
68                &url,
69                crate::Message {
70                    body: None,
71                    content_type: None,
72                },
73            )
74            .await
75    }
76    /**
77     * Add suppressions to a suppression group.
78     *
79     * This function performs a `POST` to the `/asm/groups/{group_id}/suppressions` endpoint.
80     *
81     * **This endpoint allows you to add email addresses to an unsubscribe group.**
82     *
83     * If you attempt to add suppressions to a group that has been deleted or does not exist, the suppressions will be added to the global suppressions list.
84     *
85     * **Parameters:**
86     *
87     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
88     */
89    pub async fn post_asm_groups_group(
90        &self,
91        group_id: &str,
92        body: &crate::types::SuppressionsRequestBody,
93    ) -> ClientResult<crate::Response<crate::types::PostAsmGroupsGroupSuppressionsResponse>> {
94        let url = self.client.url(
95            &format!(
96                "/asm/groups/{}/suppressions",
97                crate::progenitor_support::encode_path(group_id),
98            ),
99            None,
100        );
101        self.client
102            .post(
103                &url,
104                crate::Message {
105                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
106                    content_type: None,
107                },
108            )
109            .await
110    }
111    /**
112     * Search for suppressions within a group.
113     *
114     * This function performs a `POST` to the `/asm/groups/{group_id}/suppressions/search` endpoint.
115     *
116     * **This endpoint allows you to search a suppression group for multiple suppressions.**
117     *
118     * When given a list of email addresses and a group ID, this endpoint will only return the email addresses that have been unsubscribed from the given group.
119     *
120     * **Parameters:**
121     *
122     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
123     */
124    pub async fn post_asm_groups_group_search(
125        &self,
126        group_id: &str,
127        body: &crate::types::SuppressionsRequestBody,
128    ) -> ClientResult<crate::Response<Vec<String>>> {
129        let url = self.client.url(
130            &format!(
131                "/asm/groups/{}/suppressions/search",
132                crate::progenitor_support::encode_path(group_id),
133            ),
134            None,
135        );
136        self.client
137            .post(
138                &url,
139                crate::Message {
140                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
141                    content_type: None,
142                },
143            )
144            .await
145    }
146    /**
147     * Retrieve all suppressions.
148     *
149     * This function performs a `GET` to the `/asm/suppressions` endpoint.
150     *
151     * **This endpoint allows you to retrieve a list of all suppressions.**
152     *
153     * **Parameters:**
154     *
155     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
156     */
157    pub async fn get_asm(
158        &self,
159    ) -> ClientResult<crate::Response<Vec<crate::types::GetAsmSuppressionsResponse>>> {
160        let url = self.client.url("/asm/suppressions", None);
161        self.client
162            .get(
163                &url,
164                crate::Message {
165                    body: None,
166                    content_type: None,
167                },
168            )
169            .await
170    }
171    /**
172     * Retrieve all suppressions.
173     *
174     * This function performs a `GET` to the `/asm/suppressions` endpoint.
175     *
176     * As opposed to `get_asm`, this function returns all the pages of the request at once.
177     *
178     * **This endpoint allows you to retrieve a list of all suppressions.**
179     */
180    pub async fn get_all_asm(
181        &self,
182    ) -> ClientResult<crate::Response<Vec<crate::types::GetAsmSuppressionsResponse>>> {
183        let url = self.client.url("/asm/suppressions", None);
184        self.client
185            .get_all_pages(
186                &url,
187                crate::Message {
188                    body: None,
189                    content_type: None,
190                },
191            )
192            .await
193    }
194    /**
195     * Retrieve all suppression groups for an email address.
196     *
197     * This function performs a `GET` to the `/asm/suppressions/{email}` endpoint.
198     *
199     * **This endpoint returns a list of all groups from which the given email address has been unsubscribed.**
200     *
201     * **Parameters:**
202     *
203     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
204     */
205    pub async fn get_asm_email(
206        &self,
207        email: &str,
208    ) -> ClientResult<crate::Response<crate::types::GetAsmSuppressionsEmailResponse>> {
209        let url = self.client.url(
210            &format!(
211                "/asm/suppressions/{}",
212                crate::progenitor_support::encode_path(email),
213            ),
214            None,
215        );
216        self.client
217            .get(
218                &url,
219                crate::Message {
220                    body: None,
221                    content_type: None,
222                },
223            )
224            .await
225    }
226    /**
227     * Delete a suppression from a suppression group.
228     *
229     * This function performs a `DELETE` to the `/asm/groups/{group_id}/suppressions/{email}` endpoint.
230     *
231     * **This endpoint allows you to remove a suppressed email address from the given suppression group.**
232     *
233     * Removing an address will remove the suppression, meaning email will once again be sent to the previously suppressed addresses. This should be avoided unless a recipient indicates they wish to receive email from you again. You can use our [bypass filters](https://sendgrid.com/docs/ui/sending-email/index-suppressions/#bypass-suppressions) to deliver messages to otherwise suppressed addresses when exceptions are required.
234     *
235     * **Parameters:**
236     *
237     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
238     */
239    pub async fn delete_asm_groups_group_email(
240        &self,
241        group_id: &str,
242        email: &str,
243    ) -> ClientResult<crate::Response<()>> {
244        let url = self.client.url(
245            &format!(
246                "/asm/groups/{}/suppressions/{}",
247                crate::progenitor_support::encode_path(group_id),
248                crate::progenitor_support::encode_path(email),
249            ),
250            None,
251        );
252        self.client
253            .delete(
254                &url,
255                crate::Message {
256                    body: None,
257                    content_type: None,
258                },
259            )
260            .await
261    }
262}