1use anyhow::Result;
2
3use crate::Client;
4#[derive(Clone, Debug)]
5pub struct Tags {
6 pub client: Client,
7}
8
9impl Tags {
10 #[doc(hidden)]
11 pub fn new(client: Client) -> Self {
12 Self { client }
13 }
14
15 #[doc = "List tags\n\nList the tags of the company.\n\n```rust,no_run\nasync fn \
16 example_tags_list() -> anyhow::Result<()> {\n let client = \
17 front_api::Client::new_from_env();\n let result: \
18 front_api::types::ListTagsResponse = client.tags().list().await?;\n \
19 println!(\"{:?}\", result);\n Ok(())\n}\n```"]
20 #[tracing::instrument]
21 pub async fn list<'a>(
22 &'a self,
23 ) -> Result<crate::types::ListTagsResponse, crate::types::error::Error> {
24 let mut req = self.client.client.request(
25 http::Method::GET,
26 &format!("{}/{}", self.client.base_url, "tags"),
27 );
28 req = req.bearer_auth(&self.client.token);
29 let resp = req.send().await?;
30 let status = resp.status();
31 if status.is_success() {
32 let text = resp.text().await.unwrap_or_default();
33 serde_json::from_str(&text).map_err(|err| {
34 crate::types::error::Error::from_serde_error(
35 format_serde_error::SerdeError::new(text.to_string(), err),
36 status,
37 )
38 })
39 } else {
40 Err(crate::types::error::Error::UnexpectedResponse(resp))
41 }
42 }
43
44 #[doc = "Create tag\n\nCreate a tag.\n\n```rust,no_run\nasync fn example_tags_create() -> \
45 anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n let \
46 result: front_api::types::TagResponse = client\n .tags()\n \
47 .create(&front_api::types::CreateTag {\n name: \
48 \"some-string\".to_string(),\n highlight: \
49 Some(front_api::types::Highlight::Orange),\n \
50 is_visible_in_conversation_lists: Some(false),\n })\n .await?;\n \
51 println!(\"{:?}\", result);\n Ok(())\n}\n```"]
52 #[tracing::instrument]
53 pub async fn create<'a>(
54 &'a self,
55 body: &crate::types::CreateTag,
56 ) -> Result<crate::types::TagResponse, crate::types::error::Error> {
57 let mut req = self.client.client.request(
58 http::Method::POST,
59 &format!("{}/{}", self.client.base_url, "tags"),
60 );
61 req = req.bearer_auth(&self.client.token);
62 req = req.json(body);
63 let resp = req.send().await?;
64 let status = resp.status();
65 if status.is_success() {
66 let text = resp.text().await.unwrap_or_default();
67 serde_json::from_str(&text).map_err(|err| {
68 crate::types::error::Error::from_serde_error(
69 format_serde_error::SerdeError::new(text.to_string(), err),
70 status,
71 )
72 })
73 } else {
74 Err(crate::types::error::Error::UnexpectedResponse(resp))
75 }
76 }
77
78 #[doc = "List team tags\n\nList the tags for a team.\n\n**Parameters:**\n\n- `team_id: &'astr`: The team ID (required)\n\n```rust,no_run\nasync fn example_tags_list_team() -> anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n let result: front_api::types::ListTeamTagsResponse = client.tags().list_team(\"some-string\").await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
79 #[tracing::instrument]
80 pub async fn list_team<'a>(
81 &'a self,
82 team_id: &'a str,
83 ) -> Result<crate::types::ListTeamTagsResponse, crate::types::error::Error> {
84 let mut req = self.client.client.request(
85 http::Method::GET,
86 &format!(
87 "{}/{}",
88 self.client.base_url,
89 "teams/{team_id}/tags".replace("{team_id}", team_id)
90 ),
91 );
92 req = req.bearer_auth(&self.client.token);
93 let resp = req.send().await?;
94 let status = resp.status();
95 if status.is_success() {
96 let text = resp.text().await.unwrap_or_default();
97 serde_json::from_str(&text).map_err(|err| {
98 crate::types::error::Error::from_serde_error(
99 format_serde_error::SerdeError::new(text.to_string(), err),
100 status,
101 )
102 })
103 } else {
104 Err(crate::types::error::Error::UnexpectedResponse(resp))
105 }
106 }
107
108 #[doc = "Create team tag\n\nCreate a tag for a team.\n\n**Parameters:**\n\n- `team_id: &'astr`: The team ID (required)\n\n```rust,no_run\nasync fn example_tags_create_team() -> anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n let result: front_api::types::TagResponse = client\n .tags()\n .create_team(\n \"some-string\",\n &front_api::types::CreateTag {\n name: \"some-string\".to_string(),\n highlight: Some(front_api::types::Highlight::LightBlue),\n is_visible_in_conversation_lists: Some(false),\n },\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
109 #[tracing::instrument]
110 pub async fn create_team<'a>(
111 &'a self,
112 team_id: &'a str,
113 body: &crate::types::CreateTag,
114 ) -> Result<crate::types::TagResponse, crate::types::error::Error> {
115 let mut req = self.client.client.request(
116 http::Method::POST,
117 &format!(
118 "{}/{}",
119 self.client.base_url,
120 "teams/{team_id}/tags".replace("{team_id}", team_id)
121 ),
122 );
123 req = req.bearer_auth(&self.client.token);
124 req = req.json(body);
125 let resp = req.send().await?;
126 let status = resp.status();
127 if status.is_success() {
128 let text = resp.text().await.unwrap_or_default();
129 serde_json::from_str(&text).map_err(|err| {
130 crate::types::error::Error::from_serde_error(
131 format_serde_error::SerdeError::new(text.to_string(), err),
132 status,
133 )
134 })
135 } else {
136 Err(crate::types::error::Error::UnexpectedResponse(resp))
137 }
138 }
139
140 #[doc = "List teammate tags\n\nList the tags for a teammate.\n\n**Parameters:**\n\n- \
141 `teammate_id: &'astr`: The teammate ID (required)\n\n```rust,no_run\nasync fn \
142 example_tags_list_teammate() -> anyhow::Result<()> {\n let client = \
143 front_api::Client::new_from_env();\n let result: \
144 front_api::types::ListTeammateTagsResponse =\n \
145 client.tags().list_teammate(\"some-string\").await?;\n println!(\"{:?}\", \
146 result);\n Ok(())\n}\n```"]
147 #[tracing::instrument]
148 pub async fn list_teammate<'a>(
149 &'a self,
150 teammate_id: &'a str,
151 ) -> Result<crate::types::ListTeammateTagsResponse, crate::types::error::Error> {
152 let mut req = self.client.client.request(
153 http::Method::GET,
154 &format!(
155 "{}/{}",
156 self.client.base_url,
157 "teammates/{teammate_id}/tags".replace("{teammate_id}", teammate_id)
158 ),
159 );
160 req = req.bearer_auth(&self.client.token);
161 let resp = req.send().await?;
162 let status = resp.status();
163 if status.is_success() {
164 let text = resp.text().await.unwrap_or_default();
165 serde_json::from_str(&text).map_err(|err| {
166 crate::types::error::Error::from_serde_error(
167 format_serde_error::SerdeError::new(text.to_string(), err),
168 status,
169 )
170 })
171 } else {
172 Err(crate::types::error::Error::UnexpectedResponse(resp))
173 }
174 }
175
176 #[doc = "Create teammate tag\n\nCreate a tag for a teammate.\n\n**Parameters:**\n\n- `teammate_id: &'astr`: The teammate ID (required)\n\n```rust,no_run\nasync fn example_tags_create_teammate() -> anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n let result: front_api::types::TagResponse = client\n .tags()\n .create_teammate(\n \"some-string\",\n &front_api::types::CreateTag {\n name: \"some-string\".to_string(),\n highlight: Some(front_api::types::Highlight::Orange),\n is_visible_in_conversation_lists: Some(false),\n },\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
177 #[tracing::instrument]
178 pub async fn create_teammate<'a>(
179 &'a self,
180 teammate_id: &'a str,
181 body: &crate::types::CreateTag,
182 ) -> Result<crate::types::TagResponse, crate::types::error::Error> {
183 let mut req = self.client.client.request(
184 http::Method::POST,
185 &format!(
186 "{}/{}",
187 self.client.base_url,
188 "teammates/{teammate_id}/tags".replace("{teammate_id}", teammate_id)
189 ),
190 );
191 req = req.bearer_auth(&self.client.token);
192 req = req.json(body);
193 let resp = req.send().await?;
194 let status = resp.status();
195 if status.is_success() {
196 let text = resp.text().await.unwrap_or_default();
197 serde_json::from_str(&text).map_err(|err| {
198 crate::types::error::Error::from_serde_error(
199 format_serde_error::SerdeError::new(text.to_string(), err),
200 status,
201 )
202 })
203 } else {
204 Err(crate::types::error::Error::UnexpectedResponse(resp))
205 }
206 }
207
208 #[doc = "List tag children\n\nList the children of a specific tag.\n\n**Parameters:**\n\n- \
209 `tag_id: &'astr`: The tag ID (required)\n\n```rust,no_run\nasync fn \
210 example_tags_list_children() -> anyhow::Result<()> {\n let client = \
211 front_api::Client::new_from_env();\n let result: \
212 front_api::types::ListTagChildrenResponse =\n \
213 client.tags().list_children(\"some-string\").await?;\n println!(\"{:?}\", \
214 result);\n Ok(())\n}\n```"]
215 #[tracing::instrument]
216 pub async fn list_children<'a>(
217 &'a self,
218 tag_id: &'a str,
219 ) -> Result<crate::types::ListTagChildrenResponse, crate::types::error::Error> {
220 let mut req = self.client.client.request(
221 http::Method::GET,
222 &format!(
223 "{}/{}",
224 self.client.base_url,
225 "tags/{tag_id}/children".replace("{tag_id}", tag_id)
226 ),
227 );
228 req = req.bearer_auth(&self.client.token);
229 let resp = req.send().await?;
230 let status = resp.status();
231 if status.is_success() {
232 let text = resp.text().await.unwrap_or_default();
233 serde_json::from_str(&text).map_err(|err| {
234 crate::types::error::Error::from_serde_error(
235 format_serde_error::SerdeError::new(text.to_string(), err),
236 status,
237 )
238 })
239 } else {
240 Err(crate::types::error::Error::UnexpectedResponse(resp))
241 }
242 }
243
244 #[doc = "Create child tag\n\nCreates a child tag.\n\n**Parameters:**\n\n- `tag_id: &'astr`: The tag ID (required)\n\n```rust,no_run\nasync fn example_tags_create_child() -> anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n let result: front_api::types::TagResponse = client\n .tags()\n .create_child(\n \"some-string\",\n &front_api::types::CreateTag {\n name: \"some-string\".to_string(),\n highlight: Some(front_api::types::Highlight::Grey),\n is_visible_in_conversation_lists: Some(true),\n },\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
245 #[tracing::instrument]
246 pub async fn create_child<'a>(
247 &'a self,
248 tag_id: &'a str,
249 body: &crate::types::CreateTag,
250 ) -> Result<crate::types::TagResponse, crate::types::error::Error> {
251 let mut req = self.client.client.request(
252 http::Method::POST,
253 &format!(
254 "{}/{}",
255 self.client.base_url,
256 "tags/{tag_id}/children".replace("{tag_id}", tag_id)
257 ),
258 );
259 req = req.bearer_auth(&self.client.token);
260 req = req.json(body);
261 let resp = req.send().await?;
262 let status = resp.status();
263 if status.is_success() {
264 let text = resp.text().await.unwrap_or_default();
265 serde_json::from_str(&text).map_err(|err| {
266 crate::types::error::Error::from_serde_error(
267 format_serde_error::SerdeError::new(text.to_string(), err),
268 status,
269 )
270 })
271 } else {
272 Err(crate::types::error::Error::UnexpectedResponse(resp))
273 }
274 }
275
276 #[doc = "Get tag\n\nFetche a tag.\n\n**Parameters:**\n\n- `tag_id: &'astr`: The tag ID (required)\n\n```rust,no_run\nasync fn example_tags_get() -> anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n let result: front_api::types::TagResponse = client.tags().get(\"some-string\").await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
277 #[tracing::instrument]
278 pub async fn get<'a>(
279 &'a self,
280 tag_id: &'a str,
281 ) -> Result<crate::types::TagResponse, crate::types::error::Error> {
282 let mut req = self.client.client.request(
283 http::Method::GET,
284 &format!(
285 "{}/{}",
286 self.client.base_url,
287 "tags/{tag_id}".replace("{tag_id}", tag_id)
288 ),
289 );
290 req = req.bearer_auth(&self.client.token);
291 let resp = req.send().await?;
292 let status = resp.status();
293 if status.is_success() {
294 let text = resp.text().await.unwrap_or_default();
295 serde_json::from_str(&text).map_err(|err| {
296 crate::types::error::Error::from_serde_error(
297 format_serde_error::SerdeError::new(text.to_string(), err),
298 status,
299 )
300 })
301 } else {
302 Err(crate::types::error::Error::UnexpectedResponse(resp))
303 }
304 }
305
306 #[doc = "Delete tag\n\nDelete a tag.\n\n**Parameters:**\n\n- `tag_id: &'astr`: The ID of the \
307 tag to delete (required)\n\n```rust,no_run\nasync fn example_tags_delete() -> \
308 anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n \
309 client.tags().delete(\"some-string\").await?;\n Ok(())\n}\n```"]
310 #[tracing::instrument]
311 pub async fn delete<'a>(&'a self, tag_id: &'a str) -> Result<(), crate::types::error::Error> {
312 let mut req = self.client.client.request(
313 http::Method::DELETE,
314 &format!(
315 "{}/{}",
316 self.client.base_url,
317 "tags/{tag_id}".replace("{tag_id}", tag_id)
318 ),
319 );
320 req = req.bearer_auth(&self.client.token);
321 let resp = req.send().await?;
322 let status = resp.status();
323 if status.is_success() {
324 Ok(())
325 } else {
326 Err(crate::types::error::Error::UnexpectedResponse(resp))
327 }
328 }
329
330 #[doc = "Update a tag\n\nUpdate a tag.\n\n**Parameters:**\n\n- `tag_id: &'astr`: The tag ID (required)\n\n```rust,no_run\nasync fn example_tags_update() -> anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n client\n .tags()\n .update(\n \"some-string\",\n &serde_json::Value::String(\"some-string\".to_string()),\n )\n .await?;\n Ok(())\n}\n```"]
331 #[tracing::instrument]
332 pub async fn update<'a>(
333 &'a self,
334 tag_id: &'a str,
335 body: &crate::types::UpdateTag,
336 ) -> Result<(), crate::types::error::Error> {
337 let mut req = self.client.client.request(
338 http::Method::PATCH,
339 &format!(
340 "{}/{}",
341 self.client.base_url,
342 "tags/{tag_id}".replace("{tag_id}", tag_id)
343 ),
344 );
345 req = req.bearer_auth(&self.client.token);
346 req = req.json(body);
347 let resp = req.send().await?;
348 let status = resp.status();
349 if status.is_success() {
350 Ok(())
351 } else {
352 Err(crate::types::error::Error::UnexpectedResponse(resp))
353 }
354 }
355
356 #[doc = "List tagged conversations\n\nList the conversations tagged with a tag. For more advanced filtering, see the [search endpoint](https://dev.frontapp.com/reference/conversations#search-conversations).\n> ⚠\u{fe0f} Deprecated field included\n>\n> This endpoint returns a deprecated `last_message` field in the top-level conversation bodies listed. Please use the\n> `_links.related.last_message` field instead.\n\n\n**Parameters:**\n\n- `limit: Option<i64>`: Max number of results per page\n- `page_token: Option<String>`: Token to use to request the next page\n- `q: Option<String>`: Search query object with a property `statuses`, whose value should be a list of conversation statuses (`assigned`, `unassigned`, `archived`, or `deleted`).\n- `tag_id: &'astr`: The ID of the tag (required)\n\n```rust,no_run\nasync fn example_tags_list_tagged_conversations() -> anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n let result: front_api::types::ListTaggedConversationsResponse = client\n .tags()\n .list_tagged_conversations(\n Some(4 as i64),\n Some(\"some-string\".to_string()),\n Some(\"some-string\".to_string()),\n \"some-string\",\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
357 #[tracing::instrument]
358 pub async fn list_tagged_conversations<'a>(
359 &'a self,
360 limit: Option<i64>,
361 page_token: Option<String>,
362 q: Option<String>,
363 tag_id: &'a str,
364 ) -> Result<crate::types::ListTaggedConversationsResponse, crate::types::error::Error> {
365 let mut req = self.client.client.request(
366 http::Method::GET,
367 &format!(
368 "{}/{}",
369 self.client.base_url,
370 "tags/{tag_id}/conversations".replace("{tag_id}", tag_id)
371 ),
372 );
373 req = req.bearer_auth(&self.client.token);
374 let mut query_params = Vec::new();
375 if let Some(p) = limit {
376 query_params.push(("limit", format!("{}", p)));
377 }
378
379 if let Some(p) = page_token {
380 query_params.push(("page_token", p));
381 }
382
383 if let Some(p) = q {
384 query_params.push(("q", p));
385 }
386
387 req = req.query(&query_params);
388 let resp = req.send().await?;
389 let status = resp.status();
390 if status.is_success() {
391 let text = resp.text().await.unwrap_or_default();
392 serde_json::from_str(&text).map_err(|err| {
393 crate::types::error::Error::from_serde_error(
394 format_serde_error::SerdeError::new(text.to_string(), err),
395 status,
396 )
397 })
398 } else {
399 Err(crate::types::error::Error::UnexpectedResponse(resp))
400 }
401 }
402}