roark_rs/apis/
evaluation_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 CreateEvaluationJobError {
22 Status400(models::ErrorResponse),
23 Status401(models::ErrorResponse),
24 Status403(models::ErrorResponse),
25 Status429(models::ErrorResponse),
26 Status500(models::ErrorResponse),
27 UnknownValue(serde_json::Value),
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum GetEvaluationJobError {
34 Status401(models::ErrorResponse),
35 Status403(models::ErrorResponse),
36 Status404(models::ErrorResponse),
37 Status429(models::ErrorResponse),
38 Status500(models::ErrorResponse),
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum GetEvaluationJobRunsError {
46 Status401(models::ErrorResponse),
47 Status403(models::ErrorResponse),
48 Status404(models::ErrorResponse),
49 Status429(models::ErrorResponse),
50 Status500(models::ErrorResponse),
51 UnknownValue(serde_json::Value),
52}
53
54
55pub async fn create_evaluation_job(configuration: &configuration::Configuration, evaluation_job_create_request: models::EvaluationJobCreateRequest) -> Result<models::CreateEvaluationJob201Response, Error<CreateEvaluationJobError>> {
57 let p_evaluation_job_create_request = evaluation_job_create_request;
59
60 let uri_str = format!("{}/v1/evaluation/job", 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 token) = configuration.bearer_access_token {
67 req_builder = req_builder.bearer_auth(token.to_owned());
68 };
69 req_builder = req_builder.json(&p_evaluation_job_create_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::CreateEvaluationJob201Response`"))),
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::CreateEvaluationJob201Response`")))),
88 }
89 } else {
90 let content = resp.text().await?;
91 let entity: Option<CreateEvaluationJobError> = serde_json::from_str(&content).ok();
92 Err(Error::ResponseError(ResponseContent { status, content, entity }))
93 }
94}
95
96pub async fn get_evaluation_job(configuration: &configuration::Configuration, job_id: &str) -> Result<models::GetEvaluationJob200Response, Error<GetEvaluationJobError>> {
98 let p_job_id = job_id;
100
101 let uri_str = format!("{}/v1/evaluation/job/{job_id}", configuration.base_path, job_id=crate::apis::urlencode(p_job_id));
102 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
103
104 if let Some(ref user_agent) = configuration.user_agent {
105 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
106 }
107 if let Some(ref token) = configuration.bearer_access_token {
108 req_builder = req_builder.bearer_auth(token.to_owned());
109 };
110
111 let req = req_builder.build()?;
112 let resp = configuration.client.execute(req).await?;
113
114 let status = resp.status();
115 let content_type = resp
116 .headers()
117 .get("content-type")
118 .and_then(|v| v.to_str().ok())
119 .unwrap_or("application/octet-stream");
120 let content_type = super::ContentType::from(content_type);
121
122 if !status.is_client_error() && !status.is_server_error() {
123 let content = resp.text().await?;
124 match content_type {
125 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
126 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetEvaluationJob200Response`"))),
127 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::GetEvaluationJob200Response`")))),
128 }
129 } else {
130 let content = resp.text().await?;
131 let entity: Option<GetEvaluationJobError> = serde_json::from_str(&content).ok();
132 Err(Error::ResponseError(ResponseContent { status, content, entity }))
133 }
134}
135
136pub async fn get_evaluation_job_runs(configuration: &configuration::Configuration, job_id: &str, next_cursor: Option<&str>, limit: Option<u8>) -> Result<models::GetEvaluationJobRuns200Response, Error<GetEvaluationJobRunsError>> {
138 let p_job_id = job_id;
140 let p_next_cursor = next_cursor;
141 let p_limit = limit;
142
143 let uri_str = format!("{}/v1/evaluation/job/{job_id}/runs", configuration.base_path, job_id=crate::apis::urlencode(p_job_id));
144 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
145
146 if let Some(ref param_value) = p_next_cursor {
147 req_builder = req_builder.query(&[("next_cursor", ¶m_value.to_string())]);
148 }
149 if let Some(ref param_value) = p_limit {
150 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
151 }
152 if let Some(ref user_agent) = configuration.user_agent {
153 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
154 }
155 if let Some(ref token) = configuration.bearer_access_token {
156 req_builder = req_builder.bearer_auth(token.to_owned());
157 };
158
159 let req = req_builder.build()?;
160 let resp = configuration.client.execute(req).await?;
161
162 let status = resp.status();
163 let content_type = resp
164 .headers()
165 .get("content-type")
166 .and_then(|v| v.to_str().ok())
167 .unwrap_or("application/octet-stream");
168 let content_type = super::ContentType::from(content_type);
169
170 if !status.is_client_error() && !status.is_server_error() {
171 let content = resp.text().await?;
172 match content_type {
173 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
174 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetEvaluationJobRuns200Response`"))),
175 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::GetEvaluationJobRuns200Response`")))),
176 }
177 } else {
178 let content = resp.text().await?;
179 let entity: Option<GetEvaluationJobRunsError> = serde_json::from_str(&content).ok();
180 Err(Error::ResponseError(ResponseContent { status, content, entity }))
181 }
182}
183