sendgrid_api/contacts_api_segments.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct ContactsApiSegments {
5 pub client: Client,
6}
7
8impl ContactsApiSegments {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 ContactsApiSegments { client }
12 }
13
14 /**
15 * Retrieve all segments.
16 *
17 * This function performs a `GET` to the `/contactdb/segments` endpoint.
18 *
19 * **This endpoint allows you to retrieve all of your segments.**
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_segments(
26 &self,
27 ) -> ClientResult<crate::Response<crate::types::ListAllSegmentsResponse>> {
28 let url = self.client.url("/contactdb/segments", 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 Segment.
41 *
42 * This function performs a `POST` to the `/contactdb/segments` endpoint.
43 *
44 * **This endpoint allows you to create a new segment.**
45 *
46 *
47 * Valid operators for create and update depend on the type of the field for which you are searching.
48 *
49 * **Dates**
50 * - "eq", "ne", "lt" (before), "gt" (after)
51 * - You may use MM/DD/YYYY for day granularity or an epoch for second granularity.
52 * - "empty", "not_empty"
53 * - "is within"
54 * - You may use an [ISO 8601 date format](https://en.wikipedia.org/wiki/ISO_8601) or the # of days.
55 *
56 * **Text**
57 * - "contains"
58 * - "eq" (is/equals - matches the full field)
59 * - "ne" (is not/not equals - matches any field where the entire field is not the condition value)
60 * - "empty"
61 * - "not_empty"
62 *
63 * **Numbers**
64 * - "eq" (is/equals)
65 * - "lt" (is less than)
66 * - "gt" (is greater than)
67 * - "empty"
68 * - "not_empty"
69 *
70 * **Email Clicks and Opens**
71 * - "eq" (opened)
72 * - "ne" (not opened)
73 *
74 * All field values must be a string.
75 *
76 *
77 * Conditions using "eq" or "ne" for email clicks and opens should provide a "field" of either `clicks.campaign_identifier` or `opens.campaign_identifier`.
78 * The condition value should be a string containing the id of a completed campaign.
79 *
80 *
81 * The conditions list may contain multiple conditions, joined by an "and" or "or" in the "and_or" field.
82 *
83 * The first condition in the conditions list must have an empty "and_or", and subsequent conditions must all specify an "and_or".
84 *
85 * **Parameters:**
86 *
87 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
88 */
89 pub async fn post_contactdb_segment(
90 &self,
91 body: &crate::types::ContactdbSegments,
92 ) -> ClientResult<crate::Response<crate::types::ContactdbSegmentsWithAllOf>> {
93 let url = self.client.url("/contactdb/segments", None);
94 self.client
95 .post(
96 &url,
97 crate::Message {
98 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
99 content_type: Some("application/json".to_string()),
100 },
101 )
102 .await
103 }
104 /**
105 * Retrieve a segment.
106 *
107 * This function performs a `GET` to the `/contactdb/segments/{segment_id}` endpoint.
108 *
109 * **This endpoint allows you to retrieve a single segment with the given ID.**
110 *
111 * **Parameters:**
112 *
113 * * `segment_id: i64` -- The ID of the segment you want to request.
114 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
115 */
116 pub async fn get_contactdb_segments_segment(
117 &self,
118 segment_id: &str,
119 ) -> ClientResult<crate::Response<crate::types::ContactdbSegments>> {
120 let url = self.client.url(
121 &format!(
122 "/contactdb/segments/{}",
123 crate::progenitor_support::encode_path(segment_id),
124 ),
125 None,
126 );
127 self.client
128 .get(
129 &url,
130 crate::Message {
131 body: None,
132 content_type: None,
133 },
134 )
135 .await
136 }
137 /**
138 * Delete a segment.
139 *
140 * This function performs a `DELETE` to the `/contactdb/segments/{segment_id}` endpoint.
141 *
142 * **This endpoint allows you to delete a segment from your recipients database.**
143 *
144 * You also have the option to delete all the contacts from your Marketing Campaigns recipient database who were in this segment.
145 *
146 * **Parameters:**
147 *
148 * * `delete_contacts: bool` -- True to delete all contacts matching the segment in addition to deleting the segment.
149 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
150 */
151 pub async fn delete_contactdb_segments_segment(
152 &self,
153 segment_id: &str,
154 delete_contacts: bool,
155 body: &serde_json::Value,
156 ) -> ClientResult<crate::Response<()>> {
157 let mut query_args: Vec<(String, String)> = Default::default();
158 if delete_contacts {
159 query_args.push(("delete_contacts".to_string(), delete_contacts.to_string()));
160 }
161 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
162 let url = self.client.url(
163 &format!(
164 "/contactdb/segments/{}?{}",
165 crate::progenitor_support::encode_path(segment_id),
166 query_
167 ),
168 None,
169 );
170 self.client
171 .delete(
172 &url,
173 crate::Message {
174 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
175 content_type: None,
176 },
177 )
178 .await
179 }
180 /**
181 * Update a segment.
182 *
183 * This function performs a `PATCH` to the `/contactdb/segments/{segment_id}` endpoint.
184 *
185 * **This endpoint allows you to update a segment.**
186 *
187 * **Parameters:**
188 *
189 * * `segment_id: &str` -- The license key provided with your New Relic account.
190 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
191 */
192 pub async fn patch_contactdb_segments_segment(
193 &self,
194 segment_id: &str,
195 body: &crate::types::PatchContactdbSegmentsSegmentRequest,
196 ) -> ClientResult<crate::Response<crate::types::ContactdbSegments>> {
197 let url = self.client.url(
198 &format!(
199 "/contactdb/segments/{}",
200 crate::progenitor_support::encode_path(segment_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 /**
215 * Retrieve recipients on a segment.
216 *
217 * This function performs a `GET` to the `/contactdb/segments/{segment_id}/recipients` endpoint.
218 *
219 * **This endpoint allows you to retrieve all of the recipients in a segment with the given ID.**
220 *
221 * **Parameters:**
222 *
223 * * `page: i64`
224 * * `page_size: i64`
225 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
226 */
227 pub async fn get_contactdb_segments_segment_recipients(
228 &self,
229 segment_id: i64,
230 page: i64,
231 page_size: i64,
232 ) -> ClientResult<crate::Response<crate::types::ListRecipientsOnASegmentResponse>> {
233 let mut query_args: Vec<(String, String)> = Default::default();
234 if page > 0 {
235 query_args.push(("page".to_string(), page.to_string()));
236 }
237 if page_size > 0 {
238 query_args.push(("page_size".to_string(), page_size.to_string()));
239 }
240 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
241 let url = self.client.url(
242 &format!(
243 "/contactdb/segments/{}/recipients?{}",
244 crate::progenitor_support::encode_path(&segment_id.to_string()),
245 query_
246 ),
247 None,
248 );
249 self.client
250 .get(
251 &url,
252 crate::Message {
253 body: None,
254 content_type: None,
255 },
256 )
257 .await
258 }
259}