ebbmem_client_generated/apis/
events_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 StreamEventsError {
22 Status422(models::HttpValidationError),
23 UnknownValue(serde_json::Value),
24}
25
26
27pub async fn stream_events(configuration: &configuration::Configuration, last_event_id: Option<&str>, event_types: Option<Vec<String>>, namespace: Option<&str>, namespaces: Option<Vec<String>>, last_event_id2: Option<&str>, token: Option<&str>) -> Result<models::StreamEventsResponse200, Error<StreamEventsError>> {
29 let p_query_last_event_id = last_event_id;
31 let p_query_event_types = event_types;
32 let p_query_namespace = namespace;
33 let p_query_namespaces = namespaces;
34 let p_header_last_event_id = last_event_id2;
35 let p_query_token = token;
36
37 let uri_str = format!("{}/api/v1/events/stream", configuration.base_path);
38 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
39
40 if let Some(ref param_value) = p_query_last_event_id {
41 req_builder = req_builder.query(&[("last_event_id", ¶m_value.to_string())]);
42 }
43 if let Some(ref param_value) = p_query_event_types {
44 req_builder = match "multi" {
45 "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("event_types".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
46 _ => req_builder.query(&[("event_types", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
47 };
48 }
49 if let Some(ref param_value) = p_query_namespace {
50 req_builder = req_builder.query(&[("namespace", ¶m_value.to_string())]);
51 }
52 if let Some(ref param_value) = p_query_namespaces {
53 req_builder = match "multi" {
54 "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("namespaces".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
55 _ => req_builder.query(&[("namespaces", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
56 };
57 }
58 if let Some(ref param_value) = p_query_token {
59 req_builder = req_builder.query(&[("token", ¶m_value.to_string())]);
60 }
61 if let Some(ref user_agent) = configuration.user_agent {
62 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
63 }
64 if let Some(param_value) = p_header_last_event_id {
65 req_builder = req_builder.header("Last-Event-ID", param_value.to_string());
66 }
67 if let Some(ref token) = configuration.bearer_access_token {
68 req_builder = req_builder.bearer_auth(token.to_owned());
69 };
70 if let Some(ref apikey) = configuration.api_key {
71 let key = apikey.key.clone();
72 let value = match apikey.prefix {
73 Some(ref prefix) => format!("{} {}", prefix, key),
74 None => key,
75 };
76 req_builder = req_builder.header("X-API-Key", value);
77 };
78
79 let req = req_builder.build()?;
80 let resp = configuration.client.execute(req).await?;
81
82 let status = resp.status();
83 let content_type = resp
84 .headers()
85 .get("content-type")
86 .and_then(|v| v.to_str().ok())
87 .unwrap_or("application/octet-stream");
88 let content_type = super::ContentType::from(content_type);
89
90 if !status.is_client_error() && !status.is_server_error() {
91 let content = resp.text().await?;
92 match content_type {
93 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
94 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::StreamEventsResponse200`"))),
95 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::StreamEventsResponse200`")))),
96 }
97 } else {
98 let content = resp.text().await?;
99 let entity: Option<StreamEventsError> = serde_json::from_str(&content).ok();
100 Err(Error::ResponseError(ResponseContent { status, content, entity }))
101 }
102}
103