sendgrid_api/
alerts.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct Alerts {
5    pub client: Client,
6}
7
8impl Alerts {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        Alerts { client }
12    }
13
14    /**
15     * Retrieve all alerts.
16     *
17     * This function performs a `GET` to the `/alerts` endpoint.
18     *
19     * **This endpoint allows you to retrieve all of your alerts.**
20     *
21     * Alerts allow you to specify an email address to receive notifications regarding your email usage or statistics.
22     * * Usage alerts allow you to set the threshold at which an alert will be sent.
23     * * Stats notifications allow you to set how frequently you would like to receive email statistics reports. For example, "daily", "weekly", or "monthly".
24     *
25     * For more information about alerts, please see our [Alerts documentation](https://sendgrid.com/docs/ui/account-and-settings/alerts/).
26     *
27     * **Parameters:**
28     *
29     * * `authorization: &str` -- The license key provided with your New Relic account.
30     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
31     */
32    pub async fn get_page(
33        &self,
34    ) -> ClientResult<crate::Response<Vec<crate::types::GetAlertsResponse>>> {
35        let url = self.client.url("/alerts", None);
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 alerts.
48     *
49     * This function performs a `GET` to the `/alerts` endpoint.
50     *
51     * As opposed to `get`, this function returns all the pages of the request at once.
52     *
53     * **This endpoint allows you to retrieve all of your alerts.**
54     *
55     * Alerts allow you to specify an email address to receive notifications regarding your email usage or statistics.
56     * * Usage alerts allow you to set the threshold at which an alert will be sent.
57     * * Stats notifications allow you to set how frequently you would like to receive email statistics reports. For example, "daily", "weekly", or "monthly".
58     *
59     * For more information about alerts, please see our [Alerts documentation](https://sendgrid.com/docs/ui/account-and-settings/alerts/).
60     */
61    pub async fn get_all(
62        &self,
63    ) -> ClientResult<crate::Response<Vec<crate::types::GetAlertsResponse>>> {
64        let url = self.client.url("/alerts", None);
65        self.client
66            .get_all_pages(
67                &url,
68                crate::Message {
69                    body: None,
70                    content_type: None,
71                },
72            )
73            .await
74    }
75    /**
76     * Create a new Alert.
77     *
78     * This function performs a `POST` to the `/alerts` endpoint.
79     *
80     * **This endpoint allows you to create a new alert.**
81     *
82     * Alerts allow you to specify an email address to receive notifications regarding your email usage or statistics. There are two types of alerts that can be created with this endpoint:
83     *
84     * * `usage_limit` allows you to set the threshold at which an alert will be sent.
85     * * `stats_notification` allows you to set how frequently you would like to receive email statistics reports. For example, "daily", "weekly", or "monthly".
86     *
87     * For more information about alerts, please see our [Alerts documentation](https://sendgrid.com/docs/ui/account-and-settings/alerts/).
88     *
89     * **Parameters:**
90     *
91     * * `authorization: &str` -- The license key provided with your New Relic account.
92     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
93     */
94    pub async fn post(
95        &self,
96        body: &crate::types::PostAlertsRequest,
97    ) -> ClientResult<crate::Response<crate::types::PostAlertsResponse>> {
98        let url = self.client.url("/alerts", None);
99        self.client
100            .post(
101                &url,
102                crate::Message {
103                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
104                    content_type: Some("application/json".to_string()),
105                },
106            )
107            .await
108    }
109    /**
110     * Retrieve a specific alert.
111     *
112     * This function performs a `GET` to the `/alerts/{alert_id}` endpoint.
113     *
114     * **This endpoint allows you to retrieve a specific alert.**
115     *
116     * Alerts allow you to specify an email address to receive notifications regarding your email usage or statistics.
117     * * Usage alerts allow you to set the threshold at which an alert will be sent.
118     * * Stats notifications allow you to set how frequently you would like to receive email statistics reports. For example, "daily", "weekly", or "monthly".
119     *
120     * For more information about alerts, please see our [Alerts documentation](https://sendgrid.com/docs/ui/account-and-settings/alerts/).
121     *
122     * **Parameters:**
123     *
124     * * `authorization: &str` -- The license key provided with your New Relic account.
125     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
126     */
127    pub async fn get(
128        &self,
129        alert_id: i64,
130    ) -> ClientResult<crate::Response<crate::types::GetAlertsAlertResponse>> {
131        let url = self.client.url(
132            &format!(
133                "/alerts/{}",
134                crate::progenitor_support::encode_path(&alert_id.to_string()),
135            ),
136            None,
137        );
138        self.client
139            .get(
140                &url,
141                crate::Message {
142                    body: None,
143                    content_type: None,
144                },
145            )
146            .await
147    }
148    /**
149     * Delete an alert.
150     *
151     * This function performs a `DELETE` to the `/alerts/{alert_id}` endpoint.
152     *
153     * **This endpoint allows you to delete an alert.**
154     *
155     * Alerts allow you to specify an email address to receive notifications regarding your email usage or statistics.
156     * * Usage alerts allow you to set the threshold at which an alert will be sent.
157     * * Stats notifications allow you to set how frequently you would like to receive email statistics reports. For example, "daily", "weekly", or "monthly".
158     *
159     * For more information about alerts, please see our [Alerts documentation](https://sendgrid.com/docs/ui/account-and-settings/alerts/).
160     *
161     * **Parameters:**
162     *
163     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
164     */
165    pub async fn delete(&self, alert_id: i64) -> ClientResult<crate::Response<crate::types::Help>> {
166        let url = self.client.url(
167            &format!(
168                "/alerts/{}",
169                crate::progenitor_support::encode_path(&alert_id.to_string()),
170            ),
171            None,
172        );
173        self.client
174            .delete(
175                &url,
176                crate::Message {
177                    body: None,
178                    content_type: None,
179                },
180            )
181            .await
182    }
183    /**
184     * Update an alert.
185     *
186     * This function performs a `PATCH` to the `/alerts/{alert_id}` endpoint.
187     *
188     * **This endpoint allows you to update an alert.**
189     *
190     * Alerts allow you to specify an email address to receive notifications regarding your email usage or statistics.
191     * * Usage alerts allow you to set the threshold at which an alert will be sent.
192     * * Stats notifications allow you to set how frequently you would like to receive email statistics reports. For example, "daily", "weekly", or "monthly".
193     *
194     * For more information about alerts, please see our [Alerts documentation](https://sendgrid.com/docs/ui/account-and-settings/alerts/).
195     *
196     * **Parameters:**
197     *
198     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
199     */
200    pub async fn patch(
201        &self,
202        alert_id: i64,
203        body: &crate::types::PatchAlertsAlertRequest,
204    ) -> ClientResult<crate::Response<crate::types::GetAlertsAlertResponse>> {
205        let url = self.client.url(
206            &format!(
207                "/alerts/{}",
208                crate::progenitor_support::encode_path(&alert_id.to_string()),
209            ),
210            None,
211        );
212        self.client
213            .patch(
214                &url,
215                crate::Message {
216                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
217                    content_type: Some("application/json".to_string()),
218                },
219            )
220            .await
221    }
222}