sendgrid_api/
blocks_api.rs

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