sendgrid_api/suppressions_global.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct SuppressionsGlobal {
5 pub client: Client,
6}
7
8impl SuppressionsGlobal {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 SuppressionsGlobal { client }
12 }
13
14 /**
15 * Add recipient addresses to the global suppression group.
16 *
17 * This function performs a `POST` to the `/asm/suppressions/global` endpoint.
18 *
19 * **This endpoint allows you to add one or more email addresses to the global suppressions group.**
20 *
21 * **Parameters:**
22 *
23 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
24 */
25 pub async fn post_asm(
26 &self,
27 body: &crate::types::SuppressionsRequestBody,
28 ) -> ClientResult<crate::Response<crate::types::SuppressionsRequestBody>> {
29 let url = self.client.url("/asm/suppressions/global", None);
30 self.client
31 .post(
32 &url,
33 crate::Message {
34 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
35 content_type: None,
36 },
37 )
38 .await
39 }
40 /**
41 * Retrieve all global suppressions.
42 *
43 * This function performs a `GET` to the `/suppression/unsubscribes` endpoint.
44 *
45 * **This endpoint allows you to retrieve a list of all email address that are globally suppressed.**
46 *
47 * **Parameters:**
48 *
49 * * `start_time: i64` -- Refers start of the time range in unix timestamp when an unsubscribe email was created (inclusive).
50 * * `end_time: i64` -- Refers end of the time range in unix timestamp when an unsubscribe email was created (inclusive).
51 * * `limit: i64` -- The number of results to display on each page.
52 * * `offset: i64` -- The point in the list of results to begin displaying global suppressions.
53 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
54 */
55 pub async fn get_suppression_unsubscribes(
56 &self,
57 start_time: i64,
58 end_time: i64,
59 limit: i64,
60 offset: i64,
61 ) -> ClientResult<crate::Response<Vec<crate::types::GetSuppressionUnsubscribesResponse>>> {
62 let mut query_args: Vec<(String, String)> = Default::default();
63 if end_time > 0 {
64 query_args.push(("end_time".to_string(), end_time.to_string()));
65 }
66 if limit > 0 {
67 query_args.push(("limit".to_string(), limit.to_string()));
68 }
69 if offset > 0 {
70 query_args.push(("offset".to_string(), offset.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/unsubscribes?{}", query_), None);
79 self.client
80 .get(
81 &url,
82 crate::Message {
83 body: None,
84 content_type: None,
85 },
86 )
87 .await
88 }
89 /**
90 * Retrieve all global suppressions.
91 *
92 * This function performs a `GET` to the `/suppression/unsubscribes` endpoint.
93 *
94 * As opposed to `get_suppression_unsubscribes`, this function returns all the pages of the request at once.
95 *
96 * **This endpoint allows you to retrieve a list of all email address that are globally suppressed.**
97 */
98 pub async fn get_all_suppression_unsubscribes(
99 &self,
100 start_time: i64,
101 end_time: i64,
102 offset: i64,
103 ) -> ClientResult<crate::Response<Vec<crate::types::GetSuppressionUnsubscribesResponse>>> {
104 let mut query_args: Vec<(String, String)> = Default::default();
105 if end_time > 0 {
106 query_args.push(("end_time".to_string(), end_time.to_string()));
107 }
108 if offset > 0 {
109 query_args.push(("offset".to_string(), offset.to_string()));
110 }
111 if start_time > 0 {
112 query_args.push(("start_time".to_string(), start_time.to_string()));
113 }
114 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
115 let url = self
116 .client
117 .url(&format!("/suppression/unsubscribes?{}", query_), None);
118 self.client
119 .get_all_pages(
120 &url,
121 crate::Message {
122 body: None,
123 content_type: None,
124 },
125 )
126 .await
127 }
128 /**
129 * Retrieve a Global Suppression.
130 *
131 * This function performs a `GET` to the `/asm/suppressions/global/{email}` endpoint.
132 *
133 * **This endpoint allows you to retrieve a global suppression. You can also use this endpoint to confirm if an email address is already globally suppresed.**
134 *
135 * If the email address you include in the URL path parameter `{email}` is already globally suppressed, the response will include that email address. If the address you enter for `{email}` is not globally suppressed, an empty JSON object `{}` will be returned.
136 *
137 * **Parameters:**
138 *
139 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
140 */
141 pub async fn get_asm_email(
142 &self,
143 email: &str,
144 ) -> ClientResult<crate::Response<crate::types::RetrieveAGlobalSuppressionResponse>> {
145 let url = self.client.url(
146 &format!(
147 "/asm/suppressions/global/{}",
148 crate::progenitor_support::encode_path(email),
149 ),
150 None,
151 );
152 self.client
153 .get(
154 &url,
155 crate::Message {
156 body: None,
157 content_type: None,
158 },
159 )
160 .await
161 }
162 /**
163 * Delete a Global Suppression.
164 *
165 * This function performs a `DELETE` to the `/asm/suppressions/global/{email}` endpoint.
166 *
167 * **This endpoint allows you to remove an email address from the global suppressions group.**
168 *
169 * Deleting a suppression group 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.
170 *
171 * **Parameters:**
172 *
173 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
174 */
175 pub async fn delete_asm_email(
176 &self,
177 email: &str,
178 ) -> ClientResult<crate::Response<crate::types::Help>> {
179 let url = self.client.url(
180 &format!(
181 "/asm/suppressions/global/{}",
182 crate::progenitor_support::encode_path(email),
183 ),
184 None,
185 );
186 self.client
187 .delete(
188 &url,
189 crate::Message {
190 body: None,
191 content_type: None,
192 },
193 )
194 .await
195 }
196}