sendgrid_api/segmenting_contacts_beta.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct SegmentingContactsBeta {
5 pub client: Client,
6}
7
8impl SegmentingContactsBeta {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 SegmentingContactsBeta { client }
12 }
13
14 /**
15 * Get List of Segments.
16 *
17 * This function performs a `GET` to the `/marketing/segments/2.0` endpoint.
18 *
19 * **The Segmentation V2 API is currently in private beta. If you'd like to be added to the beta, please fill out this [form](https://docs.google.com/forms/d/e/1FAIpQLSd5zwC9dRk8lAp1oTWjdGc-aSY69flW_7wnutvKBhpUluSnfQ/viewform)**
20 *
21 * The query param `parent_list_ids` is treated as a filter. Any match will be returned. 0 matches will return a response code of 200 with an empty `results` array.
22 *
23 * `parent_list_ids` | `no_parent_list_id` | `result`
24 * -----------------:|:--------------------:|:-------------
25 * empty | false | all segments
26 * values | false | segments filtered by list_ids
27 * values | true | segments filtered by list_ids and segments with no parent list_ids
28 * empty | true | segments with no parent list_ids
29 *
30 * **Parameters:**
31 *
32 * * `parent_list_ids: &str` -- A comma separated list up to 50 in size, to filter segments on. Only segments that have any of these list ids as the parent list will be retrieved. This is different from the parameter of the same name used when creating a segment.
33 * * `no_parent_list_id: bool` -- If set to `true` segments with an empty value of `parent_list_id` will be returned in the filter. If the value is not present it defaults to 'false'.
34 */
35 pub async fn get_segments(
36 &self,
37 parent_list_ids: &str,
38 no_parent_list_id: bool,
39 ) -> ClientResult<crate::Response<crate::types::AllSegmentsResponse>> {
40 let mut query_args: Vec<(String, String)> = Default::default();
41 if no_parent_list_id {
42 query_args.push((
43 "no_parent_list_id".to_string(),
44 no_parent_list_id.to_string(),
45 ));
46 }
47 if !parent_list_ids.is_empty() {
48 query_args.push(("parent_list_ids".to_string(), parent_list_ids.to_string()));
49 }
50 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
51 let url = self
52 .client
53 .url(&format!("/marketing/segments/2.0?{}", query_), None);
54 self.client
55 .get(
56 &url,
57 crate::Message {
58 body: None,
59 content_type: None,
60 },
61 )
62 .await
63 }
64 /**
65 * Create Segment.
66 *
67 * This function performs a `POST` to the `/marketing/segments/2.0` endpoint.
68 *
69 * **The Segmentation V2 API is currently in private beta. If you'd like to be added to the beta, please fill out this [form](https://docs.google.com/forms/d/e/1FAIpQLSd5zwC9dRk8lAp1oTWjdGc-aSY69flW_7wnutvKBhpUluSnfQ/viewform)**
70 *
71 * Segment `name` has to be unique. A user can not create a new segment with an existing segment name.
72 */
73 pub async fn post_segment(
74 &self,
75 body: &crate::types::SegmentWriteV2,
76 ) -> ClientResult<crate::Response<crate::types::SegmentResponse>> {
77 let url = self.client.url("/marketing/segments/2.0", None);
78 self.client
79 .post(
80 &url,
81 crate::Message {
82 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
83 content_type: None,
84 },
85 )
86 .await
87 }
88 /**
89 * Get Segment by ID.
90 *
91 * This function performs a `GET` to the `/marketing/segments/2.0/{segment_id}` endpoint.
92 *
93 * **The Segmentation V2 API is currently in private beta. If you'd like to be added to the beta, please fill out this [form](https://docs.google.com/forms/d/e/1FAIpQLSd5zwC9dRk8lAp1oTWjdGc-aSY69flW_7wnutvKBhpUluSnfQ/viewform)**
94 *
95 * **Parameters:**
96 *
97 * * `contacts_sample: bool` -- Defaults to `true`. Set to `false` to exclude the contacts_sample in the response.
98 */
99 pub async fn get_segments_segment(
100 &self,
101 segment_id: &str,
102 contacts_sample: bool,
103 ) -> ClientResult<crate::Response<crate::types::SegmentResponse>> {
104 let mut query_args: Vec<(String, String)> = Default::default();
105 if contacts_sample {
106 query_args.push(("contacts_sample".to_string(), contacts_sample.to_string()));
107 }
108 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
109 let url = self.client.url(
110 &format!(
111 "/marketing/segments/2.0/{}?{}",
112 crate::progenitor_support::encode_path(segment_id),
113 query_
114 ),
115 None,
116 );
117 self.client
118 .get(
119 &url,
120 crate::Message {
121 body: None,
122 content_type: None,
123 },
124 )
125 .await
126 }
127 /**
128 * Delete segment.
129 *
130 * This function performs a `DELETE` to the `/marketing/segments/2.0/{segment_id}` endpoint.
131 *
132 * **The Segmentation V2 API is currently in private beta. If you'd like to be added to the beta, please fill out this [form](https://docs.google.com/forms/d/e/1FAIpQLSd5zwC9dRk8lAp1oTWjdGc-aSY69flW_7wnutvKBhpUluSnfQ/viewform)**
133 */
134 pub async fn delete_segments_segment(
135 &self,
136 segment_id: &str,
137 ) -> ClientResult<crate::Response<()>> {
138 let url = self.client.url(
139 &format!(
140 "/marketing/segments/2.0/{}",
141 crate::progenitor_support::encode_path(segment_id),
142 ),
143 None,
144 );
145 self.client
146 .delete(
147 &url,
148 crate::Message {
149 body: None,
150 content_type: None,
151 },
152 )
153 .await
154 }
155 /**
156 * Update Segment.
157 *
158 * This function performs a `PATCH` to the `/marketing/segments/2.0/{segment_id}` endpoint.
159 *
160 * **The Segmentation V2 API is currently in private beta. If you'd like to be added to the beta, please fill out this [form](https://docs.google.com/forms/d/e/1FAIpQLSd5zwC9dRk8lAp1oTWjdGc-aSY69flW_7wnutvKBhpUluSnfQ/viewform)**
161 *
162 * Segment `name` has to be unique. A user can not create a new segment with an existing segment name.
163 */
164 pub async fn patch_segments_segment(
165 &self,
166 segment_id: &str,
167 body: &crate::types::SegmentUpdate,
168 ) -> ClientResult<crate::Response<crate::types::SegmentResponse>> {
169 let url = self.client.url(
170 &format!(
171 "/marketing/segments/2.0/{}",
172 crate::progenitor_support::encode_path(segment_id),
173 ),
174 None,
175 );
176 self.client
177 .patch(
178 &url,
179 crate::Message {
180 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
181 content_type: Some("application/json".to_string()),
182 },
183 )
184 .await
185 }
186}