sendgrid_api/
link_branding.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct LinkBranding {
5    pub client: Client,
6}
7
8impl LinkBranding {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        LinkBranding { client }
12    }
13
14    /**
15     * Retrieve all branded links.
16     *
17     * This function performs a `GET` to the `/whitelabel/links` endpoint.
18     *
19     * **This endpoint allows you to retrieve all branded links**.
20     *
21     * You can submit this request as one of your subusers if you include their ID in the `on-behalf-of` header in the request.
22     *
23     * **Parameters:**
24     *
25     * * `limit: i64` -- Limits the number of results returned per page.
26     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
27     */
28    pub async fn get_whitelabel_links(
29        &self,
30        limit: i64,
31    ) -> ClientResult<crate::Response<Vec<crate::types::LinkBranding200Response>>> {
32        let mut query_args: Vec<(String, String)> = Default::default();
33        if limit > 0 {
34            query_args.push(("limit".to_string(), limit.to_string()));
35        }
36        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
37        let url = self
38            .client
39            .url(&format!("/whitelabel/links?{}", query_), None);
40        self.client
41            .get(
42                &url,
43                crate::Message {
44                    body: None,
45                    content_type: None,
46                },
47            )
48            .await
49    }
50    /**
51     * Retrieve all branded links.
52     *
53     * This function performs a `GET` to the `/whitelabel/links` endpoint.
54     *
55     * As opposed to `get_whitelabel_links`, this function returns all the pages of the request at once.
56     *
57     * **This endpoint allows you to retrieve all branded links**.
58     *
59     * You can submit this request as one of your subusers if you include their ID in the `on-behalf-of` header in the request.
60     */
61    pub async fn get_all_whitelabel_links(
62        &self,
63    ) -> ClientResult<crate::Response<Vec<crate::types::LinkBranding200Response>>> {
64        let url = self.client.url("/whitelabel/links", 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 branded link.
77     *
78     * This function performs a `POST` to the `/whitelabel/links` endpoint.
79     *
80     * **This endpoint allows you to create a new branded link.**
81     *
82     * To create the link branding, supply the root domain and, optionally, the subdomain — these go into separate fields in your request body. The root domain should match your FROM email address. If you provide a  subdomain, it must be different from the subdomain you used for authenticating your domain.
83     *
84     * You can submit this request as one of your subusers if you include their ID in the `on-behalf-of` header in the request.
85     *
86     * **Parameters:**
87     *
88     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
89     */
90    pub async fn post_whitelabel_link(
91        &self,
92        body: &crate::types::PostWhitelabelLinksRequest,
93    ) -> ClientResult<crate::Response<crate::types::LinkBranding200Response>> {
94        let url = self.client.url("/whitelabel/links", None);
95        self.client
96            .post(
97                &url,
98                crate::Message {
99                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
100                    content_type: Some("application/json".to_string()),
101                },
102            )
103            .await
104    }
105    /**
106     * Validate a branded link.
107     *
108     * This function performs a `POST` to the `/whitelabel/links/{id}/validate` endpoint.
109     *
110     * **This endpoint allows you to validate a branded link.**
111     *
112     * You can submit this request as one of your subusers if you include their ID in the `on-behalf-of` header in the request.
113     *
114     * **Parameters:**
115     *
116     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
117     */
118    pub async fn post_whitelabel_links_validate(
119        &self,
120        id: i64,
121    ) -> ClientResult<crate::Response<crate::types::PostWhitelabelLinksValidateResponse>> {
122        let url = self.client.url(
123            &format!(
124                "/whitelabel/links/{}/validate",
125                crate::progenitor_support::encode_path(&id.to_string()),
126            ),
127            None,
128        );
129        self.client
130            .post(
131                &url,
132                crate::Message {
133                    body: None,
134                    content_type: None,
135                },
136            )
137            .await
138    }
139    /**
140     * Associate a branded link with a subuser.
141     *
142     * This function performs a `POST` to the `/whitelabel/links/{link_id}/subuser` endpoint.
143     *
144     * **This endpoint allows you to associate a branded link with a subuser account.**
145     *
146     * Link branding can be associated with subusers from the parent account. This functionality allows subusers to send mail using their parent's link branding. To associate link branding, the parent account must first create a branded link and validate it. The parent may then associate that branded link with a subuser via the API or the [Subuser Management page of the Twilio SendGrid App](https://app.sendgrid.com/settings/subusers).
147     */
148    pub async fn post_whitelabel_links_link_subuser(
149        &self,
150        link_id: i64,
151        body: &crate::types::PostWhitelabelLinksLinkSubuserRequest,
152    ) -> ClientResult<crate::Response<crate::types::LinkBranding200Response>> {
153        let url = self.client.url(
154            &format!(
155                "/whitelabel/links/{}/subuser",
156                crate::progenitor_support::encode_path(&link_id.to_string()),
157            ),
158            None,
159        );
160        self.client
161            .post(
162                &url,
163                crate::Message {
164                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
165                    content_type: Some("application/json".to_string()),
166                },
167            )
168            .await
169    }
170    /**
171     * Retrieve a branded link.
172     *
173     * This function performs a `GET` to the `/whitelabel/links/{id}` endpoint.
174     *
175     * **This endpoint allows you to retrieve a specific branded link by providing its ID.**
176     *
177     * You can submit this request as one of your subusers if you include their ID in the `on-behalf-of` header in the request.
178     *
179     * **Parameters:**
180     *
181     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
182     */
183    pub async fn get_whitelabel_links_link_branding(
184        &self,
185        id: i64,
186    ) -> ClientResult<crate::Response<crate::types::LinkBranding200Response>> {
187        let url = self.client.url(
188            &format!(
189                "/whitelabel/links/{}",
190                crate::progenitor_support::encode_path(&id.to_string()),
191            ),
192            None,
193        );
194        self.client
195            .get(
196                &url,
197                crate::Message {
198                    body: None,
199                    content_type: None,
200                },
201            )
202            .await
203    }
204    /**
205     * Delete a branded link.
206     *
207     * This function performs a `DELETE` to the `/whitelabel/links/{id}` endpoint.
208     *
209     * **This endpoint allows you to delete a branded link.**
210     *
211     * Your request will receive a response with a 204 status code if the deletion was successful. The call does not return the link's details, so if you wish to record these make sure you call the  "Retrieve a branded link" endpoint *before* you request its deletion.
212     *
213     * You can submit this request as one of your subusers if you include their ID in the `on-behalf-of` header in the request.
214     *
215     * **Parameters:**
216     *
217     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
218     */
219    pub async fn delete_whitelabel_links(
220        &self,
221        id: i64,
222    ) -> ClientResult<crate::Response<crate::types::Help>> {
223        let url = self.client.url(
224            &format!(
225                "/whitelabel/links/{}",
226                crate::progenitor_support::encode_path(&id.to_string()),
227            ),
228            None,
229        );
230        self.client
231            .delete(
232                &url,
233                crate::Message {
234                    body: None,
235                    content_type: None,
236                },
237            )
238            .await
239    }
240    /**
241     * Update a branded link.
242     *
243     * This function performs a `PATCH` to the `/whitelabel/links/{id}` endpoint.
244     *
245     * **This endpoint allows you to update a specific branded link. You can use this endpoint to change a branded link's default status.**
246     *
247     * You can submit this request as one of your subusers if you include their ID in the `on-behalf-of` header in the request.
248     *
249     * **Parameters:**
250     *
251     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
252     */
253    pub async fn patch_whitelabel_links(
254        &self,
255        id: i64,
256        body: &crate::types::PatchWhitelabelLinksRequest,
257    ) -> ClientResult<crate::Response<crate::types::LinkBranding200Response>> {
258        let url = self.client.url(
259            &format!(
260                "/whitelabel/links/{}",
261                crate::progenitor_support::encode_path(&id.to_string()),
262            ),
263            None,
264        );
265        self.client
266            .patch(
267                &url,
268                crate::Message {
269                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
270                    content_type: Some("application/json".to_string()),
271                },
272            )
273            .await
274    }
275    /**
276     * Retrieve the default branded link.
277     *
278     * This function performs a `GET` to the `/whitelabel/links/default` endpoint.
279     *
280     * **This endpoint allows you to retrieve the default branded link.**
281     *
282     * The default branded link is the actual URL to be used when sending messages. If you have more than one branded link, the default is determined by the following order:
283     *
284     * * The validated branded link marked as `default` (set when you call the "Create a branded link" endpoint or by calling the "Update a branded link" endpoint on an existing link)
285     * * Legacy branded links (migrated from the whitelabel wizard)
286     * * Default SendGrid-branded links (i.e., `100.ct.sendgrid.net`)
287     *
288     * You can submit this request as one of your subusers if you include their ID in the `on-behalf-of` header in the request.
289     *
290     * **Parameters:**
291     *
292     * * `domain: &str` -- The domain to match against when finding the default branded link.
293     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
294     */
295    pub async fn get_whitelabel_links_default(
296        &self,
297        domain: &str,
298    ) -> ClientResult<crate::Response<crate::types::LinkBranding200Response>> {
299        let mut query_args: Vec<(String, String)> = Default::default();
300        if !domain.is_empty() {
301            query_args.push(("domain".to_string(), domain.to_string()));
302        }
303        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
304        let url = self
305            .client
306            .url(&format!("/whitelabel/links/default?{}", query_), None);
307        self.client
308            .get(
309                &url,
310                crate::Message {
311                    body: None,
312                    content_type: None,
313                },
314            )
315            .await
316    }
317    /**
318     * Retrieve a subuser's branded link.
319     *
320     * This function performs a `GET` to the `/whitelabel/links/subuser` endpoint.
321     *
322     * **This endpoint allows you to retrieve the branded link associated with a subuser.**
323     *
324     * Link branding can be associated with subusers from the parent account. This functionality allows subusers to send mail using their parent's link branding. To associate link branding, the parent account must first create a branded link and then validate it. The parent may then associate that branded link with a subuser via the API or the [Subuser Management page of the Twilio SendGrid App](https://app.sendgrid.com/settings/subusers).
325     *
326     * **Parameters:**
327     *
328     * * `username: &str` -- The username of the subuser to retrieve associated branded links for.
329     */
330    pub async fn get_whitelabel_links_subuser(
331        &self,
332        username: &str,
333    ) -> ClientResult<crate::Response<crate::types::LinkBranding200Response>> {
334        let mut query_args: Vec<(String, String)> = Default::default();
335        if !username.is_empty() {
336            query_args.push(("username".to_string(), username.to_string()));
337        }
338        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
339        let url = self
340            .client
341            .url(&format!("/whitelabel/links/subuser?{}", query_), None);
342        self.client
343            .get(
344                &url,
345                crate::Message {
346                    body: None,
347                    content_type: None,
348                },
349            )
350            .await
351    }
352    /**
353     * Disassociate a branded link from a subuser.
354     *
355     * This function performs a `DELETE` to the `/whitelabel/links/subuser` endpoint.
356     *
357     * **This endpoint allows you to take a branded link away from a subuser.**
358     *
359     * Link branding can be associated with subusers from the parent account. This functionality allows subusers to send mail using their parent's link branding. To associate link branding, the parent account must first create a branded link and validate it. The parent may then associate that branded link with a subuser via the API or the [Subuser Management page of the Twilio SendGrid App](https://app.sendgrid.com/settings/subusers).
360     *
361     * Your request will receive a response with a 204 status code if the disassociation was successful.
362     *
363     * **Parameters:**
364     *
365     * * `username: &str` -- The username of the subuser account that you want to disassociate a branded link from.
366     */
367    pub async fn delete_whitelabel_links_subuser(
368        &self,
369        username: &str,
370    ) -> ClientResult<crate::Response<crate::types::Help>> {
371        let mut query_args: Vec<(String, String)> = Default::default();
372        if !username.is_empty() {
373            query_args.push(("username".to_string(), username.to_string()));
374        }
375        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
376        let url = self
377            .client
378            .url(&format!("/whitelabel/links/subuser?{}", query_), None);
379        self.client
380            .delete(
381                &url,
382                crate::Message {
383                    body: None,
384                    content_type: None,
385                },
386            )
387            .await
388    }
389}