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