front_api/
comments.rs

1use anyhow::Result;
2
3use crate::Client;
4#[derive(Clone, Debug)]
5pub struct Comments {
6    pub client: Client,
7}
8
9impl Comments {
10    #[doc(hidden)]
11    pub fn new(client: Client) -> Self {
12        Self { client }
13    }
14
15    #[doc = "List conversation comments\n\nList the comments in a conversation in reverse \
16             chronological order (newest first).\n\n**Parameters:**\n\n- `conversation_id: \
17             &'astr`: The conversation ID (required)\n\n```rust,no_run\nasync fn \
18             example_comments_list_conversation() -> anyhow::Result<()> {\n    let client = \
19             front_api::Client::new_from_env();\n    let result: \
20             front_api::types::ListConversationCommentsResponse =\n        \
21             client.comments().list_conversation(\"some-string\").await?;\n    println!(\"{:?}\", \
22             result);\n    Ok(())\n}\n```"]
23    #[tracing::instrument]
24    pub async fn list_conversation<'a>(
25        &'a self,
26        conversation_id: &'a str,
27    ) -> Result<crate::types::ListConversationCommentsResponse, crate::types::error::Error> {
28        let mut req = self.client.client.request(
29            http::Method::GET,
30            &format!(
31                "{}/{}",
32                self.client.base_url,
33                "conversations/{conversation_id}/comments"
34                    .replace("{conversation_id}", conversation_id)
35            ),
36        );
37        req = req.bearer_auth(&self.client.token);
38        let resp = req.send().await?;
39        let status = resp.status();
40        if status.is_success() {
41            let text = resp.text().await.unwrap_or_default();
42            serde_json::from_str(&text).map_err(|err| {
43                crate::types::error::Error::from_serde_error(
44                    format_serde_error::SerdeError::new(text.to_string(), err),
45                    status,
46                )
47            })
48        } else {
49            Err(crate::types::error::Error::UnexpectedResponse(resp))
50        }
51    }
52
53    #[doc = "Create comment\n\nAdd a comment to a conversation.\n\n**Parameters:**\n\n- `conversation_id: &'astr`: The conversation ID (required)\n\n```rust,no_run\nasync fn example_comments_create() -> anyhow::Result<()> {\n    let client = front_api::Client::new_from_env();\n    let result: front_api::types::CommentResponse = client\n        .comments()\n        .create(\n            \"some-string\",\n            &serde_json::Value::String(\"some-string\".to_string()),\n        )\n        .await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
54    #[tracing::instrument]
55    pub async fn create<'a>(
56        &'a self,
57        conversation_id: &'a str,
58        body: &crate::types::CreateComment,
59    ) -> Result<crate::types::CommentResponse, crate::types::error::Error> {
60        let mut req = self.client.client.request(
61            http::Method::POST,
62            &format!(
63                "{}/{}",
64                self.client.base_url,
65                "conversations/{conversation_id}/comments"
66                    .replace("{conversation_id}", conversation_id)
67            ),
68        );
69        req = req.bearer_auth(&self.client.token);
70        req = req.json(body);
71        let resp = req.send().await?;
72        let status = resp.status();
73        if status.is_success() {
74            let text = resp.text().await.unwrap_or_default();
75            serde_json::from_str(&text).map_err(|err| {
76                crate::types::error::Error::from_serde_error(
77                    format_serde_error::SerdeError::new(text.to_string(), err),
78                    status,
79                )
80            })
81        } else {
82            Err(crate::types::error::Error::UnexpectedResponse(resp))
83        }
84    }
85
86    #[doc = "Get comment\n\nFetches a comment.\n\n**Parameters:**\n\n- `comment_id: &'astr`: The \
87             Comment ID (required)\n\n```rust,no_run\nasync fn example_comments_get() -> \
88             anyhow::Result<()> {\n    let client = front_api::Client::new_from_env();\n    let \
89             result: front_api::types::CommentResponse = \
90             client.comments().get(\"some-string\").await?;\n    println!(\"{:?}\", result);\n    \
91             Ok(())\n}\n```"]
92    #[tracing::instrument]
93    pub async fn get<'a>(
94        &'a self,
95        comment_id: &'a str,
96    ) -> Result<crate::types::CommentResponse, crate::types::error::Error> {
97        let mut req = self.client.client.request(
98            http::Method::GET,
99            &format!(
100                "{}/{}",
101                self.client.base_url,
102                "comments/{comment_id}".replace("{comment_id}", comment_id)
103            ),
104        );
105        req = req.bearer_auth(&self.client.token);
106        let resp = req.send().await?;
107        let status = resp.status();
108        if status.is_success() {
109            let text = resp.text().await.unwrap_or_default();
110            serde_json::from_str(&text).map_err(|err| {
111                crate::types::error::Error::from_serde_error(
112                    format_serde_error::SerdeError::new(text.to_string(), err),
113                    status,
114                )
115            })
116        } else {
117            Err(crate::types::error::Error::UnexpectedResponse(resp))
118        }
119    }
120
121    #[doc = "List comment mentions\n\nList the teammates mentioned in a \
122             comment.\n\n**Parameters:**\n\n- `comment_id: &'astr`: The Comment ID \
123             (required)\n\n```rust,no_run\nasync fn example_comments_list_mentions() -> \
124             anyhow::Result<()> {\n    let client = front_api::Client::new_from_env();\n    let \
125             result: front_api::types::ListCommentMentionsResponse =\n        \
126             client.comments().list_mentions(\"some-string\").await?;\n    println!(\"{:?}\", \
127             result);\n    Ok(())\n}\n```"]
128    #[tracing::instrument]
129    pub async fn list_mentions<'a>(
130        &'a self,
131        comment_id: &'a str,
132    ) -> Result<crate::types::ListCommentMentionsResponse, crate::types::error::Error> {
133        let mut req = self.client.client.request(
134            http::Method::GET,
135            &format!(
136                "{}/{}",
137                self.client.base_url,
138                "comments/{comment_id}/mentions".replace("{comment_id}", comment_id)
139            ),
140        );
141        req = req.bearer_auth(&self.client.token);
142        let resp = req.send().await?;
143        let status = resp.status();
144        if status.is_success() {
145            let text = resp.text().await.unwrap_or_default();
146            serde_json::from_str(&text).map_err(|err| {
147                crate::types::error::Error::from_serde_error(
148                    format_serde_error::SerdeError::new(text.to_string(), err),
149                    status,
150                )
151            })
152        } else {
153            Err(crate::types::error::Error::UnexpectedResponse(resp))
154        }
155    }
156}