hanzo_client/apis/
pubsub_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 PostPubsubPublishError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum PostPubsubRequestError {
29 UnknownValue(serde_json::Value),
30}
31
32
33pub async fn post_pubsub_publish(configuration: &configuration::Configuration, bus_publish: models::BusPublish) -> Result<models::BusAck, Error<PostPubsubPublishError>> {
35 let p_bus_publish = bus_publish;
37
38 let uri_str = format!("{}/v1/pubsub/publish", configuration.base_path);
39 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
40
41 if let Some(ref user_agent) = configuration.user_agent {
42 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
43 }
44 if let Some(ref token) = configuration.bearer_access_token {
45 req_builder = req_builder.bearer_auth(token.to_owned());
46 };
47 req_builder = req_builder.json(&p_bus_publish);
48
49 let req = req_builder.build()?;
50 let resp = configuration.client.execute(req).await?;
51
52 let status = resp.status();
53 let content_type = resp
54 .headers()
55 .get("content-type")
56 .and_then(|v| v.to_str().ok())
57 .unwrap_or("application/octet-stream");
58 let content_type = super::ContentType::from(content_type);
59
60 if !status.is_client_error() && !status.is_server_error() {
61 let content = resp.text().await?;
62 match content_type {
63 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
64 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BusAck`"))),
65 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::BusAck`")))),
66 }
67 } else {
68 let content = resp.text().await?;
69 let entity: Option<PostPubsubPublishError> = serde_json::from_str(&content).ok();
70 Err(Error::ResponseError(ResponseContent { status, content, entity }))
71 }
72}
73
74pub async fn post_pubsub_request(configuration: &configuration::Configuration, bus_request: models::BusRequest) -> Result<models::BusMessage, Error<PostPubsubRequestError>> {
76 let p_bus_request = bus_request;
78
79 let uri_str = format!("{}/v1/pubsub/request", configuration.base_path);
80 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
81
82 if let Some(ref user_agent) = configuration.user_agent {
83 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
84 }
85 if let Some(ref token) = configuration.bearer_access_token {
86 req_builder = req_builder.bearer_auth(token.to_owned());
87 };
88 req_builder = req_builder.json(&p_bus_request);
89
90 let req = req_builder.build()?;
91 let resp = configuration.client.execute(req).await?;
92
93 let status = resp.status();
94 let content_type = resp
95 .headers()
96 .get("content-type")
97 .and_then(|v| v.to_str().ok())
98 .unwrap_or("application/octet-stream");
99 let content_type = super::ContentType::from(content_type);
100
101 if !status.is_client_error() && !status.is_server_error() {
102 let content = resp.text().await?;
103 match content_type {
104 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
105 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BusMessage`"))),
106 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::BusMessage`")))),
107 }
108 } else {
109 let content = resp.text().await?;
110 let entity: Option<PostPubsubRequestError> = serde_json::from_str(&content).ok();
111 Err(Error::ResponseError(ResponseContent { status, content, entity }))
112 }
113}
114