sendgrid_api/
segmenting_contacts.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct SegmentingContacts {
5    pub client: Client,
6}
7
8impl SegmentingContacts {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        SegmentingContacts { client }
12    }
13
14    /**
15     * Get List of Segments.
16     *
17     * This function performs a `GET` to the `/marketing/segments` endpoint.
18     *
19     * **This endpoint allows you to retrieve a list of segments.**
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 of list ids to be used when searching for segments with the specified parent_list_id, no more than 50 is allowed.
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_marketing_segments(
36        &self,
37        parent_list_ids: &str,
38        no_parent_list_id: bool,
39    ) -> ClientResult<crate::Response<crate::types::GetMarketingSegmentsResponse>> {
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?{}", 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` endpoint.
68     *
69     * **This endpoint allows you to create a segment.**
70     */
71    pub async fn post_marketing_segment(
72        &self,
73        body: &crate::types::PostMarketingSegmentsRequestAllOf,
74    ) -> ClientResult<crate::Response<crate::types::FullSegmentAllOf>> {
75        let url = self.client.url("/marketing/segments", None);
76        self.client
77            .post(
78                &url,
79                crate::Message {
80                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
81                    content_type: Some("application/json".to_string()),
82                },
83            )
84            .await
85    }
86    /**
87     * Get Segment by ID.
88     *
89     * This function performs a `GET` to the `/marketing/segments/{segment_id}` endpoint.
90     *
91     * **This endpoint allows you to retrieve a single segment by ID.**
92     *
93     * **Parameters:**
94     *
95     * * `query_json: bool` -- Defaults to `false`.  Set to `true` to return the parsed SQL AST as a JSON object in the field `query_json`.
96     */
97    pub async fn get_marketing_segments_segment(
98        &self,
99        segment_id: &str,
100        query_json: bool,
101    ) -> ClientResult<crate::Response<crate::types::FullSegmentAllOf>> {
102        let mut query_args: Vec<(String, String)> = Default::default();
103        if query_json {
104            query_args.push(("query_json".to_string(), query_json.to_string()));
105        }
106        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
107        let url = self.client.url(
108            &format!(
109                "/marketing/segments/{}?{}",
110                crate::progenitor_support::encode_path(segment_id),
111                query_
112            ),
113            None,
114        );
115        self.client
116            .get(
117                &url,
118                crate::Message {
119                    body: None,
120                    content_type: None,
121                },
122            )
123            .await
124    }
125    /**
126     * Delete Segment.
127     *
128     * This function performs a `DELETE` to the `/marketing/segments/{segment_id}` endpoint.
129     *
130     * **This endpoint allows you to delete a segment by `segment_id`.**
131     *
132     * Note that deleting a segment does not delete the contacts associated with the segment by default. Contacts associated with a deleted segment will remain in your list of all contacts and any other segments they belong to.
133     */
134    pub async fn delete_marketing_segments_segment(
135        &self,
136        segment_id: &str,
137    ) -> ClientResult<crate::Response<crate::types::Help>> {
138        let url = self.client.url(
139            &format!(
140                "/marketing/segments/{}",
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/{segment_id}` endpoint.
159     *
160     * **This endpoint allows you to update a segment.**
161     *
162     * Segment `name` needs to be unique. A user can not update a segment name to an existing one.
163     */
164    pub async fn patch_marketing_segments_segment(
165        &self,
166        segment_id: &str,
167        body: &crate::types::SegmentWriteV2,
168    ) -> ClientResult<crate::Response<crate::types::FullSegmentAllOf>> {
169        let url = self.client.url(
170            &format!(
171                "/marketing/segments/{}",
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: None,
182                },
183            )
184            .await
185    }
186    /**
187     * Bulk Delete Segments.
188     *
189     * This function performs a `POST` to the `/marketing/segments/delete` endpoint.
190     *
191     * This endpoint allows you to delete segments in bulk.
192     *
193     * If the segments are used by automations or the segments do not exist in the database, the segment IDs that could not be deleted along with automation IDs that are associated to those segments will be returned.
194     */
195    pub async fn post_marketing_segments_delete(
196        &self,
197        body: &crate::types::PostMarketingSegmentsDeleteRequest,
198    ) -> ClientResult<crate::Response<crate::types::PostMarketingSegmentsDeleteResponse>> {
199        let url = self.client.url("/marketing/segments/delete", None);
200        self.client
201            .post(
202                &url,
203                crate::Message {
204                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
205                    content_type: Some("application/json".to_string()),
206                },
207            )
208            .await
209    }
210}