sendgrid_api/
ip_pools.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct IpPools {
5    pub client: Client,
6}
7
8impl IpPools {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        IpPools { client }
12    }
13
14    /**
15     * Retrieve all IP pools.
16     *
17     * This function performs a `GET` to the `/ips/pools` endpoint.
18     *
19     * **This endpoint allows you to get all of your IP pools.**
20     */
21    pub async fn get_ips_pools(
22        &self,
23    ) -> ClientResult<crate::Response<Vec<crate::types::IpPoolsPoolResp>>> {
24        let url = self.client.url("/ips/pools", None);
25        self.client
26            .get(
27                &url,
28                crate::Message {
29                    body: None,
30                    content_type: None,
31                },
32            )
33            .await
34    }
35    /**
36     * Retrieve all IP pools.
37     *
38     * This function performs a `GET` to the `/ips/pools` endpoint.
39     *
40     * As opposed to `get_ips_pools`, this function returns all the pages of the request at once.
41     *
42     * **This endpoint allows you to get all of your IP pools.**
43     */
44    pub async fn get_all_ips_pools(
45        &self,
46    ) -> ClientResult<crate::Response<Vec<crate::types::IpPoolsPoolResp>>> {
47        let url = self.client.url("/ips/pools", None);
48        self.client
49            .get_all_pages(
50                &url,
51                crate::Message {
52                    body: None,
53                    content_type: None,
54                },
55            )
56            .await
57    }
58    /**
59     * Create an IP pool.
60     *
61     * This function performs a `POST` to the `/ips/pools` endpoint.
62     *
63     * **This endpoint allows you to create an IP pool.**
64     *
65     * Before you can create an IP pool, you need to activate the IP in your SendGrid account:
66     *
67     * 1. Log into your SendGrid account.  
68     * 1. Navigate to **Settings** and then select **IP Addresses**.  
69     * 1. Find the IP address you want to activate and then click **Edit**.  
70     * 1. Check **Allow my account to send mail using this IP address**.
71     * 1. Click **Save**.
72     */
73    pub async fn post_ips_pool(
74        &self,
75        body: &crate::types::IpPool,
76    ) -> ClientResult<crate::Response<crate::types::IpPoolsPoolResp>> {
77        let url = self.client.url("/ips/pools", None);
78        self.client
79            .post(
80                &url,
81                crate::Message {
82                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
83                    content_type: Some("application/json".to_string()),
84                },
85            )
86            .await
87    }
88    /**
89     * Add an IP address to a pool.
90     *
91     * This function performs a `POST` to the `/ips/pools/{pool_name}/ips` endpoint.
92     *
93     * **This endpoint allows you to add an IP address to an IP pool.**
94     *
95     * You can add the same IP address to multiple pools. It may take up to 60 seconds for your IP address to be added to a pool after your request is made.
96     *
97     * Before you can add an IP to a pool, you need to activate it in your SendGrid account:
98     *
99     * 1. Log into your SendGrid account.  
100     * 1. Navigate to **Settings** and then select **IP Addresses**.  
101     * 1. Find the IP address you want to activate and then click **Edit**.  
102     * 1. Check **Allow my account to send mail using this IP address**.
103     * 1. Click **Save**.
104     *
105     * You can retrieve all of your available IP addresses from the "Retrieve all IP addresses" endpoint.
106     */
107    pub async fn post_ips_pools_pool_name_ip(
108        &self,
109        pool_name: &str,
110        body: &crate::types::PostIpsWarmupRequest,
111    ) -> ClientResult<crate::Response<crate::types::GetIpsAssignedResponse>> {
112        let url = self.client.url(
113            &format!(
114                "/ips/pools/{}/ips",
115                crate::progenitor_support::encode_path(pool_name),
116            ),
117            None,
118        );
119        self.client
120            .post(
121                &url,
122                crate::Message {
123                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
124                    content_type: Some("application/json".to_string()),
125                },
126            )
127            .await
128    }
129    /**
130     * Retrieve all the IPs in a specified pool.
131     *
132     * This function performs a `GET` to the `/ips/pools/{pool_name}` endpoint.
133     *
134     * **This endpoint allows you to get all of the IP addresses that are in a specific IP pool.**
135     */
136    pub async fn get_ips_pools_pool_name(
137        &self,
138        pool_name: &str,
139    ) -> ClientResult<crate::Response<crate::types::GetIpsPoolsPoolNameResponse>> {
140        let url = self.client.url(
141            &format!(
142                "/ips/pools/{}",
143                crate::progenitor_support::encode_path(pool_name),
144            ),
145            None,
146        );
147        self.client
148            .get(
149                &url,
150                crate::Message {
151                    body: None,
152                    content_type: None,
153                },
154            )
155            .await
156    }
157    /**
158     * Rename an IP pool.
159     *
160     * This function performs a `PUT` to the `/ips/pools/{pool_name}` endpoint.
161     *
162     * **This endpoint allows you to update the name of an IP pool.**
163     */
164    pub async fn put_ips_pools_pool_name(
165        &self,
166        pool_name: &str,
167        body: &crate::types::PutIpsPoolsPoolNameRequest,
168    ) -> ClientResult<crate::Response<crate::types::IpPoolsPoolResp>> {
169        let url = self.client.url(
170            &format!(
171                "/ips/pools/{}",
172                crate::progenitor_support::encode_path(pool_name),
173            ),
174            None,
175        );
176        self.client
177            .put(
178                &url,
179                crate::Message {
180                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
181                    content_type: Some("application/json".to_string()),
182                },
183            )
184            .await
185    }
186    /**
187     * Delete an IP pool.
188     *
189     * This function performs a `DELETE` to the `/ips/pools/{pool_name}` endpoint.
190     *
191     * **This endpoint allows you to delete an IP pool.**
192     */
193    pub async fn delete_ips_pools_pool_name(
194        &self,
195        pool_name: &str,
196    ) -> ClientResult<crate::Response<crate::types::Help>> {
197        let url = self.client.url(
198            &format!(
199                "/ips/pools/{}",
200                crate::progenitor_support::encode_path(pool_name),
201            ),
202            None,
203        );
204        self.client
205            .delete(
206                &url,
207                crate::Message {
208                    body: None,
209                    content_type: None,
210                },
211            )
212            .await
213    }
214    /**
215     * Remove an IP address from a pool.
216     *
217     * This function performs a `DELETE` to the `/ips/pools/{pool_name}/ips/{ip}` endpoint.
218     *
219     * **This endpoint allows you to remove an IP address from an IP pool.**
220     */
221    pub async fn delete_ips_pools_pool_name_ip(
222        &self,
223        pool_name: &str,
224        ip: &str,
225    ) -> ClientResult<crate::Response<crate::types::Help>> {
226        let url = self.client.url(
227            &format!(
228                "/ips/pools/{}/ips/{}",
229                crate::progenitor_support::encode_path(pool_name),
230                crate::progenitor_support::encode_path(ip),
231            ),
232            None,
233        );
234        self.client
235            .delete(
236                &url,
237                crate::Message {
238                    body: None,
239                    content_type: None,
240                },
241            )
242            .await
243    }
244}