langfuse_client_base/apis/
score_configs_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 ScoreConfigsCreateError {
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 ScoreConfigsGetError {
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 ScoreConfigsGetByIdError {
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 score_configs_create(
55 configuration: &configuration::Configuration,
56 create_score_config_request: models::CreateScoreConfigRequest,
57) -> Result<models::ScoreConfig, Error<ScoreConfigsCreateError>> {
58 let p_body_create_score_config_request = create_score_config_request;
60
61 let uri_str = format!("{}/api/public/score-configs", 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_score_config_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::ScoreConfig`"))),
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::ScoreConfig`")))),
91 }
92 } else {
93 let content = resp.text().await?;
94 let entity: Option<ScoreConfigsCreateError> = 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 score_configs_get(
106 configuration: &configuration::Configuration,
107 page: Option<i32>,
108 limit: Option<i32>,
109) -> Result<models::ScoreConfigs, Error<ScoreConfigsGetError>> {
110 let p_query_page = page;
112 let p_query_limit = limit;
113
114 let uri_str = format!("{}/api/public/score-configs", configuration.base_path);
115 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
116
117 if let Some(ref param_value) = p_query_page {
118 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
119 }
120 if let Some(ref param_value) = p_query_limit {
121 req_builder = req_builder.query(&[("limit", ¶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::ScoreConfigs`"))),
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::ScoreConfigs`")))),
147 }
148 } else {
149 let content = resp.text().await?;
150 let entity: Option<ScoreConfigsGetError> = serde_json::from_str(&content).ok();
151 Err(Error::ResponseError(ResponseContent {
152 status,
153 content,
154 entity,
155 }))
156 }
157}
158
159#[bon::builder]
161pub async fn score_configs_get_by_id(
162 configuration: &configuration::Configuration,
163 config_id: &str,
164) -> Result<models::ScoreConfig, Error<ScoreConfigsGetByIdError>> {
165 let p_path_config_id = config_id;
167
168 let uri_str = format!(
169 "{}/api/public/score-configs/{configId}",
170 configuration.base_path,
171 configId = crate::apis::urlencode(p_path_config_id)
172 );
173 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
174
175 if let Some(ref user_agent) = configuration.user_agent {
176 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
177 }
178 if let Some(ref auth_conf) = configuration.basic_auth {
179 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
180 };
181
182 let req = req_builder.build()?;
183 let resp = configuration.client.execute(req).await?;
184
185 let status = resp.status();
186 let content_type = resp
187 .headers()
188 .get("content-type")
189 .and_then(|v| v.to_str().ok())
190 .unwrap_or("application/octet-stream");
191 let content_type = super::ContentType::from(content_type);
192
193 if !status.is_client_error() && !status.is_server_error() {
194 let content = resp.text().await?;
195 match content_type {
196 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
197 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ScoreConfig`"))),
198 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::ScoreConfig`")))),
199 }
200 } else {
201 let content = resp.text().await?;
202 let entity: Option<ScoreConfigsGetByIdError> = serde_json::from_str(&content).ok();
203 Err(Error::ResponseError(ResponseContent {
204 status,
205 content,
206 entity,
207 }))
208 }
209}