sendgrid_api/webhooks.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct Webhooks {
5 pub client: Client,
6}
7
8impl Webhooks {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 Webhooks { client }
12 }
13
14 /**
15 * Retrieve Event Webhook settings.
16 *
17 * This function performs a `GET` to the `/user/webhooks/event/settings` endpoint.
18 *
19 * **This endpoint allows you to retrieve your current event webhook settings.**
20 *
21 * If an event type is marked as `true`, then the event webhook will include information about that event.
22 *
23 * SendGrid’s Event Webhook will notify a URL of your choice via HTTP POST with information about events that occur as SendGrid processes your email.
24 *
25 * Common uses of this data are to remove unsubscribes, react to spam reports, determine unengaged recipients, identify bounced email addresses, or create advanced analytics of your email program.
26 *
27 * **Parameters:**
28 *
29 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
30 */
31 pub async fn get_user_event_settings(
32 &self,
33 ) -> ClientResult<crate::Response<crate::types::WebhooksEventWebhookResponse>> {
34 let url = self.client.url("/user/webhooks/event/settings", None);
35 self.client
36 .get(
37 &url,
38 crate::Message {
39 body: None,
40 content_type: None,
41 },
42 )
43 .await
44 }
45 /**
46 * Update Event Notification Settings.
47 *
48 * This function performs a `PATCH` to the `/user/webhooks/event/settings` endpoint.
49 *
50 * **This endpoint allows you to update your current event webhook settings.**
51 *
52 * If an event type is marked as `true`, then the event webhook will include information about that event.
53 *
54 * SendGrid’s Event Webhook will notify a URL of your choice via HTTP POST with information about events that occur as SendGrid processes your email.
55 *
56 * Common uses of this data are to remove unsubscribes, react to spam reports, determine unengaged recipients, identify bounced email addresses, or create advanced analytics of your email program.
57 *
58 * **Parameters:**
59 *
60 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
61 */
62 pub async fn patch_user_event_settings(
63 &self,
64 body: &crate::types::WebhooksEventWebhookUpdateWithOAuthRequest,
65 ) -> ClientResult<crate::Response<crate::types::WebhooksEventWebhookResponse>> {
66 let url = self.client.url("/user/webhooks/event/settings", None);
67 self.client
68 .patch(
69 &url,
70 crate::Message {
71 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
72 content_type: Some("application/json".to_string()),
73 },
74 )
75 .await
76 }
77 /**
78 * Retrieve all parse settings.
79 *
80 * This function performs a `GET` to the `/user/webhooks/parse/settings` endpoint.
81 *
82 * **This endpoint allows you to retrieve all of your current inbound parse settings.**
83 *
84 * **Parameters:**
85 *
86 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
87 */
88 pub async fn get_user_parse_settings(
89 &self,
90 ) -> ClientResult<crate::Response<crate::types::GetUserWebhooksParseSettingsResponse>> {
91 let url = self.client.url("/user/webhooks/parse/settings", None);
92 self.client
93 .get(
94 &url,
95 crate::Message {
96 body: None,
97 content_type: None,
98 },
99 )
100 .await
101 }
102 /**
103 * Retrieves Inbound Parse Webhook statistics.
104 *
105 * This function performs a `GET` to the `/user/webhooks/parse/stats` endpoint.
106 *
107 * **This endpoint allows you to retrieve the statistics for your Parse Webhook useage.**
108 *
109 * SendGrid's Inbound Parse Webhook allows you to parse the contents and attachments of incomming emails. The Parse API can then POST the parsed emails to a URL that you specify. The Inbound Parse Webhook cannot parse messages greater than 30MB in size, including all attachments.
110 *
111 * There are a number of pre-made integrations for the SendGrid Parse Webhook which make processing events easy. You can find these integrations in the [Library Index](https://sendgrid.com/docs/Integrate/libraries.html#-Webhook-Libraries).
112 *
113 * **Parameters:**
114 *
115 * * `limit: &str` -- The license key provided with your New Relic account.
116 * * `offset: &str` -- The license key provided with your New Relic account.
117 * * `aggregated_by: crate::types::TraitStatsAdvancedBaseQueryStringsAggregatedBy` -- How to group the statistics. Must be either "day", "week", or "month".
118 * * `start_date: &str` -- The starting date of the statistics you want to retrieve. Must be in the format YYYY-MM-DD.
119 * * `end_date: &str` -- The end date of the statistics you want to retrieve. Must be in the format YYYY-MM-DD.
120 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
121 */
122 pub async fn get_user_parse_stats(
123 &self,
124 limit: &str,
125 offset: &str,
126 aggregated_by: crate::types::TraitStatsAdvancedBaseQueryStringsAggregatedBy,
127 start_date: &str,
128 end_date: &str,
129 ) -> ClientResult<crate::Response<Vec<crate::types::GetUserWebhooksParseStatsResponseData>>>
130 {
131 let mut query_args: Vec<(String, String)> = Default::default();
132 if !aggregated_by.to_string().is_empty() {
133 query_args.push(("aggregated_by".to_string(), aggregated_by.to_string()));
134 }
135 if !end_date.is_empty() {
136 query_args.push(("end_date".to_string(), end_date.to_string()));
137 }
138 if !limit.is_empty() {
139 query_args.push(("limit".to_string(), limit.to_string()));
140 }
141 if !offset.is_empty() {
142 query_args.push(("offset".to_string(), offset.to_string()));
143 }
144 if !start_date.is_empty() {
145 query_args.push(("start_date".to_string(), start_date.to_string()));
146 }
147 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
148 let url = self
149 .client
150 .url(&format!("/user/webhooks/parse/stats?{}", query_), None);
151 self.client
152 .get(
153 &url,
154 crate::Message {
155 body: None,
156 content_type: None,
157 },
158 )
159 .await
160 }
161 /**
162 * Retrieves Inbound Parse Webhook statistics.
163 *
164 * This function performs a `GET` to the `/user/webhooks/parse/stats` endpoint.
165 *
166 * As opposed to `get_user_parse_stats`, this function returns all the pages of the request at once.
167 *
168 * **This endpoint allows you to retrieve the statistics for your Parse Webhook useage.**
169 *
170 * SendGrid's Inbound Parse Webhook allows you to parse the contents and attachments of incomming emails. The Parse API can then POST the parsed emails to a URL that you specify. The Inbound Parse Webhook cannot parse messages greater than 30MB in size, including all attachments.
171 *
172 * There are a number of pre-made integrations for the SendGrid Parse Webhook which make processing events easy. You can find these integrations in the [Library Index](https://sendgrid.com/docs/Integrate/libraries.html#-Webhook-Libraries).
173 */
174 pub async fn get_all_user_parse_stats(
175 &self,
176 offset: &str,
177 aggregated_by: crate::types::TraitStatsAdvancedBaseQueryStringsAggregatedBy,
178 start_date: &str,
179 end_date: &str,
180 ) -> ClientResult<crate::Response<Vec<crate::types::GetUserWebhooksParseStatsResponseData>>>
181 {
182 let mut query_args: Vec<(String, String)> = Default::default();
183 if !aggregated_by.to_string().is_empty() {
184 query_args.push(("aggregated_by".to_string(), aggregated_by.to_string()));
185 }
186 if !end_date.is_empty() {
187 query_args.push(("end_date".to_string(), end_date.to_string()));
188 }
189 if !offset.is_empty() {
190 query_args.push(("offset".to_string(), offset.to_string()));
191 }
192 if !start_date.is_empty() {
193 query_args.push(("start_date".to_string(), start_date.to_string()));
194 }
195 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
196 let url = self
197 .client
198 .url(&format!("/user/webhooks/parse/stats?{}", query_), None);
199 self.client
200 .get_all_pages(
201 &url,
202 crate::Message {
203 body: None,
204 content_type: None,
205 },
206 )
207 .await
208 }
209 /**
210 * Retrieve Signed Webhook Public Key.
211 *
212 * This function performs a `GET` to the `/user/webhooks/event/settings/signed` endpoint.
213 *
214 * **This endpoint allows you to retrieve your signed webhook's public key.**
215 *
216 * Once you have enabled signing of the Event Webhook, you will need the public key provided to verify the signatures on requests coming from Twilio SendGrid. You can retrieve the public key from this endpoint at any time.
217 *
218 * For more information about cryptographically signing the Event Webhook, see [Getting Started with the Event Webhook Security Features](https://sendgrid.com/docs/for-developers/tracking-events/getting-started-event-webhook-security-features).
219 *
220 * **Parameters:**
221 *
222 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
223 */
224 pub async fn get_user_event_settings_signed(
225 &self,
226 ) -> ClientResult<crate::Response<crate::types::GetUserWebhooksEventSettingsSignedResponse>>
227 {
228 let url = self
229 .client
230 .url("/user/webhooks/event/settings/signed", None);
231 self.client
232 .get(
233 &url,
234 crate::Message {
235 body: None,
236 content_type: None,
237 },
238 )
239 .await
240 }
241 /**
242 * Enable/Disable Signed Webhook.
243 *
244 * This function performs a `PATCH` to the `/user/webhooks/event/settings/signed` endpoint.
245 *
246 * **This endpoint allows you to enable or disable signing of the Event Webhook.**
247 *
248 * This endpoint takes a single boolean request parameter, `enabled`. You may either enable or disable signing of the Event Webhook using this endpoint. Once enabled, you can retrieve your public key using the `/webhooks/event/settings/signed` endpoint.
249 *
250 * For more information about cryptographically signing the Event Webhook, see [Getting Started with the Event Webhook Security Features](https://sendgrid.com/docs/for-developers/tracking-events/getting-started-event-webhook-security-features).
251 *
252 * **Parameters:**
253 *
254 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
255 */
256 pub async fn patch_user_event_settings_signed(
257 &self,
258 body: &crate::types::GetTrackingSettingsOpenResponse,
259 ) -> ClientResult<crate::Response<crate::types::GetUserWebhooksEventSettingsSignedResponse>>
260 {
261 let url = self
262 .client
263 .url("/user/webhooks/event/settings/signed", None);
264 self.client
265 .patch(
266 &url,
267 crate::Message {
268 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
269 content_type: Some("application/json".to_string()),
270 },
271 )
272 .await
273 }
274 /**
275 * Test Event Notification Settings.
276 *
277 * This function performs a `POST` to the `/user/webhooks/event/test` endpoint.
278 *
279 * **This endpoint allows you to test your event webhook by sending a fake event notification post to the provided URL.**
280 *
281 * SendGrid’s Event Webhook will notify a URL of your choice via HTTP POST with information about events that occur as SendGrid processes your email.
282 *
283 * Common uses of this data are to remove unsubscribes, react to spam reports, determine unengaged recipients, identify bounced email addresses, or create advanced analytics of your email program.
284 *
285 * >**Tip**: Retry logic for this endpoint differs from other endpoints, which use a rolling 24-hour retry.
286 *
287 * If your web server does not return a 2xx response type, we will retry a POST request until we receive a 2xx response or the maximum time of 10 minutes has expired.
288 *
289 * **Parameters:**
290 *
291 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
292 */
293 pub async fn post_user_event_test(
294 &self,
295 body: &crate::types::PostUserWebhooksEventTestRequest,
296 ) -> ClientResult<crate::Response<()>> {
297 let url = self.client.url("/user/webhooks/event/test", None);
298 self.client
299 .post(
300 &url,
301 crate::Message {
302 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
303 content_type: Some("application/json".to_string()),
304 },
305 )
306 .await
307 }
308}