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
use anyhow::Result;
use crate::Client;
pub struct DesignsApi {
pub client: Client,
}
impl DesignsApi {
#[doc(hidden)]
pub fn new(client: Client) -> Self {
DesignsApi { client }
}
/**
* Get Design.
*
* This function performs a `GET` to the `/designs/{id}` endpoint.
*
* **This endpoint allows you to retrieve a single design**.
*
* A GET request to `/designs/{id}` will retrieve details about a specific design in your Design Library.
*
* This endpoint is valuable when retrieving information stored in a field that you wish to update using a PATCH request.
*/
pub async fn get_design(&self, id: &str) -> Result<crate::types::DesignOutputAllOf> {
let url = format!("/designs/{}", crate::progenitor_support::encode_path(id),);
self.client.get(&url, None).await
}
/**
* Duplicate Design.
*
* This function performs a `POST` to the `/designs/{id}` endpoint.
*
* **This endpoint allows you to duplicate one of your existing designs**.
*
* Modifying an existing design is often the easiest way to create something new.
*
* 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.
*
* 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.
* More on retrieving design IDs can be found below.
*/
pub async fn post_duplicate_design(
&self,
id: &str,
body: &crate::types::DesignDuplicateInput,
) -> Result<crate::types::DesignOutputAllOf> {
let url = format!("/designs/{}", crate::progenitor_support::encode_path(id),);
self.client
.post(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
.await
}
/**
* Delete Design.
*
* This function performs a `DELETE` to the `/designs/{id}` endpoint.
*
* **This endpoint allows you to delete a single design**.
*
* Be sure to check the ID of the design you intend to delete before making this request; deleting a design is a permanent action.
*/
pub async fn delete_design(&self, id: &str) -> Result<crate::types::Help> {
let url = format!("/designs/{}", crate::progenitor_support::encode_path(id),);
self.client.delete(&url, None).await
}
/**
* Update Design.
*
* This function performs a `PATCH` to the `/designs/{id}` endpoint.
*
* **This endpoint allows you to edit a design**.
*
* 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.
*
* 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.
*
* ```
* {
* "name": "<Updated Name>"
* }
* ```
*/
pub async fn put_design(
&self,
id: &str,
body: &crate::types::PutDesignRequest,
) -> Result<crate::types::DesignOutputAllOf> {
let url = format!("/designs/{}", crate::progenitor_support::encode_path(id),);
self.client
.patch(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
.await
}
/**
* List Designs.
*
* This function performs a `GET` to the `/designs` endpoint.
*
* **This endpoint allows you to retrieve a list of designs already stored in your Design Library**.
*
* 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.
*
* 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.
*
* **Parameters:**
*
* * `page_size: u64` -- number of results to return.
* * `page_token: &str` -- token corresponding to a specific page of results, as provided by metadata.
* * `summary: bool` -- Indicates if your subuser statistics will be sent to your New Relic Dashboard.
*/
pub async fn list_designs(
&self,
page_size: u64,
page_token: &str,
summary: bool,
) -> Result<crate::types::ListDesignsResponse> {
let mut query_args: Vec<(String, String)> = Default::default();
if !page_size.to_string().is_empty() {
query_args.push(("page_size".to_string(), page_size.to_string()));
}
if !page_token.is_empty() {
query_args.push(("page_token".to_string(), page_token.to_string()));
}
if summary {
query_args.push(("summary".to_string(), summary.to_string()));
}
let query_ = serde_urlencoded::to_string(&query_args).unwrap();
let url = format!("/designs?{}", query_);
self.client.get(&url, None).await
}
/**
* Create Design.
*
* This function performs a `POST` to the `/designs` endpoint.
*
* **This endpoint allows you to create a new design**.
*
* 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/).
*
* 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).
*
* 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.
*/
pub async fn post_design(
&self,
body: &crate::types::DesignInputAllOf,
) -> Result<crate::types::DesignOutputAllOf> {
let url = "/designs".to_string();
self.client
.post(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
.await
}
/**
* Get SendGrid Pre-built Design.
*
* This function performs a `GET` to the `/designs/pre-builts/{id}` endpoint.
*
* **This endpoint allows you to retrieve a single pre-built design**.
*
* A GET request to `/designs/pre-builts/{id}` will retrieve details about a specific pre-built design.
*
* This endpoint is valuable when retrieving details about a pre-built design that you wish to duplicate and modify.
*/
pub async fn get_sendgrid_pre_built_design(
&self,
id: &str,
) -> Result<crate::types::DesignOutputAllOf> {
let url = format!(
"/designs/pre-builts/{}",
crate::progenitor_support::encode_path(id),
);
self.client.get(&url, None).await
}
/**
* Duplicate SendGrid Pre-built Design.
*
* This function performs a `POST` to the `/designs/pre-builts/{id}` endpoint.
*
* **This endpoint allows you to duplicate one of the pre-built Twilio SendGrid designs**.
*
* 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.
*
* 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.
* More on retrieving design IDs can be found above.
*/
pub async fn post_sendgrid_pre_built_design(
&self,
id: &str,
body: &crate::types::DesignDuplicateInput,
) -> Result<crate::types::DesignOutputAllOf> {
let url = format!(
"/designs/pre-builts/{}",
crate::progenitor_support::encode_path(id),
);
self.client
.post(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
.await
}
/**
* List SendGrid Pre-built Designs.
*
* This function performs a `GET` to the `/designs/pre-builts` endpoint.
*
* **This endpoint allows you to retrieve a list of pre-built designs provided by Twilio SendGrid**.
*
* 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.
*
* 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.
*
* This endpoint is useful for retrieving the IDs of Twilio SendGrid designs that you want to duplicate and modify.
*
* **Parameters:**
*
* * `page_size: u64` -- number of results to return.
* * `page_token: &str` -- token corresponding to a specific page of results, as provided by metadata.
* * `summary: bool` -- Indicates if your subuser statistics will be sent to your New Relic Dashboard.
*/
pub async fn list_sendgrid_pre_built_designs(
&self,
page_size: u64,
page_token: &str,
summary: bool,
) -> Result<crate::types::ListDesignsResponse> {
let mut query_args: Vec<(String, String)> = Default::default();
if !page_size.to_string().is_empty() {
query_args.push(("page_size".to_string(), page_size.to_string()));
}
if !page_token.is_empty() {
query_args.push(("page_token".to_string(), page_token.to_string()));
}
if summary {
query_args.push(("summary".to_string(), summary.to_string()));
}
let query_ = serde_urlencoded::to_string(&query_args).unwrap();
let url = format!("/designs/pre-builts?{}", query_);
self.client.get(&url, None).await
}
}