sendgrid_api/ip_addresses.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct IpAddresses {
5 pub client: Client,
6}
7
8impl IpAddresses {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 IpAddresses { client }
12 }
13
14 /**
15 * Retrieve all IP addresses.
16 *
17 * This function performs a `GET` to the `/ips` endpoint.
18 *
19 * **This endpoint allows you to retrieve a list of all assigned and unassigned IPs.**
20 *
21 * Response includes warm up status, pools, assigned subusers, and reverse DNS info. The start_date field corresponds to when warmup started for that IP.
22 *
23 * A single IP address or a range of IP addresses may be dedicated to an account in order to send email for multiple domains. The reputation of this IP is based on the aggregate performance of all the senders who use it.
24 *
25 * **Parameters:**
26 *
27 * * `ip: &str` -- The license key provided with your New Relic account.
28 * * `exclude_whitelabels: bool` -- Indicates if your subuser statistics will be sent to your New Relic Dashboard.
29 * * `limit: i64` -- The number of IPs you want returned at the same time.
30 * * `offset: i64` -- The offset for the number of IPs that you are requesting.
31 * * `subuser: &str` -- The license key provided with your New Relic account.
32 * * `sort_by_direction: crate::types::SortByDirection` -- The direction to sort the results.
33 */
34 pub async fn get_ips(
35 &self,
36 ip: &str,
37 exclude_whitelabels: bool,
38 limit: i64,
39 offset: i64,
40 subuser: &str,
41 sort_by_direction: crate::types::SortByDirection,
42 ) -> ClientResult<crate::Response<Vec<crate::types::GetIpsResponse>>> {
43 let mut query_args: Vec<(String, String)> = Default::default();
44 if exclude_whitelabels {
45 query_args.push((
46 "exclude_whitelabels".to_string(),
47 exclude_whitelabels.to_string(),
48 ));
49 }
50 if !ip.is_empty() {
51 query_args.push(("ip".to_string(), ip.to_string()));
52 }
53 if limit > 0 {
54 query_args.push(("limit".to_string(), limit.to_string()));
55 }
56 if offset > 0 {
57 query_args.push(("offset".to_string(), offset.to_string()));
58 }
59 if !sort_by_direction.to_string().is_empty() {
60 query_args.push((
61 "sort_by_direction".to_string(),
62 sort_by_direction.to_string(),
63 ));
64 }
65 if !subuser.is_empty() {
66 query_args.push(("subuser".to_string(), subuser.to_string()));
67 }
68 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
69 let url = self.client.url(&format!("/ips?{}", query_), None);
70 self.client
71 .get(
72 &url,
73 crate::Message {
74 body: None,
75 content_type: None,
76 },
77 )
78 .await
79 }
80 /**
81 * Retrieve all IP addresses.
82 *
83 * This function performs a `GET` to the `/ips` endpoint.
84 *
85 * As opposed to `get_ips`, this function returns all the pages of the request at once.
86 *
87 * **This endpoint allows you to retrieve a list of all assigned and unassigned IPs.**
88 *
89 * Response includes warm up status, pools, assigned subusers, and reverse DNS info. The start_date field corresponds to when warmup started for that IP.
90 *
91 * A single IP address or a range of IP addresses may be dedicated to an account in order to send email for multiple domains. The reputation of this IP is based on the aggregate performance of all the senders who use it.
92 */
93 pub async fn get_all_ips(
94 &self,
95 ip: &str,
96 exclude_whitelabels: bool,
97 offset: i64,
98 subuser: &str,
99 sort_by_direction: crate::types::SortByDirection,
100 ) -> ClientResult<crate::Response<Vec<crate::types::GetIpsResponse>>> {
101 let mut query_args: Vec<(String, String)> = Default::default();
102 if exclude_whitelabels {
103 query_args.push((
104 "exclude_whitelabels".to_string(),
105 exclude_whitelabels.to_string(),
106 ));
107 }
108 if !ip.is_empty() {
109 query_args.push(("ip".to_string(), ip.to_string()));
110 }
111 if offset > 0 {
112 query_args.push(("offset".to_string(), offset.to_string()));
113 }
114 if !sort_by_direction.to_string().is_empty() {
115 query_args.push((
116 "sort_by_direction".to_string(),
117 sort_by_direction.to_string(),
118 ));
119 }
120 if !subuser.is_empty() {
121 query_args.push(("subuser".to_string(), subuser.to_string()));
122 }
123 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
124 let url = self.client.url(&format!("/ips?{}", query_), None);
125 self.client
126 .get_all_pages(
127 &url,
128 crate::Message {
129 body: None,
130 content_type: None,
131 },
132 )
133 .await
134 }
135 /**
136 * Add IPs.
137 *
138 * This function performs a `POST` to the `/ips` endpoint.
139 *
140 * **This endpoint is for adding a(n) IP Address(es) to your account.**
141 */
142 pub async fn post_ip(
143 &self,
144 body: &crate::types::PostIpsRequest,
145 ) -> ClientResult<crate::Response<crate::types::PostIpsResponseData>> {
146 let url = self.client.url("/ips", None);
147 self.client
148 .post(
149 &url,
150 crate::Message {
151 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
152 content_type: Some("application/json".to_string()),
153 },
154 )
155 .await
156 }
157 /**
158 * Get remaining IPs count.
159 *
160 * This function performs a `GET` to the `/ips/remaining` endpoint.
161 *
162 * **This endpoint gets amount of IP Addresses that can still be created during a given period and the price of those IPs.**
163 */
164 pub async fn get_ips_remaining(
165 &self,
166 ) -> ClientResult<crate::Response<crate::types::GetIpsRemainingResponse>> {
167 let url = self.client.url("/ips/remaining", None);
168 self.client
169 .get(
170 &url,
171 crate::Message {
172 body: None,
173 content_type: None,
174 },
175 )
176 .await
177 }
178 /**
179 * Retrieve all assigned IPs.
180 *
181 * This function performs a `GET` to the `/ips/assigned` endpoint.
182 *
183 * **This endpoint allows you to retrieve only assigned IP addresses.**
184 *
185 * A single IP address or a range of IP addresses may be dedicated to an account in order to send email for multiple domains. The reputation of this IP is based on the aggregate performance of all the senders who use it.
186 */
187 pub async fn get_ips_assigned(
188 &self,
189 ) -> ClientResult<crate::Response<Vec<crate::types::GetIpsAssignedResponse>>> {
190 let url = self.client.url("/ips/assigned", None);
191 self.client
192 .get(
193 &url,
194 crate::Message {
195 body: None,
196 content_type: None,
197 },
198 )
199 .await
200 }
201 /**
202 * Retrieve all assigned IPs.
203 *
204 * This function performs a `GET` to the `/ips/assigned` endpoint.
205 *
206 * As opposed to `get_ips_assigned`, this function returns all the pages of the request at once.
207 *
208 * **This endpoint allows you to retrieve only assigned IP addresses.**
209 *
210 * A single IP address or a range of IP addresses may be dedicated to an account in order to send email for multiple domains. The reputation of this IP is based on the aggregate performance of all the senders who use it.
211 */
212 pub async fn get_all_ips_assigned(
213 &self,
214 ) -> ClientResult<crate::Response<Vec<crate::types::GetIpsAssignedResponse>>> {
215 let url = self.client.url("/ips/assigned", None);
216 self.client
217 .get_all_pages(
218 &url,
219 crate::Message {
220 body: None,
221 content_type: None,
222 },
223 )
224 .await
225 }
226 /**
227 * Retrieve all IP pools an IP address belongs to.
228 *
229 * This function performs a `GET` to the `/ips/{ip_address}` endpoint.
230 *
231 * **This endpoint allows you to see which IP pools a particular IP address has been added to.**
232 *
233 * The same IP address can be added to multiple IP pools.
234 *
235 * A single IP address or a range of IP addresses may be dedicated to an account in order to send email for multiple domains. The reputation of this IP is based on the aggregate performance of all the senders who use it.
236 */
237 pub async fn get_ips_ip_address(
238 &self,
239 ip_address: &str,
240 ) -> ClientResult<crate::Response<crate::types::GetIpsIpAddressResponse>> {
241 let url = self.client.url(
242 &format!(
243 "/ips/{}",
244 crate::progenitor_support::encode_path(ip_address),
245 ),
246 None,
247 );
248 self.client
249 .get(
250 &url,
251 crate::Message {
252 body: None,
253 content_type: None,
254 },
255 )
256 .await
257 }
258}