sendgrid_api/
designs_api.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct DesignsApi {
5    pub client: Client,
6}
7
8impl DesignsApi {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        DesignsApi { client }
12    }
13
14    /**
15     * Get Design.
16     *
17     * This function performs a `GET` to the `/designs/{id}` endpoint.
18     *
19     * **This endpoint allows you to retrieve a single design**.
20     *
21     * A GET request to `/designs/{id}` will retrieve details about a specific design in your Design Library.
22     *
23     * This endpoint is valuable when retrieving information stored in a field that you wish to update using a PATCH request.
24     */
25    pub async fn get_design(
26        &self,
27        id: &str,
28    ) -> ClientResult<crate::Response<crate::types::DesignOutputAllOf>> {
29        let url = self.client.url(
30            &format!("/designs/{}", crate::progenitor_support::encode_path(id),),
31            None,
32        );
33        self.client
34            .get(
35                &url,
36                crate::Message {
37                    body: None,
38                    content_type: None,
39                },
40            )
41            .await
42    }
43    /**
44     * Duplicate Design.
45     *
46     * This function performs a `POST` to the `/designs/{id}` endpoint.
47     *
48     * **This endpoint allows you to duplicate one of your existing designs**.
49     *
50     * Modifying an existing design is often the easiest way to create something new.
51     *
52     * You are not required to pass any data in the body of a request to this endpoint. If you choose to leave the `name` field blank, your duplicate will be assigned the name of the design it was copied from with the text "Duplicate: " prepended to it. This name change is only a convenience, as the duplicate will be assigned a unique ID that differentiates it from your other designs.
53     *
54     * You can modify your duplicate’s name at the time of creation by passing an updated value to the `name` field when making the initial request.
55     * More on retrieving design IDs can be found below.
56     */
57    pub async fn post_duplicate_design(
58        &self,
59        id: &str,
60        body: &crate::types::DesignDuplicateInput,
61    ) -> ClientResult<crate::Response<crate::types::DesignOutputAllOf>> {
62        let url = self.client.url(
63            &format!("/designs/{}", crate::progenitor_support::encode_path(id),),
64            None,
65        );
66        self.client
67            .post(
68                &url,
69                crate::Message {
70                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
71                    content_type: None,
72                },
73            )
74            .await
75    }
76    /**
77     * Delete Design.
78     *
79     * This function performs a `DELETE` to the `/designs/{id}` endpoint.
80     *
81     * **This endpoint allows you to delete a single design**.
82     *
83     * Be sure to check the ID of the design you intend to delete before making this request; deleting a design is a permanent action.
84     */
85    pub async fn delete_design(
86        &self,
87        id: &str,
88    ) -> ClientResult<crate::Response<crate::types::Help>> {
89        let url = self.client.url(
90            &format!("/designs/{}", crate::progenitor_support::encode_path(id),),
91            None,
92        );
93        self.client
94            .delete(
95                &url,
96                crate::Message {
97                    body: None,
98                    content_type: None,
99                },
100            )
101            .await
102    }
103    /**
104     * Update Design.
105     *
106     * This function performs a `PATCH` to the `/designs/{id}` endpoint.
107     *
108     * **This endpoint allows you to edit a design**.
109     *
110     * The Design API supports PATCH requests, which allow you to make partial updates to a single design. Passing data to a specific field will update only the data stored in that field; all other fields will be unaltered.
111     *
112     * For example, updating a design's name requires that you make a PATCH request to this endpoint with data specified for the `name` field only.
113     *
114     * ```
115     * {
116     *     "name": "<Updated Name>"
117     * }
118     * ```
119     */
120    pub async fn put_design(
121        &self,
122        id: &str,
123        body: &crate::types::PutDesignRequest,
124    ) -> ClientResult<crate::Response<crate::types::DesignOutputAllOf>> {
125        let url = self.client.url(
126            &format!("/designs/{}", crate::progenitor_support::encode_path(id),),
127            None,
128        );
129        self.client
130            .patch(
131                &url,
132                crate::Message {
133                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
134                    content_type: Some("application/json".to_string()),
135                },
136            )
137            .await
138    }
139    /**
140     * List Designs.
141     *
142     * This function performs a `GET` to the `/designs` endpoint.
143     *
144     * **This endpoint allows you to retrieve a list of designs already stored in your Design Library**.
145     *
146     * A GET request to `/designs` will return a list of your existing designs. This endpoint will not return the pre-built Twilio SendGrid designs. Pre-built designs can be retrieved using the `/designs/pre-builts` endpoint, which is detailed below.
147     *
148     * By default, you will receive 100 results per request; however, you can modify the number of results returned by passing an integer to the `page_size` query parameter.
149     *
150     * **Parameters:**
151     *
152     * * `page_size: u64` -- number of results to return.
153     * * `page_token: &str` -- token corresponding to a specific page of results, as provided by metadata.
154     * * `summary: bool` -- Indicates if your subuser statistics will be sent to your New Relic Dashboard.
155     */
156    pub async fn list_designs(
157        &self,
158        page_size: u64,
159        page_token: &str,
160        summary: bool,
161    ) -> ClientResult<crate::Response<crate::types::ListDesignsResponse>> {
162        let mut query_args: Vec<(String, String)> = Default::default();
163        if !page_size.to_string().is_empty() {
164            query_args.push(("page_size".to_string(), page_size.to_string()));
165        }
166        if !page_token.is_empty() {
167            query_args.push(("page_token".to_string(), page_token.to_string()));
168        }
169        if summary {
170            query_args.push(("summary".to_string(), summary.to_string()));
171        }
172        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
173        let url = self.client.url(&format!("/designs?{}", query_), None);
174        self.client
175            .get(
176                &url,
177                crate::Message {
178                    body: None,
179                    content_type: None,
180                },
181            )
182            .await
183    }
184    /**
185     * Create Design.
186     *
187     * This function performs a `POST` to the `/designs` endpoint.
188     *
189     * **This endpoint allows you to create a new design**.
190     *
191     * You can add a new design by passing data, including a string of HTML email content, to `/designs`. When creating designs from scratch, be aware of the styling constraints inherent to many email clients. For a list of best practices, see our guide to [Cross-Platform Email Design](https://sendgrid.com/docs/ui/sending-email/cross-platform-html-design/).
192     *
193     * The Design Library can also convert your design’s HTML elements into drag and drop modules that are editable in the Designs Library user interface. For more, visit the [Design and Code Editor documentation](https://sendgrid.com/docs/ui/sending-email/editor/#drag--drop-markup).
194     *
195     * Because the `/designs` endpoint makes it easy to add designs, you can create a design with your preferred tooling or migrate designs you already own without relying on the Design Library UI.
196     */
197    pub async fn post_design(
198        &self,
199        body: &crate::types::DesignInputAllOf,
200    ) -> ClientResult<crate::Response<crate::types::DesignOutputAllOf>> {
201        let url = self.client.url("/designs", None);
202        self.client
203            .post(
204                &url,
205                crate::Message {
206                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
207                    content_type: Some("application/json".to_string()),
208                },
209            )
210            .await
211    }
212    /**
213     * Get SendGrid Pre-built Design.
214     *
215     * This function performs a `GET` to the `/designs/pre-builts/{id}` endpoint.
216     *
217     * **This endpoint allows you to retrieve a single pre-built design**.
218     *
219     * A GET request to `/designs/pre-builts/{id}` will retrieve details about a specific pre-built design.
220     *
221     * This endpoint is valuable when retrieving details about a pre-built design that you wish to duplicate and modify.
222     */
223    pub async fn get_sendgrid_pre_built_design(
224        &self,
225        id: &str,
226    ) -> ClientResult<crate::Response<crate::types::DesignOutputAllOf>> {
227        let url = self.client.url(
228            &format!(
229                "/designs/pre-builts/{}",
230                crate::progenitor_support::encode_path(id),
231            ),
232            None,
233        );
234        self.client
235            .get(
236                &url,
237                crate::Message {
238                    body: None,
239                    content_type: None,
240                },
241            )
242            .await
243    }
244    /**
245     * Duplicate SendGrid Pre-built Design.
246     *
247     * This function performs a `POST` to the `/designs/pre-builts/{id}` endpoint.
248     *
249     * **This endpoint allows you to duplicate one of the pre-built Twilio SendGrid designs**.
250     *
251     * Like duplicating one of your existing designs, you are not required to pass any data in the body of a request to this endpoint. If you choose to leave the `name` field blank, your duplicate will be assigned the name of the design it was copied from with the text "Duplicate: " prepended to it. This name change is only a convenience, as the duplicate design will be assigned a unique ID that differentiates it from your other designs. You can retrieve the IDs for Twilio SendGrid pre-built designs using the "List SendGrid Pre-built Designs" endpoint.
252     *
253     * You can modify your duplicate’s name at the time of creation by passing an updated value to the `name` field when making the initial request.
254     * More on retrieving design IDs can be found above.
255     */
256    pub async fn post_sendgrid_pre_built_design(
257        &self,
258        id: &str,
259        body: &crate::types::DesignDuplicateInput,
260    ) -> ClientResult<crate::Response<crate::types::DesignOutputAllOf>> {
261        let url = self.client.url(
262            &format!(
263                "/designs/pre-builts/{}",
264                crate::progenitor_support::encode_path(id),
265            ),
266            None,
267        );
268        self.client
269            .post(
270                &url,
271                crate::Message {
272                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
273                    content_type: None,
274                },
275            )
276            .await
277    }
278    /**
279     * List SendGrid Pre-built Designs.
280     *
281     * This function performs a `GET` to the `/designs/pre-builts` endpoint.
282     *
283     * **This endpoint allows you to retrieve a list of pre-built designs provided by Twilio SendGrid**.
284     *
285     * Unlike the `/designs` endpoint where *your* designs are stored, a GET request made to `designs/pre-builts` will retrieve a list of the pre-built Twilio SendGrid designs. This endpoint will not return the designs stored in your Design Library.
286     *
287     * By default, you will receive 100 results per request; however, you can modify the number of results returned by passing an integer to the `page_size` query parameter.
288     *
289     * This endpoint is useful for retrieving the IDs of Twilio SendGrid designs that you want to duplicate and modify.
290     *
291     * **Parameters:**
292     *
293     * * `page_size: u64` -- number of results to return.
294     * * `page_token: &str` -- token corresponding to a specific page of results, as provided by metadata.
295     * * `summary: bool` -- Indicates if your subuser statistics will be sent to your New Relic Dashboard.
296     */
297    pub async fn list_sendgrid_pre_built_designs(
298        &self,
299        page_size: u64,
300        page_token: &str,
301        summary: bool,
302    ) -> ClientResult<crate::Response<crate::types::ListDesignsResponse>> {
303        let mut query_args: Vec<(String, String)> = Default::default();
304        if !page_size.to_string().is_empty() {
305            query_args.push(("page_size".to_string(), page_size.to_string()));
306        }
307        if !page_token.is_empty() {
308            query_args.push(("page_token".to_string(), page_token.to_string()));
309        }
310        if summary {
311            query_args.push(("summary".to_string(), summary.to_string()));
312        }
313        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
314        let url = self
315            .client
316            .url(&format!("/designs/pre-builts?{}", query_), None);
317        self.client
318            .get(
319                &url,
320                crate::Message {
321                    body: None,
322                    content_type: None,
323                },
324            )
325            .await
326    }
327}