limit_lens/apis/
rate_test_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 CreateTestSessionError {
22 Status500(),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum GetAllSessionsError {
30 UnknownValue(serde_json::Value),
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum GetTestMetricsError {
37 Status404(),
38 UnknownValue(serde_json::Value),
39}
40
41#[derive(Debug, Clone, Serialize, Deserialize)]
43#[serde(untagged)]
44pub enum MetricsDashboardError {
45 UnknownValue(serde_json::Value),
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum ReceiveTestRequestError {
52 Status404(),
53 UnknownValue(serde_json::Value),
54}
55
56
57pub async fn create_test_session(configuration: &configuration::Configuration, create_session_request: models::CreateSessionRequest) -> Result<models::TestSession, Error<CreateTestSessionError>> {
59 let p_create_session_request = create_session_request;
61
62 let uri_str = format!("{}/api/test/session", configuration.base_path);
63 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
64
65 if let Some(ref user_agent) = configuration.user_agent {
66 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
67 }
68 req_builder = req_builder.json(&p_create_session_request);
69
70 let req = req_builder.build()?;
71 let resp = configuration.client.execute(req).await?;
72
73 let status = resp.status();
74 let content_type = resp
75 .headers()
76 .get("content-type")
77 .and_then(|v| v.to_str().ok())
78 .unwrap_or("application/octet-stream");
79 let content_type = super::ContentType::from(content_type);
80
81 if !status.is_client_error() && !status.is_server_error() {
82 let content = resp.text().await?;
83 match content_type {
84 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
85 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TestSession`"))),
86 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::TestSession`")))),
87 }
88 } else {
89 let content = resp.text().await?;
90 let entity: Option<CreateTestSessionError> = serde_json::from_str(&content).ok();
91 Err(Error::ResponseError(ResponseContent { status, content, entity }))
92 }
93}
94
95pub async fn get_all_sessions(configuration: &configuration::Configuration, ) -> Result<Vec<models::TestSession>, Error<GetAllSessionsError>> {
97
98 let uri_str = format!("{}/api/test/sessions", configuration.base_path);
99 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
100
101 if let Some(ref user_agent) = configuration.user_agent {
102 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
103 }
104
105 let req = req_builder.build()?;
106 let resp = configuration.client.execute(req).await?;
107
108 let status = resp.status();
109 let content_type = resp
110 .headers()
111 .get("content-type")
112 .and_then(|v| v.to_str().ok())
113 .unwrap_or("application/octet-stream");
114 let content_type = super::ContentType::from(content_type);
115
116 if !status.is_client_error() && !status.is_server_error() {
117 let content = resp.text().await?;
118 match content_type {
119 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
120 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::TestSession>`"))),
121 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::TestSession>`")))),
122 }
123 } else {
124 let content = resp.text().await?;
125 let entity: Option<GetAllSessionsError> = serde_json::from_str(&content).ok();
126 Err(Error::ResponseError(ResponseContent { status, content, entity }))
127 }
128}
129
130pub async fn get_test_metrics(configuration: &configuration::Configuration, session_id: &str) -> Result<models::TestMetrics, Error<GetTestMetricsError>> {
132 let p_session_id = session_id;
134
135 let uri_str = format!("{}/api/test/metrics/{session_id}", configuration.base_path, session_id=crate::apis::urlencode(p_session_id));
136 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
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
142 let req = req_builder.build()?;
143 let resp = configuration.client.execute(req).await?;
144
145 let status = resp.status();
146 let content_type = resp
147 .headers()
148 .get("content-type")
149 .and_then(|v| v.to_str().ok())
150 .unwrap_or("application/octet-stream");
151 let content_type = super::ContentType::from(content_type);
152
153 if !status.is_client_error() && !status.is_server_error() {
154 let content = resp.text().await?;
155 match content_type {
156 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
157 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TestMetrics`"))),
158 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::TestMetrics`")))),
159 }
160 } else {
161 let content = resp.text().await?;
162 let entity: Option<GetTestMetricsError> = serde_json::from_str(&content).ok();
163 Err(Error::ResponseError(ResponseContent { status, content, entity }))
164 }
165}
166
167pub async fn metrics_dashboard(configuration: &configuration::Configuration, ) -> Result<(), Error<MetricsDashboardError>> {
169
170 let uri_str = format!("{}/dashboard", configuration.base_path);
171 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
172
173 if let Some(ref user_agent) = configuration.user_agent {
174 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
175 }
176
177 let req = req_builder.build()?;
178 let resp = configuration.client.execute(req).await?;
179
180 let status = resp.status();
181
182 if !status.is_client_error() && !status.is_server_error() {
183 Ok(())
184 } else {
185 let content = resp.text().await?;
186 let entity: Option<MetricsDashboardError> = serde_json::from_str(&content).ok();
187 Err(Error::ResponseError(ResponseContent { status, content, entity }))
188 }
189}
190
191pub async fn receive_test_request(configuration: &configuration::Configuration, session_id: &str) -> Result<(), Error<ReceiveTestRequestError>> {
193 let p_session_id = session_id;
195
196 let uri_str = format!("{}/api/test/request/{session_id}", configuration.base_path, session_id=crate::apis::urlencode(p_session_id));
197 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
198
199 if let Some(ref user_agent) = configuration.user_agent {
200 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
201 }
202
203 let req = req_builder.build()?;
204 let resp = configuration.client.execute(req).await?;
205
206 let status = resp.status();
207
208 if !status.is_client_error() && !status.is_server_error() {
209 Ok(())
210 } else {
211 let content = resp.text().await?;
212 let entity: Option<ReceiveTestRequestError> = serde_json::from_str(&content).ok();
213 Err(Error::ResponseError(ResponseContent { status, content, entity }))
214 }
215}
216