sendgrid_api/lists.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct Lists {
5 pub client: Client,
6}
7
8impl Lists {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 Lists { client }
12 }
13
14 /**
15 * Get All Lists.
16 *
17 * This function performs a `GET` to the `/marketing/lists` endpoint.
18 *
19 * **This endpoint returns an array of all of your contact lists.**
20 *
21 * **Parameters:**
22 *
23 * * `page_size: f64` -- Maximum number of elements to return. Defaults to 100, returns 1000 max.
24 * * `page_token: &str` -- The license key provided with your New Relic account.
25 */
26 pub async fn get_mc(
27 &self,
28 page_size: f64,
29 page_token: &str,
30 ) -> ClientResult<crate::Response<crate::types::GetMcListsResponse>> {
31 let mut query_args: Vec<(String, String)> = Default::default();
32 if !page_size.to_string().is_empty() {
33 query_args.push(("page_size".to_string(), page_size.to_string()));
34 }
35 if !page_token.is_empty() {
36 query_args.push(("page_token".to_string(), page_token.to_string()));
37 }
38 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
39 let url = self
40 .client
41 .url(&format!("/marketing/lists?{}", query_), None);
42 self.client
43 .get(
44 &url,
45 crate::Message {
46 body: None,
47 content_type: None,
48 },
49 )
50 .await
51 }
52 /**
53 * Create List.
54 *
55 * This function performs a `POST` to the `/marketing/lists` endpoint.
56 *
57 * **This endpoint creates a new contacts list.**
58 *
59 * Once you create a list, you can use the UI to [trigger an automation](https://sendgrid.com/docs/ui/sending-email/getting-started-with-automation/#create-an-automation) every time you add a new contact to the list.
60 *
61 * A link to the newly created object is in `_metadata`.
62 */
63 pub async fn post_mc(
64 &self,
65 body: &crate::types::IpPool,
66 ) -> ClientResult<crate::Response<crate::types::List>> {
67 let url = self.client.url("/marketing/lists", None);
68 self.client
69 .post(
70 &url,
71 crate::Message {
72 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
73 content_type: Some("application/json".to_string()),
74 },
75 )
76 .await
77 }
78 /**
79 * Get List Contact Count.
80 *
81 * This function performs a `GET` to the `/marketing/lists/{id}/contacts/count` endpoint.
82 *
83 * **This endpoint returns the number of contacts on a specific list.**
84 */
85 pub async fn get_mc_contacts_count(
86 &self,
87 id: &str,
88 ) -> ClientResult<crate::Response<crate::types::GetMcListsContactsCountResponse>> {
89 let url = self.client.url(
90 &format!(
91 "/marketing/lists/{}/contacts/count",
92 crate::progenitor_support::encode_path(id),
93 ),
94 None,
95 );
96 self.client
97 .get(
98 &url,
99 crate::Message {
100 body: None,
101 content_type: None,
102 },
103 )
104 .await
105 }
106 /**
107 * Get a List by ID.
108 *
109 * This function performs a `GET` to the `/marketing/lists/{id}` endpoint.
110 *
111 * **This endpoint returns data about a specific list.**
112 *
113 * Setting the optional parameter `contact_sample=true` returns the `contact_sample` in the response body. Up to fifty of the most recent contacts uploaded or attached to a list will be returned, sorted alphabetically, by email address.
114 *
115 * The full contact count is also returned.
116 *
117 * **Parameters:**
118 *
119 * * `contact_sample: bool` -- Indicates if your subuser statistics will be sent to your New Relic Dashboard.
120 */
121 pub async fn get_mc_lists(
122 &self,
123 id: &str,
124 contact_sample: bool,
125 ) -> ClientResult<crate::Response<crate::types::GetMcListsResponseAllOf>> {
126 let mut query_args: Vec<(String, String)> = Default::default();
127 if contact_sample {
128 query_args.push(("contact_sample".to_string(), contact_sample.to_string()));
129 }
130 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
131 let url = self.client.url(
132 &format!(
133 "/marketing/lists/{}?{}",
134 crate::progenitor_support::encode_path(id),
135 query_
136 ),
137 None,
138 );
139 self.client
140 .get(
141 &url,
142 crate::Message {
143 body: None,
144 content_type: None,
145 },
146 )
147 .await
148 }
149 /**
150 * Delete a list.
151 *
152 * This function performs a `DELETE` to the `/marketing/lists/{id}` endpoint.
153 *
154 * **This endpoint allows you to deletes a specific list.**
155 *
156 * Optionally, you can also delete contacts associated to the list. The query parameter, `delete_contacts=true`, will delete the list and start an asynchronous job to delete associated contacts.
157 *
158 * **Parameters:**
159 *
160 * * `delete_contacts: bool` -- Indicates if your subuser statistics will be sent to your New Relic Dashboard.
161 */
162 pub async fn delete(
163 &self,
164 id: &str,
165 delete_contacts: bool,
166 ) -> ClientResult<crate::Response<crate::types::DeleteListsResponse>> {
167 let mut query_args: Vec<(String, String)> = Default::default();
168 if delete_contacts {
169 query_args.push(("delete_contacts".to_string(), delete_contacts.to_string()));
170 }
171 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
172 let url = self.client.url(
173 &format!(
174 "/marketing/lists/{}?{}",
175 crate::progenitor_support::encode_path(id),
176 query_
177 ),
178 None,
179 );
180 self.client
181 .delete(
182 &url,
183 crate::Message {
184 body: None,
185 content_type: None,
186 },
187 )
188 .await
189 }
190 /**
191 * Update List.
192 *
193 * This function performs a `PATCH` to the `/marketing/lists/{id}` endpoint.
194 *
195 * **This endpoint updates the name of a list.**
196 */
197 pub async fn patch_mc(
198 &self,
199 id: &str,
200 body: &crate::types::PatchMcListsRequest,
201 ) -> ClientResult<crate::Response<crate::types::List>> {
202 let url = self.client.url(
203 &format!(
204 "/marketing/lists/{}",
205 crate::progenitor_support::encode_path(id),
206 ),
207 None,
208 );
209 self.client
210 .patch(
211 &url,
212 crate::Message {
213 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
214 content_type: Some("application/json".to_string()),
215 },
216 )
217 .await
218 }
219 /**
220 * Remove Contacts from a List.
221 *
222 * This function performs a `DELETE` to the `/marketing/lists/{id}/contacts` endpoint.
223 *
224 * **This endpoint allows you to remove contacts from a given list.**
225 *
226 * The contacts will not be deleted. Only their list membership will be changed.
227 *
228 * **Parameters:**
229 *
230 * * `contact_ids: &str` -- The license key provided with your New Relic account.
231 */
232 pub async fn delete_mc_contacts(
233 &self,
234 id: &str,
235 contact_ids: &str,
236 ) -> ClientResult<crate::Response<crate::types::DeleteMcListsContactsResponse>> {
237 let mut query_args: Vec<(String, String)> = Default::default();
238 if !contact_ids.is_empty() {
239 query_args.push(("contact_ids".to_string(), contact_ids.to_string()));
240 }
241 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
242 let url = self.client.url(
243 &format!(
244 "/marketing/lists/{}/contacts?{}",
245 crate::progenitor_support::encode_path(id),
246 query_
247 ),
248 None,
249 );
250 self.client
251 .delete(
252 &url,
253 crate::Message {
254 body: None,
255 content_type: None,
256 },
257 )
258 .await
259 }
260}