sendgrid_api/
domain_authentication.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct DomainAuthentication {
5    pub client: Client,
6}
7
8impl DomainAuthentication {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        DomainAuthentication { client }
12    }
13
14    /**
15     * List all authenticated domains.
16     *
17     * This function performs a `GET` to the `/whitelabel/domains` endpoint.
18     *
19     * **This endpoint allows you to retrieve a list of all domains you have authenticated.**
20     *
21     * **Parameters:**
22     *
23     * * `limit: i64` -- Number of domains to return.
24     * * `offset: i64` -- Paging offset.
25     * * `exclude_subusers: bool` -- Indicates if your subuser statistics will be sent to your New Relic Dashboard.
26     * * `username: &str` -- The license key provided with your New Relic account.
27     * * `domain: &str` -- The license key provided with your New Relic account.
28     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
29     */
30    pub async fn get_whitelabel_domains(
31        &self,
32        limit: i64,
33        offset: i64,
34        exclude_subusers: bool,
35        username: &str,
36        domain: &str,
37    ) -> ClientResult<crate::Response<Vec<crate::types::DomainAuthentication200ResponseAllOf>>>
38    {
39        let mut query_args: Vec<(String, String)> = Default::default();
40        if !domain.is_empty() {
41            query_args.push(("domain".to_string(), domain.to_string()));
42        }
43        if exclude_subusers {
44            query_args.push(("exclude_subusers".to_string(), exclude_subusers.to_string()));
45        }
46        if limit > 0 {
47            query_args.push(("limit".to_string(), limit.to_string()));
48        }
49        if offset > 0 {
50            query_args.push(("offset".to_string(), offset.to_string()));
51        }
52        if !username.is_empty() {
53            query_args.push(("username".to_string(), username.to_string()));
54        }
55        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
56        let url = self
57            .client
58            .url(&format!("/whitelabel/domains?{}", query_), None);
59        self.client
60            .get(
61                &url,
62                crate::Message {
63                    body: None,
64                    content_type: None,
65                },
66            )
67            .await
68    }
69    /**
70     * List all authenticated domains.
71     *
72     * This function performs a `GET` to the `/whitelabel/domains` endpoint.
73     *
74     * As opposed to `get_whitelabel_domains`, this function returns all the pages of the request at once.
75     *
76     * **This endpoint allows you to retrieve a list of all domains you have authenticated.**
77     */
78    pub async fn get_all_whitelabel_domains(
79        &self,
80        offset: i64,
81        exclude_subusers: bool,
82        username: &str,
83        domain: &str,
84    ) -> ClientResult<crate::Response<Vec<crate::types::DomainAuthentication200ResponseAllOf>>>
85    {
86        let mut query_args: Vec<(String, String)> = Default::default();
87        if !domain.is_empty() {
88            query_args.push(("domain".to_string(), domain.to_string()));
89        }
90        if exclude_subusers {
91            query_args.push(("exclude_subusers".to_string(), exclude_subusers.to_string()));
92        }
93        if offset > 0 {
94            query_args.push(("offset".to_string(), offset.to_string()));
95        }
96        if !username.is_empty() {
97            query_args.push(("username".to_string(), username.to_string()));
98        }
99        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
100        let url = self
101            .client
102            .url(&format!("/whitelabel/domains?{}", query_), None);
103        self.client
104            .get_all_pages(
105                &url,
106                crate::Message {
107                    body: None,
108                    content_type: None,
109                },
110            )
111            .await
112    }
113    /**
114     * Authenticate a domain.
115     *
116     * This function performs a `POST` to the `/whitelabel/domains` endpoint.
117     *
118     * **This endpoint allows you to authenticate a domain.**
119     *
120     * If you are authenticating a domain for a subuser, you have two options:
121     * 1. Use the "username" parameter. This allows you to authenticate a domain on behalf of your subuser. This means the subuser is able to see and modify the authenticated domain.
122     * 2. Use the Association workflow (see Associate Domain section). This allows you to authenticate a domain created by the parent to a subuser. This means the subuser will default to the assigned domain, but will not be able to see or modify that authenticated domain. However, if the subuser authenticates their own domain it will overwrite the assigned domain.
123     *
124     * **Parameters:**
125     *
126     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
127     */
128    pub async fn post_whitelabel_domain(
129        &self,
130        body: &crate::types::PostWhitelabelDomainsRequest,
131    ) -> ClientResult<crate::Response<crate::types::AuthenticationDomain>> {
132        let url = self.client.url("/whitelabel/domains", None);
133        self.client
134            .post(
135                &url,
136                crate::Message {
137                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
138                    content_type: Some("application/json".to_string()),
139                },
140            )
141            .await
142    }
143    /**
144     * Retrieve an authenticated domain.
145     *
146     * This function performs a `GET` to the `/whitelabel/domains/{domain_id}` endpoint.
147     *
148     * **This endpoint allows you to retrieve a specific authenticated domain.**
149     *
150     * **Parameters:**
151     *
152     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
153     */
154    pub async fn get_whitelabel_domains_domain(
155        &self,
156        domain_id: &str,
157    ) -> ClientResult<crate::Response<crate::types::AuthenticationDomain>> {
158        let url = self.client.url(
159            &format!(
160                "/whitelabel/domains/{}",
161                crate::progenitor_support::encode_path(domain_id),
162            ),
163            None,
164        );
165        self.client
166            .get(
167                &url,
168                crate::Message {
169                    body: None,
170                    content_type: None,
171                },
172            )
173            .await
174    }
175    /**
176     * Delete an authenticated domain.
177     *
178     * This function performs a `DELETE` to the `/whitelabel/domains/{domain_id}` endpoint.
179     *
180     * **This endpoint allows you to delete an authenticated domain.**
181     *
182     * **Parameters:**
183     *
184     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
185     */
186    pub async fn delete_whitelabel_domains_domain(
187        &self,
188        domain_id: &str,
189    ) -> ClientResult<crate::Response<crate::types::Help>> {
190        let url = self.client.url(
191            &format!(
192                "/whitelabel/domains/{}",
193                crate::progenitor_support::encode_path(domain_id),
194            ),
195            None,
196        );
197        self.client
198            .delete(
199                &url,
200                crate::Message {
201                    body: None,
202                    content_type: None,
203                },
204            )
205            .await
206    }
207    /**
208     * Update an authenticated domain.
209     *
210     * This function performs a `PATCH` to the `/whitelabel/domains/{domain_id}` endpoint.
211     *
212     * **This endpoint allows you to update the settings for an authenticated domain.**
213     *
214     * **Parameters:**
215     *
216     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
217     */
218    pub async fn patch_whitelabel_domains_domain(
219        &self,
220        domain_id: &str,
221        body: &crate::types::PatchWhitelabelDomainsDomainRequest,
222    ) -> ClientResult<crate::Response<Vec<crate::types::DomainAuthentication200ResponseAllOf>>>
223    {
224        let url = self.client.url(
225            &format!(
226                "/whitelabel/domains/{}",
227                crate::progenitor_support::encode_path(domain_id),
228            ),
229            None,
230        );
231        self.client
232            .patch(
233                &url,
234                crate::Message {
235                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
236                    content_type: Some("application/json".to_string()),
237                },
238            )
239            .await
240    }
241    /**
242     * Get the default authentication.
243     *
244     * This function performs a `GET` to the `/whitelabel/domains/default` endpoint.
245     *
246     * **This endpoint allows you to retrieve the default authentication for a domain.**
247     *
248     * When creating or updating a domain authentication, you can set the domain as a default. The default domain will be used to send all mail. If you have multiple authenticated domains, the authenticated domain matching the domain of the From address will be used, and the default will be overridden.
249     *
250     * This endpoint will return a default domain and its details only if a default is set. You are not required to set a default. If you do not set a default domain, this endpoint will return general information about your domain authentication status.
251     *
252     * **Parameters:**
253     *
254     * * `domain: &str` -- The license key provided with your New Relic account.
255     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
256     */
257    pub async fn get_whitelabel_domains_default(
258        &self,
259        domain: &str,
260    ) -> ClientResult<crate::Response<Vec<crate::types::DomainAuthentication200ResponseAllOf>>>
261    {
262        let mut query_args: Vec<(String, String)> = Default::default();
263        if !domain.is_empty() {
264            query_args.push(("domain".to_string(), domain.to_string()));
265        }
266        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
267        let url = self
268            .client
269            .url(&format!("/whitelabel/domains/default?{}", query_), None);
270        self.client
271            .get(
272                &url,
273                crate::Message {
274                    body: None,
275                    content_type: None,
276                },
277            )
278            .await
279    }
280    /**
281     * Get the default authentication.
282     *
283     * This function performs a `GET` to the `/whitelabel/domains/default` endpoint.
284     *
285     * As opposed to `get_whitelabel_domains_default`, this function returns all the pages of the request at once.
286     *
287     * **This endpoint allows you to retrieve the default authentication for a domain.**
288     *
289     * When creating or updating a domain authentication, you can set the domain as a default. The default domain will be used to send all mail. If you have multiple authenticated domains, the authenticated domain matching the domain of the From address will be used, and the default will be overridden.
290     *
291     * This endpoint will return a default domain and its details only if a default is set. You are not required to set a default. If you do not set a default domain, this endpoint will return general information about your domain authentication status.
292     */
293    pub async fn get_all_whitelabel_domains_default(
294        &self,
295        domain: &str,
296    ) -> ClientResult<crate::Response<Vec<crate::types::DomainAuthentication200ResponseAllOf>>>
297    {
298        let mut query_args: Vec<(String, String)> = Default::default();
299        if !domain.is_empty() {
300            query_args.push(("domain".to_string(), domain.to_string()));
301        }
302        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
303        let url = self
304            .client
305            .url(&format!("/whitelabel/domains/default?{}", query_), None);
306        self.client
307            .get_all_pages(
308                &url,
309                crate::Message {
310                    body: None,
311                    content_type: None,
312                },
313            )
314            .await
315    }
316    /**
317     * Add an IP to an authenticated domain.
318     *
319     * This function performs a `POST` to the `/whitelabel/domains/{id}/ips` endpoint.
320     *
321     * **This endpoint allows you to add an IP address to an authenticated domain.**
322     *
323     * **Parameters:**
324     *
325     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
326     */
327    pub async fn post_whitelabel_domains_ip(
328        &self,
329        id: i64,
330        body: &crate::types::Ips,
331    ) -> ClientResult<crate::Response<crate::types::DomainAuthentication>> {
332        let url = self.client.url(
333            &format!(
334                "/whitelabel/domains/{}/ips",
335                crate::progenitor_support::encode_path(&id.to_string()),
336            ),
337            None,
338        );
339        self.client
340            .post(
341                &url,
342                crate::Message {
343                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
344                    content_type: Some("application/json".to_string()),
345                },
346            )
347            .await
348    }
349    /**
350     * Remove an IP from an authenticated domain.
351     *
352     * This function performs a `DELETE` to the `/whitelabel/domains/{id}/ips/{ip}` endpoint.
353     *
354     * **This endpoint allows you to remove an IP address from that domain's authentication.**
355     *
356     * **Parameters:**
357     *
358     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
359     */
360    pub async fn delete_whitelabel_domains_ips_ip(
361        &self,
362        id: i64,
363        ip: &str,
364    ) -> ClientResult<crate::Response<crate::types::DomainAuthentication>> {
365        let url = self.client.url(
366            &format!(
367                "/whitelabel/domains/{}/ips/{}",
368                crate::progenitor_support::encode_path(&id.to_string()),
369                crate::progenitor_support::encode_path(ip),
370            ),
371            None,
372        );
373        self.client
374            .delete(
375                &url,
376                crate::Message {
377                    body: None,
378                    content_type: None,
379                },
380            )
381            .await
382    }
383    /**
384     * Validate a domain authentication.
385     *
386     * This function performs a `POST` to the `/whitelabel/domains/{id}/validate` endpoint.
387     *
388     * **This endpoint allows you to validate an authenticated domain. If it fails, it will return an error message describing why the domain could not be validated.**
389     *
390     * **Parameters:**
391     *
392     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
393     */
394    pub async fn post_whitelabel_domains_validate(
395        &self,
396        id: i64,
397    ) -> ClientResult<crate::Response<crate::types::PostWhitelabelDomainsValidateResponse>> {
398        let url = self.client.url(
399            &format!(
400                "/whitelabel/domains/{}/validate",
401                crate::progenitor_support::encode_path(&id.to_string()),
402            ),
403            None,
404        );
405        self.client
406            .post(
407                &url,
408                crate::Message {
409                    body: None,
410                    content_type: None,
411                },
412            )
413            .await
414    }
415    /**
416     * List the authenticated domain associated with the given user.
417     *
418     * This function performs a `GET` to the `/whitelabel/domains/subuser` endpoint.
419     *
420     * **This endpoint allows you to retrieve all of the authenticated domains that have been assigned to a specific subuser.**
421     *
422     * Authenticated domains can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's domain authentication. To associate a authenticated domain with a subuser, the parent account must first authenticate and validate the domain. The the parent may then associate the authenticated domain via the subuser management tools.
423     *
424     * **Parameters:**
425     *
426     * * `username: &str` -- Username for the subuser to find associated authenticated domain.
427     */
428    pub async fn get_whitelabel_domains_subuser(
429        &self,
430        username: &str,
431    ) -> ClientResult<crate::Response<crate::types::DomainAuthentication>> {
432        let mut query_args: Vec<(String, String)> = Default::default();
433        if !username.is_empty() {
434            query_args.push(("username".to_string(), username.to_string()));
435        }
436        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
437        let url = self
438            .client
439            .url(&format!("/whitelabel/domains/subuser?{}", query_), None);
440        self.client
441            .get(
442                &url,
443                crate::Message {
444                    body: None,
445                    content_type: None,
446                },
447            )
448            .await
449    }
450    /**
451     * Disassociate an authenticated domain from a given user.
452     *
453     * This function performs a `DELETE` to the `/whitelabel/domains/subuser` endpoint.
454     *
455     * **This endpoint allows you to disassociate a specific authenticated domain from a subuser.**
456     *
457     * Authenticated domains can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's domain authentication. To associate a authenticated domain with a subuser, the parent account must first authenticate and validate the domain. The the parent may then associate the authenticated domain via the subuser management tools.
458     *
459     * **Parameters:**
460     *
461     * * `username: &str` -- Username for the subuser to find associated authenticated domain.
462     */
463    pub async fn delete_whitelabel_domains_subuser(
464        &self,
465        username: &str,
466    ) -> ClientResult<crate::Response<crate::types::Help>> {
467        let mut query_args: Vec<(String, String)> = Default::default();
468        if !username.is_empty() {
469            query_args.push(("username".to_string(), username.to_string()));
470        }
471        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
472        let url = self
473            .client
474            .url(&format!("/whitelabel/domains/subuser?{}", query_), None);
475        self.client
476            .delete(
477                &url,
478                crate::Message {
479                    body: None,
480                    content_type: None,
481                },
482            )
483            .await
484    }
485    /**
486     * Associate a authenticated domain with a given user.
487     *
488     * This function performs a `POST` to the `/whitelabel/domains/{domain_id}/subuser` endpoint.
489     *
490     * **This endpoint allows you to associate a specific authenticated domain with a subuser.**
491     *
492     * Authenticated domains can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's domain authentication. To associate a authenticated domain with a subuser, the parent account must first authenticate and validate the domain. The the parent may then associate the authenticated domain via the subuser management tools.
493     */
494    pub async fn post_whitelabel_domains_domain_subuser(
495        &self,
496        domain_id: i64,
497        body: &crate::types::PutUserUsernameResponse,
498    ) -> ClientResult<crate::Response<crate::types::DomainAuthentication>> {
499        let url = self.client.url(
500            &format!(
501                "/whitelabel/domains/{}/subuser",
502                crate::progenitor_support::encode_path(&domain_id.to_string()),
503            ),
504            None,
505        );
506        self.client
507            .post(
508                &url,
509                crate::Message {
510                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
511                    content_type: Some("application/json".to_string()),
512                },
513            )
514            .await
515    }
516}