sendgrid_api/contacts_api_lists.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct ContactsApiLists {
5 pub client: Client,
6}
7
8impl ContactsApiLists {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 ContactsApiLists { client }
12 }
13
14 /**
15 * Retrieve all lists.
16 *
17 * This function performs a `GET` to the `/contactdb/lists` endpoint.
18 *
19 * **This endpoint allows you to retrieve all of your recipient lists. If you don't have any lists, an empty array will be returned.**
20 *
21 * **Parameters:**
22 *
23 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
24 */
25 pub async fn get_contactdb_lists(
26 &self,
27 ) -> ClientResult<crate::Response<crate::types::ListAllListsResponse>> {
28 let url = self.client.url("/contactdb/lists", None);
29 self.client
30 .get(
31 &url,
32 crate::Message {
33 body: None,
34 content_type: None,
35 },
36 )
37 .await
38 }
39 /**
40 * Create a List.
41 *
42 * This function performs a `POST` to the `/contactdb/lists` endpoint.
43 *
44 * **This endpoint allows you to create a list for your recipients.**
45 *
46 * **Parameters:**
47 *
48 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
49 */
50 pub async fn post_contactdb_list(
51 &self,
52 body: &crate::types::IpPool,
53 ) -> ClientResult<crate::Response<crate::types::ContactdbList>> {
54 let url = self.client.url("/contactdb/lists", None);
55 self.client
56 .post(
57 &url,
58 crate::Message {
59 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
60 content_type: Some("application/json".to_string()),
61 },
62 )
63 .await
64 }
65 /**
66 * Delete Multiple lists.
67 *
68 * This function performs a `DELETE` to the `/contactdb/lists` endpoint.
69 *
70 * **This endpoint allows you to delete multiple recipient lists.**
71 *
72 * **Parameters:**
73 *
74 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
75 */
76 pub async fn delete_contactdb_lists(&self, body: &[i64]) -> ClientResult<crate::Response<()>> {
77 let url = self.client.url("/contactdb/lists", None);
78 self.client
79 .delete(
80 &url,
81 crate::Message {
82 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
83 content_type: Some("application/json".to_string()),
84 },
85 )
86 .await
87 }
88 /**
89 * Retrieve a single list.
90 *
91 * This function performs a `GET` to the `/contactdb/lists/{list_id}` endpoint.
92 *
93 * **This endpoint allows you to retrieve a single recipient list.**
94 *
95 * **Parameters:**
96 *
97 * * `list_id: i64` -- The ID of the list to retrieve.
98 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
99 */
100 pub async fn get_contactdb_lists_list(
101 &self,
102 list_id: &str,
103 ) -> ClientResult<crate::Response<crate::types::ContactdbList>> {
104 let url = self.client.url(
105 &format!(
106 "/contactdb/lists/{}",
107 crate::progenitor_support::encode_path(list_id),
108 ),
109 None,
110 );
111 self.client
112 .get(
113 &url,
114 crate::Message {
115 body: None,
116 content_type: None,
117 },
118 )
119 .await
120 }
121 /**
122 * Delete a List.
123 *
124 * This function performs a `DELETE` to the `/contactdb/lists/{list_id}` endpoint.
125 *
126 * **This endpoint allows you to delete a specific recipient list with the given ID.**
127 *
128 * **Parameters:**
129 *
130 * * `delete_contacts: bool` -- Adds the ability to delete all contacts on the list in addition to deleting the list.
131 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
132 */
133 pub async fn delete_contactdb_lists_list(
134 &self,
135 list_id: &str,
136 delete_contacts: bool,
137 body: &serde_json::Value,
138 ) -> ClientResult<crate::Response<()>> {
139 let mut query_args: Vec<(String, String)> = Default::default();
140 if delete_contacts {
141 query_args.push(("delete_contacts".to_string(), delete_contacts.to_string()));
142 }
143 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
144 let url = self.client.url(
145 &format!(
146 "/contactdb/lists/{}?{}",
147 crate::progenitor_support::encode_path(list_id),
148 query_
149 ),
150 None,
151 );
152 self.client
153 .delete(
154 &url,
155 crate::Message {
156 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
157 content_type: None,
158 },
159 )
160 .await
161 }
162 /**
163 * Update a List.
164 *
165 * This function performs a `PATCH` to the `/contactdb/lists/{list_id}` endpoint.
166 *
167 * **This endpoint allows you to update the name of one of your recipient lists.**
168 *
169 * **Parameters:**
170 *
171 * * `list_id: i64` -- The ID of the list you are updating.
172 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
173 */
174 pub async fn patch_contactdb_lists_list(
175 &self,
176 list_id: &str,
177 body: &crate::types::IpPool,
178 ) -> ClientResult<crate::Response<crate::types::PatchContactdbListsListResponse>> {
179 let url = self.client.url(
180 &format!(
181 "/contactdb/lists/{}",
182 crate::progenitor_support::encode_path(list_id),
183 ),
184 None,
185 );
186 self.client
187 .patch(
188 &url,
189 crate::Message {
190 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
191 content_type: Some("application/json".to_string()),
192 },
193 )
194 .await
195 }
196 /**
197 * Retrieve all recipients on a List.
198 *
199 * This function performs a `GET` to the `/contactdb/lists/{list_id}/recipients` endpoint.
200 *
201 * **This endpoint allows you to retrieve all recipients on the list with the given ID.**
202 *
203 * **Parameters:**
204 *
205 * * `page: i64` -- Page index of first recipient to return (must be a positive integer).
206 * * `page_size: i64` -- Number of recipients to return at a time (must be a positive integer between 1 and 1000).
207 * * `list_id: i64` -- The ID of the list whose recipients you are requesting.
208 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
209 */
210 pub async fn get_contactdb_lists_list_recipients(
211 &self,
212 list_id: i64,
213 page: i64,
214 page_size: i64,
215 ) -> ClientResult<crate::Response<crate::types::GetContactdbRecipientsSearchResponse>> {
216 let mut query_args: Vec<(String, String)> = Default::default();
217 if page > 0 {
218 query_args.push(("page".to_string(), page.to_string()));
219 }
220 if page_size > 0 {
221 query_args.push(("page_size".to_string(), page_size.to_string()));
222 }
223 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
224 let url = self.client.url(
225 &format!(
226 "/contactdb/lists/{}/recipients?{}",
227 crate::progenitor_support::encode_path(&list_id.to_string()),
228 query_
229 ),
230 None,
231 );
232 self.client
233 .get(
234 &url,
235 crate::Message {
236 body: None,
237 content_type: None,
238 },
239 )
240 .await
241 }
242 /**
243 * Add Multiple Recipients to a List.
244 *
245 * This function performs a `POST` to the `/contactdb/lists/{list_id}/recipients` endpoint.
246 *
247 * **This endpoint allows you to add multiple recipients to a list.**
248 *
249 * Adds existing recipients to a list, passing in the recipient IDs to add. Recipient IDs should be passed exactly as they are returned from recipient endpoints.
250 *
251 * **Parameters:**
252 *
253 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
254 */
255 pub async fn post_contactdb_lists_list_recipient(
256 &self,
257 list_id: i64,
258 body: &[i64],
259 ) -> ClientResult<crate::Response<()>> {
260 let url = self.client.url(
261 &format!(
262 "/contactdb/lists/{}/recipients",
263 crate::progenitor_support::encode_path(&list_id.to_string()),
264 ),
265 None,
266 );
267 self.client
268 .post(
269 &url,
270 crate::Message {
271 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
272 content_type: Some("application/json".to_string()),
273 },
274 )
275 .await
276 }
277 /**
278 * Add a Single Recipient to a List.
279 *
280 * This function performs a `POST` to the `/contactdb/lists/{list_id}/recipients/{recipient_id}` endpoint.
281 *
282 * **This endpoint allows you to add a single recipient to a list.**
283 *
284 * **Parameters:**
285 *
286 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
287 */
288 pub async fn post_contactdb_lists_list_recipients_recipient(
289 &self,
290 list_id: i64,
291 recipient_id: &str,
292 ) -> ClientResult<crate::Response<()>> {
293 let url = self.client.url(
294 &format!(
295 "/contactdb/lists/{}/recipients/{}",
296 crate::progenitor_support::encode_path(&list_id.to_string()),
297 crate::progenitor_support::encode_path(recipient_id),
298 ),
299 None,
300 );
301 self.client
302 .post(
303 &url,
304 crate::Message {
305 body: None,
306 content_type: None,
307 },
308 )
309 .await
310 }
311 /**
312 * Delete a Single Recipient from a Single List.
313 *
314 * This function performs a `DELETE` to the `/contactdb/lists/{list_id}/recipients/{recipient_id}` endpoint.
315 *
316 * **This endpoint allows you to delete a single recipient from a list.**
317 *
318 * **Parameters:**
319 *
320 * * `list_id: i64` -- The ID of the list you are taking this recipient away from.
321 * * `recipient_id: i64` -- The ID of the recipient to take off the list.
322 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
323 */
324 pub async fn delete_contactdb_lists_list_recipients_recipient(
325 &self,
326 list_id: i64,
327 recipient_id: &str,
328 body: &serde_json::Value,
329 ) -> ClientResult<crate::Response<()>> {
330 let url = self.client.url(
331 &format!(
332 "/contactdb/lists/{}/recipients/{}",
333 crate::progenitor_support::encode_path(&list_id.to_string()),
334 crate::progenitor_support::encode_path(recipient_id),
335 ),
336 None,
337 );
338 self.client
339 .delete(
340 &url,
341 crate::Message {
342 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
343 content_type: None,
344 },
345 )
346 .await
347 }
348}