langfuse_client_base/apis/
comments_api.rs1use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum CommentsCreateError {
20 Status400(serde_json::Value),
21 Status401(serde_json::Value),
22 Status403(serde_json::Value),
23 Status404(serde_json::Value),
24 Status405(serde_json::Value),
25 UnknownValue(serde_json::Value),
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum CommentsGetError {
32 Status400(serde_json::Value),
33 Status401(serde_json::Value),
34 Status403(serde_json::Value),
35 Status404(serde_json::Value),
36 Status405(serde_json::Value),
37 UnknownValue(serde_json::Value),
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum CommentsGetByIdError {
44 Status400(serde_json::Value),
45 Status401(serde_json::Value),
46 Status403(serde_json::Value),
47 Status404(serde_json::Value),
48 Status405(serde_json::Value),
49 UnknownValue(serde_json::Value),
50}
51
52#[bon::builder]
54pub async fn comments_create(
55 configuration: &configuration::Configuration,
56 create_comment_request: models::CreateCommentRequest,
57) -> Result<models::CreateCommentResponse, Error<CommentsCreateError>> {
58 let p_body_create_comment_request = create_comment_request;
60
61 let uri_str = format!("{}/api/public/comments", configuration.base_path);
62 let mut req_builder = configuration
63 .client
64 .request(reqwest::Method::POST, &uri_str);
65
66 if let Some(ref user_agent) = configuration.user_agent {
67 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
68 }
69 if let Some(ref auth_conf) = configuration.basic_auth {
70 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
71 };
72 req_builder = req_builder.json(&p_body_create_comment_request);
73
74 let req = req_builder.build()?;
75 let resp = configuration.client.execute(req).await?;
76
77 let status = resp.status();
78 let content_type = resp
79 .headers()
80 .get("content-type")
81 .and_then(|v| v.to_str().ok())
82 .unwrap_or("application/octet-stream");
83 let content_type = super::ContentType::from(content_type);
84
85 if !status.is_client_error() && !status.is_server_error() {
86 let content = resp.text().await?;
87 match content_type {
88 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
89 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateCommentResponse`"))),
90 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::CreateCommentResponse`")))),
91 }
92 } else {
93 let content = resp.text().await?;
94 let entity: Option<CommentsCreateError> = serde_json::from_str(&content).ok();
95 Err(Error::ResponseError(ResponseContent {
96 status,
97 content,
98 entity,
99 }))
100 }
101}
102
103#[bon::builder]
105pub async fn comments_get(
106 configuration: &configuration::Configuration,
107 page: Option<i32>,
108 limit: Option<i32>,
109 object_type: Option<&str>,
110 object_id: Option<&str>,
111 author_user_id: Option<&str>,
112) -> Result<models::GetCommentsResponse, Error<CommentsGetError>> {
113 let p_query_page = page;
115 let p_query_limit = limit;
116 let p_query_object_type = object_type;
117 let p_query_object_id = object_id;
118 let p_query_author_user_id = author_user_id;
119
120 let uri_str = format!("{}/api/public/comments", configuration.base_path);
121 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
122
123 if let Some(ref param_value) = p_query_page {
124 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
125 }
126 if let Some(ref param_value) = p_query_limit {
127 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
128 }
129 if let Some(ref param_value) = p_query_object_type {
130 req_builder = req_builder.query(&[("objectType", ¶m_value.to_string())]);
131 }
132 if let Some(ref param_value) = p_query_object_id {
133 req_builder = req_builder.query(&[("objectId", ¶m_value.to_string())]);
134 }
135 if let Some(ref param_value) = p_query_author_user_id {
136 req_builder = req_builder.query(&[("authorUserId", ¶m_value.to_string())]);
137 }
138 if let Some(ref user_agent) = configuration.user_agent {
139 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
140 }
141 if let Some(ref auth_conf) = configuration.basic_auth {
142 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
143 };
144
145 let req = req_builder.build()?;
146 let resp = configuration.client.execute(req).await?;
147
148 let status = resp.status();
149 let content_type = resp
150 .headers()
151 .get("content-type")
152 .and_then(|v| v.to_str().ok())
153 .unwrap_or("application/octet-stream");
154 let content_type = super::ContentType::from(content_type);
155
156 if !status.is_client_error() && !status.is_server_error() {
157 let content = resp.text().await?;
158 match content_type {
159 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
160 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetCommentsResponse`"))),
161 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetCommentsResponse`")))),
162 }
163 } else {
164 let content = resp.text().await?;
165 let entity: Option<CommentsGetError> = serde_json::from_str(&content).ok();
166 Err(Error::ResponseError(ResponseContent {
167 status,
168 content,
169 entity,
170 }))
171 }
172}
173
174#[bon::builder]
176pub async fn comments_get_by_id(
177 configuration: &configuration::Configuration,
178 comment_id: &str,
179) -> Result<models::Comment, Error<CommentsGetByIdError>> {
180 let p_path_comment_id = comment_id;
182
183 let uri_str = format!(
184 "{}/api/public/comments/{commentId}",
185 configuration.base_path,
186 commentId = crate::apis::urlencode(p_path_comment_id)
187 );
188 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
189
190 if let Some(ref user_agent) = configuration.user_agent {
191 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
192 }
193 if let Some(ref auth_conf) = configuration.basic_auth {
194 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
195 };
196
197 let req = req_builder.build()?;
198 let resp = configuration.client.execute(req).await?;
199
200 let status = resp.status();
201 let content_type = resp
202 .headers()
203 .get("content-type")
204 .and_then(|v| v.to_str().ok())
205 .unwrap_or("application/octet-stream");
206 let content_type = super::ContentType::from(content_type);
207
208 if !status.is_client_error() && !status.is_server_error() {
209 let content = resp.text().await?;
210 match content_type {
211 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
212 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Comment`"))),
213 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Comment`")))),
214 }
215 } else {
216 let content = resp.text().await?;
217 let entity: Option<CommentsGetByIdError> = serde_json::from_str(&content).ok();
218 Err(Error::ResponseError(ResponseContent {
219 status,
220 content,
221 entity,
222 }))
223 }
224}