sendgrid_api/transactional_templates.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct TransactionalTemplates {
5 pub client: Client,
6}
7
8impl TransactionalTemplates {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 TransactionalTemplates { client }
12 }
13
14 /**
15 * Retrieve paged transactional templates.
16 *
17 * This function performs a `GET` to the `/templates` endpoint.
18 *
19 * **This endpoint allows you to retrieve all transactional templates.**
20 *
21 * **Parameters:**
22 *
23 * * `generations: crate::types::Generations` -- Comma-delimited list specifying which generations of templates to return. Options are `legacy`, `dynamic` or `legacy,dynamic`.
24 * * `page_size: f64` -- The number of templates to be returned in each page of results.
25 * * `page_token: &str` -- A token corresponding to a specific page of results, as provided by metadata.
26 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
27 */
28 pub async fn get_templates(
29 &self,
30 generations: crate::types::Generations,
31 page_size: f64,
32 page_token: &str,
33 ) -> ClientResult<crate::Response<crate::types::GetTemplatesResponse>> {
34 let mut query_args: Vec<(String, String)> = Default::default();
35 if !generations.to_string().is_empty() {
36 query_args.push(("generations".to_string(), generations.to_string()));
37 }
38 if !page_size.to_string().is_empty() {
39 query_args.push(("page_size".to_string(), page_size.to_string()));
40 }
41 if !page_token.is_empty() {
42 query_args.push(("page_token".to_string(), page_token.to_string()));
43 }
44 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
45 let url = self.client.url(&format!("/templates?{}", query_), None);
46 self.client
47 .get(
48 &url,
49 crate::Message {
50 body: None,
51 content_type: None,
52 },
53 )
54 .await
55 }
56 /**
57 * Create a transactional template.
58 *
59 * This function performs a `POST` to the `/templates` endpoint.
60 *
61 * **This endpoint allows you to create a transactional template.**
62 *
63 * **Parameters:**
64 *
65 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
66 */
67 pub async fn post_template(
68 &self,
69 body: &crate::types::PostTemplatesRequest,
70 ) -> ClientResult<crate::Response<crate::types::TransactionalTemplateAllOf>> {
71 let url = self.client.url("/templates", None);
72 self.client
73 .post(
74 &url,
75 crate::Message {
76 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
77 content_type: Some("application/json".to_string()),
78 },
79 )
80 .await
81 }
82 /**
83 * Retrieve a single transactional template.
84 *
85 * This function performs a `GET` to the `/templates/{template_id}` endpoint.
86 *
87 * **This endpoint allows you to retrieve a single transactional template.**
88 *
89 * **Parameters:**
90 *
91 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
92 */
93 pub async fn get_templates_template(
94 &self,
95 template_id: &str,
96 ) -> ClientResult<crate::Response<crate::types::TransactionalTemplateAllOf>> {
97 let url = self.client.url(
98 &format!(
99 "/templates/{}",
100 crate::progenitor_support::encode_path(template_id),
101 ),
102 None,
103 );
104 self.client
105 .get(
106 &url,
107 crate::Message {
108 body: None,
109 content_type: None,
110 },
111 )
112 .await
113 }
114 /**
115 * Duplicate a transactional template.
116 *
117 * This function performs a `POST` to the `/templates/{template_id}` endpoint.
118 *
119 * **This endpoint allows you to duplicate a transactional template.**
120 *
121 * **Parameters:**
122 *
123 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
124 */
125 pub async fn post_templates_template(
126 &self,
127 template_id: &str,
128 body: &crate::types::PostTemplatesTemplateRequest,
129 ) -> ClientResult<crate::Response<crate::types::TransactionalTemplateAllOf>> {
130 let url = self.client.url(
131 &format!(
132 "/templates/{}",
133 crate::progenitor_support::encode_path(template_id),
134 ),
135 None,
136 );
137 self.client
138 .post(
139 &url,
140 crate::Message {
141 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
142 content_type: Some("application/json".to_string()),
143 },
144 )
145 .await
146 }
147 /**
148 * Delete a template.
149 *
150 * This function performs a `DELETE` to the `/templates/{template_id}` endpoint.
151 *
152 * **This endpoint allows you to delete a transactional template.**
153 *
154 * **Parameters:**
155 *
156 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
157 */
158 pub async fn delete_templates_template(
159 &self,
160 template_id: &str,
161 ) -> ClientResult<crate::Response<crate::types::Help>> {
162 let url = self.client.url(
163 &format!(
164 "/templates/{}",
165 crate::progenitor_support::encode_path(template_id),
166 ),
167 None,
168 );
169 self.client
170 .delete(
171 &url,
172 crate::Message {
173 body: None,
174 content_type: None,
175 },
176 )
177 .await
178 }
179 /**
180 * Edit a transactional template.
181 *
182 * This function performs a `PATCH` to the `/templates/{template_id}` endpoint.
183 *
184 * **This endpoint allows you to edit the name of a transactional template.**
185 *
186 * To edit the template itself, [create a new transactional template version](https://sendgrid.api-docs.io/v3.0/transactional-templates-versions/create-a-new-transactional-template-version).
187 *
188 * **Parameters:**
189 *
190 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
191 */
192 pub async fn patch_templates_template(
193 &self,
194 template_id: &str,
195 body: &crate::types::PatchTemplatesTemplateRequest,
196 ) -> ClientResult<crate::Response<crate::types::TransactionalTemplateAllOf>> {
197 let url = self.client.url(
198 &format!(
199 "/templates/{}",
200 crate::progenitor_support::encode_path(template_id),
201 ),
202 None,
203 );
204 self.client
205 .patch(
206 &url,
207 crate::Message {
208 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
209 content_type: Some("application/json".to_string()),
210 },
211 )
212 .await
213 }
214}