1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
use anyhow::Result;

use crate::Client;

pub struct LinkBranding {
    pub client: Client,
}

impl LinkBranding {
    #[doc(hidden)]
    pub fn new(client: Client) -> Self {
        LinkBranding { client }
    }

    /**
     * Retrieve all branded links.
     *
     * This function performs a `GET` to the `/whitelabel/links` endpoint.
     *
     * **This endpoint allows you to retrieve all branded links**.
     *
     * You can submit this request as one of your subusers if you include their ID in the `on-behalf-of` header in the request.
     *
     * **Parameters:**
     *
     * * `limit: i64` -- Limits the number of results returned per page.
     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
     */
    pub async fn get_whitelabel_links(
        &self,
        limit: i64,
    ) -> Result<Vec<crate::types::LinkBranding200Response>> {
        let mut query_args: Vec<(String, String)> = Default::default();
        if limit > 0 {
            query_args.push(("limit".to_string(), limit.to_string()));
        }
        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
        let url = format!("/whitelabel/links?{}", query_);

        self.client.get(&url, None).await
    }

    /**
     * Retrieve all branded links.
     *
     * This function performs a `GET` to the `/whitelabel/links` endpoint.
     *
     * As opposed to `get_whitelabel_links`, this function returns all the pages of the request at once.
     *
     * **This endpoint allows you to retrieve all branded links**.
     *
     * You can submit this request as one of your subusers if you include their ID in the `on-behalf-of` header in the request.
     */
    pub async fn get_all_whitelabel_links(
        &self,
    ) -> Result<Vec<crate::types::LinkBranding200Response>> {
        let url = "/whitelabel/links".to_string();
        self.client.get_all_pages(&url, None).await
    }

    /**
     * Create a branded link.
     *
     * This function performs a `POST` to the `/whitelabel/links` endpoint.
     *
     * **This endpoint allows you to create a new branded link.**
     *
     * 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.
     *
     * You can submit this request as one of your subusers if you include their ID in the `on-behalf-of` header in the request.
     *
     * **Parameters:**
     *
     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
     */
    pub async fn post_whitelabel_link(
        &self,
        body: &crate::types::PostWhitelabelLinksRequest,
    ) -> Result<crate::types::LinkBranding200Response> {
        let url = "/whitelabel/links".to_string();
        self.client
            .post(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
            .await
    }

    /**
     * Validate a branded link.
     *
     * This function performs a `POST` to the `/whitelabel/links/{id}/validate` endpoint.
     *
     * **This endpoint allows you to validate a branded link.**
     *
     * You can submit this request as one of your subusers if you include their ID in the `on-behalf-of` header in the request.
     *
     * **Parameters:**
     *
     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
     */
    pub async fn post_whitelabel_links_validate(
        &self,
        id: i64,
    ) -> Result<crate::types::PostWhitelabelLinksValidateResponse> {
        let url = format!(
            "/whitelabel/links/{}/validate",
            crate::progenitor_support::encode_path(&id.to_string()),
        );

        self.client.post(&url, None).await
    }

    /**
     * Associate a branded link with a subuser.
     *
     * This function performs a `POST` to the `/whitelabel/links/{link_id}/subuser` endpoint.
     *
     * **This endpoint allows you to associate a branded link with a subuser account.**
     *
     * 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).
     */
    pub async fn post_whitelabel_links_link_subuser(
        &self,
        link_id: i64,
        body: &crate::types::PostWhitelabelLinksLinkSubuserRequest,
    ) -> Result<crate::types::LinkBranding200Response> {
        let url = format!(
            "/whitelabel/links/{}/subuser",
            crate::progenitor_support::encode_path(&link_id.to_string()),
        );

        self.client
            .post(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
            .await
    }

    /**
     * Retrieve a branded link.
     *
     * This function performs a `GET` to the `/whitelabel/links/{id}` endpoint.
     *
     * **This endpoint allows you to retrieve a specific branded link by providing its ID.**
     *
     * You can submit this request as one of your subusers if you include their ID in the `on-behalf-of` header in the request.
     *
     * **Parameters:**
     *
     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
     */
    pub async fn get_whitelabel_links_link_branding(
        &self,
        id: i64,
    ) -> Result<crate::types::LinkBranding200Response> {
        let url = format!(
            "/whitelabel/links/{}",
            crate::progenitor_support::encode_path(&id.to_string()),
        );

        self.client.get(&url, None).await
    }

    /**
     * Delete a branded link.
     *
     * This function performs a `DELETE` to the `/whitelabel/links/{id}` endpoint.
     *
     * **This endpoint allows you to delete a branded link.**
     *
     * 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.
     *
     * You can submit this request as one of your subusers if you include their ID in the `on-behalf-of` header in the request.
     *
     * **Parameters:**
     *
     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
     */
    pub async fn delete_whitelabel_links(&self, id: i64) -> Result<crate::types::Help> {
        let url = format!(
            "/whitelabel/links/{}",
            crate::progenitor_support::encode_path(&id.to_string()),
        );

        self.client.delete(&url, None).await
    }

    /**
     * Update a branded link.
     *
     * This function performs a `PATCH` to the `/whitelabel/links/{id}` endpoint.
     *
     * **This endpoint allows you to update a specific branded link. You can use this endpoint to change a branded link's default status.**
     *
     * You can submit this request as one of your subusers if you include their ID in the `on-behalf-of` header in the request.
     *
     * **Parameters:**
     *
     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
     */
    pub async fn patch_whitelabel_links(
        &self,
        id: i64,
        body: &crate::types::PatchWhitelabelLinksRequest,
    ) -> Result<crate::types::LinkBranding200Response> {
        let url = format!(
            "/whitelabel/links/{}",
            crate::progenitor_support::encode_path(&id.to_string()),
        );

        self.client
            .patch(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
            .await
    }

    /**
     * Retrieve the default branded link.
     *
     * This function performs a `GET` to the `/whitelabel/links/default` endpoint.
     *
     * **This endpoint allows you to retrieve the default branded link.**
     *
     * 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:
     *
     * * 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)
     * * Legacy branded links (migrated from the whitelabel wizard)
     * * Default SendGrid-branded links (i.e., `100.ct.sendgrid.net`)
     *
     * You can submit this request as one of your subusers if you include their ID in the `on-behalf-of` header in the request.
     *
     * **Parameters:**
     *
     * * `domain: &str` -- The domain to match against when finding the default branded link.
     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
     */
    pub async fn get_whitelabel_links_default(
        &self,
        domain: &str,
    ) -> Result<crate::types::LinkBranding200Response> {
        let mut query_args: Vec<(String, String)> = Default::default();
        if !domain.is_empty() {
            query_args.push(("domain".to_string(), domain.to_string()));
        }
        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
        let url = format!("/whitelabel/links/default?{}", query_);

        self.client.get(&url, None).await
    }

    /**
     * Retrieve a subuser's branded link.
     *
     * This function performs a `GET` to the `/whitelabel/links/subuser` endpoint.
     *
     * **This endpoint allows you to retrieve the branded link associated with a subuser.**
     *
     * 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).
     *
     * **Parameters:**
     *
     * * `username: &str` -- The username of the subuser to retrieve associated branded links for.
     */
    pub async fn get_whitelabel_links_subuser(
        &self,
        username: &str,
    ) -> Result<crate::types::LinkBranding200Response> {
        let mut query_args: Vec<(String, String)> = Default::default();
        if !username.is_empty() {
            query_args.push(("username".to_string(), username.to_string()));
        }
        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
        let url = format!("/whitelabel/links/subuser?{}", query_);

        self.client.get(&url, None).await
    }

    /**
     * Disassociate a branded link from a subuser.
     *
     * This function performs a `DELETE` to the `/whitelabel/links/subuser` endpoint.
     *
     * **This endpoint allows you to take a branded link away from a subuser.**
     *
     * 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).
     *
     * Your request will receive a response with a 204 status code if the disassociation was successful.
     *
     * **Parameters:**
     *
     * * `username: &str` -- The username of the subuser account that you want to disassociate a branded link from.
     */
    pub async fn delete_whitelabel_links_subuser(
        &self,
        username: &str,
    ) -> Result<crate::types::Help> {
        let mut query_args: Vec<(String, String)> = Default::default();
        if !username.is_empty() {
            query_args.push(("username".to_string(), username.to_string()));
        }
        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
        let url = format!("/whitelabel/links/subuser?{}", query_);

        self.client.delete(&url, None).await
    }
}