1use anyhow::Result;
2
3use crate::Client;
4#[derive(Clone, Debug)]
5pub struct ContactGroups {
6 pub client: Client,
7}
8
9impl ContactGroups {
10 #[doc(hidden)]
11 pub fn new(client: Client) -> Self {
12 Self { client }
13 }
14
15 #[doc = "List groups\n\nList the contact groups.\n\n```rust,no_run\nasync fn \
16 example_contact_groups_list_groups() -> anyhow::Result<()> {\n let client = \
17 front_api::Client::new_from_env();\n let result: \
18 front_api::types::ListGroupsResponse = \
19 client.contact_groups().list_groups().await?;\n println!(\"{:?}\", result);\n \
20 Ok(())\n}\n```"]
21 #[tracing::instrument]
22 pub async fn list_groups<'a>(
23 &'a self,
24 ) -> Result<crate::types::ListGroupsResponse, crate::types::error::Error> {
25 let mut req = self.client.client.request(
26 http::Method::GET,
27 &format!("{}/{}", self.client.base_url, "contact_groups"),
28 );
29 req = req.bearer_auth(&self.client.token);
30 let resp = req.send().await?;
31 let status = resp.status();
32 if status.is_success() {
33 let text = resp.text().await.unwrap_or_default();
34 serde_json::from_str(&text).map_err(|err| {
35 crate::types::error::Error::from_serde_error(
36 format_serde_error::SerdeError::new(text.to_string(), err),
37 status,
38 )
39 })
40 } else {
41 Err(crate::types::error::Error::UnexpectedResponse(resp))
42 }
43 }
44
45 #[doc = "Create group\n\nCreate a new contact group in the default \
46 team.\n\n```rust,no_run\nasync fn example_contact_groups_create_group() -> \
47 anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n \
48 client\n .contact_groups()\n \
49 .create_group(&front_api::types::CreateContactGroup {\n name: \
50 \"some-string\".to_string(),\n })\n .await?;\n Ok(())\n}\n```"]
51 #[tracing::instrument]
52 pub async fn create_group<'a>(
53 &'a self,
54 body: &crate::types::CreateContactGroup,
55 ) -> Result<(), crate::types::error::Error> {
56 let mut req = self.client.client.request(
57 http::Method::POST,
58 &format!("{}/{}", self.client.base_url, "contact_groups"),
59 );
60 req = req.bearer_auth(&self.client.token);
61 req = req.json(body);
62 let resp = req.send().await?;
63 let status = resp.status();
64 if status.is_success() {
65 Ok(())
66 } else {
67 Err(crate::types::error::Error::UnexpectedResponse(resp))
68 }
69 }
70
71 #[doc = "List team groups\n\nList contact groups belonging to the requested \
72 team.\n\n**Parameters:**\n\n- `team_id: &'astr`: The team ID \
73 (required)\n\n```rust,no_run\nasync fn example_contact_groups_list_team_groups() -> \
74 anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n let \
75 result: front_api::types::ListTeamGroupsResponse = client\n \
76 .contact_groups()\n .list_team_groups(\"some-string\")\n .await?;\n \
77 println!(\"{:?}\", result);\n Ok(())\n}\n```"]
78 #[tracing::instrument]
79 pub async fn list_team_groups<'a>(
80 &'a self,
81 team_id: &'a str,
82 ) -> Result<crate::types::ListTeamGroupsResponse, crate::types::error::Error> {
83 let mut req = self.client.client.request(
84 http::Method::GET,
85 &format!(
86 "{}/{}",
87 self.client.base_url,
88 "teams/{team_id}/contact_groups".replace("{team_id}", team_id)
89 ),
90 );
91 req = req.bearer_auth(&self.client.token);
92 let resp = req.send().await?;
93 let status = resp.status();
94 if status.is_success() {
95 let text = resp.text().await.unwrap_or_default();
96 serde_json::from_str(&text).map_err(|err| {
97 crate::types::error::Error::from_serde_error(
98 format_serde_error::SerdeError::new(text.to_string(), err),
99 status,
100 )
101 })
102 } else {
103 Err(crate::types::error::Error::UnexpectedResponse(resp))
104 }
105 }
106
107 #[doc = "Create team group\n\nCreate a new contact group for the requested team.\n\n**Parameters:**\n\n- `team_id: &'astr`: The team ID (required)\n\n```rust,no_run\nasync fn example_contact_groups_create_team_group() -> anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n client\n .contact_groups()\n .create_team_group(\n \"some-string\",\n &front_api::types::CreateContactGroup {\n name: \"some-string\".to_string(),\n },\n )\n .await?;\n Ok(())\n}\n```"]
108 #[tracing::instrument]
109 pub async fn create_team_group<'a>(
110 &'a self,
111 team_id: &'a str,
112 body: &crate::types::CreateContactGroup,
113 ) -> Result<(), crate::types::error::Error> {
114 let mut req = self.client.client.request(
115 http::Method::POST,
116 &format!(
117 "{}/{}",
118 self.client.base_url,
119 "teams/{team_id}/contact_groups".replace("{team_id}", team_id)
120 ),
121 );
122 req = req.bearer_auth(&self.client.token);
123 req = req.json(body);
124 let resp = req.send().await?;
125 let status = resp.status();
126 if status.is_success() {
127 Ok(())
128 } else {
129 Err(crate::types::error::Error::UnexpectedResponse(resp))
130 }
131 }
132
133 #[doc = "List teammate groups\n\nList the contact groups belonging to the requested teammate.\n\n**Parameters:**\n\n- `teammate_id: &'astr`: The teammate ID (required)\n\n```rust,no_run\nasync fn example_contact_groups_list_teammate_groups() -> anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n let result: front_api::types::ListTeammateGroupsResponse = client\n .contact_groups()\n .list_teammate_groups(\"some-string\")\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
134 #[tracing::instrument]
135 pub async fn list_teammate_groups<'a>(
136 &'a self,
137 teammate_id: &'a str,
138 ) -> Result<crate::types::ListTeammateGroupsResponse, crate::types::error::Error> {
139 let mut req = self.client.client.request(
140 http::Method::GET,
141 &format!(
142 "{}/{}",
143 self.client.base_url,
144 "teammates/{teammate_id}/contact_groups".replace("{teammate_id}", teammate_id)
145 ),
146 );
147 req = req.bearer_auth(&self.client.token);
148 let resp = req.send().await?;
149 let status = resp.status();
150 if status.is_success() {
151 let text = resp.text().await.unwrap_or_default();
152 serde_json::from_str(&text).map_err(|err| {
153 crate::types::error::Error::from_serde_error(
154 format_serde_error::SerdeError::new(text.to_string(), err),
155 status,
156 )
157 })
158 } else {
159 Err(crate::types::error::Error::UnexpectedResponse(resp))
160 }
161 }
162
163 #[doc = "Create teammate group\n\nCreate a new contact group for the requested teammate.\n\n**Parameters:**\n\n- `teammate_id: &'astr`: The teammate ID (required)\n\n```rust,no_run\nasync fn example_contact_groups_create_teammate_group() -> anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n client\n .contact_groups()\n .create_teammate_group(\n \"some-string\",\n &front_api::types::CreateContactGroup {\n name: \"some-string\".to_string(),\n },\n )\n .await?;\n Ok(())\n}\n```"]
164 #[tracing::instrument]
165 pub async fn create_teammate_group<'a>(
166 &'a self,
167 teammate_id: &'a str,
168 body: &crate::types::CreateContactGroup,
169 ) -> Result<(), crate::types::error::Error> {
170 let mut req = self.client.client.request(
171 http::Method::POST,
172 &format!(
173 "{}/{}",
174 self.client.base_url,
175 "teammates/{teammate_id}/contact_groups".replace("{teammate_id}", teammate_id)
176 ),
177 );
178 req = req.bearer_auth(&self.client.token);
179 req = req.json(body);
180 let resp = req.send().await?;
181 let status = resp.status();
182 if status.is_success() {
183 Ok(())
184 } else {
185 Err(crate::types::error::Error::UnexpectedResponse(resp))
186 }
187 }
188
189 #[doc = "Delete group\n\nDelete a contact group.\n\n**Parameters:**\n\n- `contact_group_id: \
190 &'astr`: The contact group ID (required)\n\n```rust,no_run\nasync fn \
191 example_contact_groups_delete_group() -> anyhow::Result<()> {\n let client = \
192 front_api::Client::new_from_env();\n \
193 client.contact_groups().delete_group(\"some-string\").await?;\n Ok(())\n}\n```"]
194 #[tracing::instrument]
195 pub async fn delete_group<'a>(
196 &'a self,
197 contact_group_id: &'a str,
198 ) -> Result<(), crate::types::error::Error> {
199 let mut req = self.client.client.request(
200 http::Method::DELETE,
201 &format!(
202 "{}/{}",
203 self.client.base_url,
204 "contact_groups/{contact_group_id}"
205 .replace("{contact_group_id}", contact_group_id)
206 ),
207 );
208 req = req.bearer_auth(&self.client.token);
209 let resp = req.send().await?;
210 let status = resp.status();
211 if status.is_success() {
212 Ok(())
213 } else {
214 Err(crate::types::error::Error::UnexpectedResponse(resp))
215 }
216 }
217
218 #[doc = "List contacts in group\n\nList the contacts belonging to the requested group.\n\n**Parameters:**\n\n- `contact_group_id: &'astr`: The contact group ID (required)\n- `limit: Option<i64>`: Max number of results per page\n- `page_token: Option<String>`: Token to use to request the next page\n\n```rust,no_run\nasync fn example_contact_groups_list_group_contacts() -> anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n let result: front_api::types::ListGroupContactsResponse = client\n .contact_groups()\n .list_group_contacts(\n \"some-string\",\n Some(4 as i64),\n Some(\"some-string\".to_string()),\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
219 #[tracing::instrument]
220 pub async fn list_group_contacts<'a>(
221 &'a self,
222 contact_group_id: &'a str,
223 limit: Option<i64>,
224 page_token: Option<String>,
225 ) -> Result<crate::types::ListGroupContactsResponse, crate::types::error::Error> {
226 let mut req = self.client.client.request(
227 http::Method::GET,
228 &format!(
229 "{}/{}",
230 self.client.base_url,
231 "contact_groups/{contact_group_id}/contacts"
232 .replace("{contact_group_id}", contact_group_id)
233 ),
234 );
235 req = req.bearer_auth(&self.client.token);
236 let mut query_params = Vec::new();
237 if let Some(p) = limit {
238 query_params.push(("limit", format!("{}", p)));
239 }
240
241 if let Some(p) = page_token {
242 query_params.push(("page_token", p));
243 }
244
245 req = req.query(&query_params);
246 let resp = req.send().await?;
247 let status = resp.status();
248 if status.is_success() {
249 let text = resp.text().await.unwrap_or_default();
250 serde_json::from_str(&text).map_err(|err| {
251 crate::types::error::Error::from_serde_error(
252 format_serde_error::SerdeError::new(text.to_string(), err),
253 status,
254 )
255 })
256 } else {
257 Err(crate::types::error::Error::UnexpectedResponse(resp))
258 }
259 }
260
261 #[doc = "Add contacts to group\n\nAdd contacts to the requested group.\n\n**Parameters:**\n\n- `contact_group_id: &'astr`: The contact group ID (required)\n\n```rust,no_run\nasync fn example_contact_groups_add_contacts_to_group() -> anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n client\n .contact_groups()\n .add_contacts_to_group(\n \"some-string\",\n &serde_json::Value::String(\"some-string\".to_string()),\n )\n .await?;\n Ok(())\n}\n```"]
262 #[tracing::instrument]
263 pub async fn add_contacts_to_group<'a>(
264 &'a self,
265 contact_group_id: &'a str,
266 body: &crate::types::AddContactsToGroup,
267 ) -> Result<(), crate::types::error::Error> {
268 let mut req = self.client.client.request(
269 http::Method::POST,
270 &format!(
271 "{}/{}",
272 self.client.base_url,
273 "contact_groups/{contact_group_id}/contacts"
274 .replace("{contact_group_id}", contact_group_id)
275 ),
276 );
277 req = req.bearer_auth(&self.client.token);
278 req = req.json(body);
279 let resp = req.send().await?;
280 let status = resp.status();
281 if status.is_success() {
282 Ok(())
283 } else {
284 Err(crate::types::error::Error::UnexpectedResponse(resp))
285 }
286 }
287}