1use 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 GetChannelsError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetChannelsAllowlistError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetChannelsInboxError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetChannelsPairingError {
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum PostChannelsByChannelSendError {
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum PostChannelsPairingApproveError {
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum PutChannelsAllowlistError {
64 UnknownValue(serde_json::Value),
65}
66
67
68pub async fn get_channels(configuration: &configuration::Configuration, ) -> Result<models::ChatChannels, Error<GetChannelsError>> {
70
71 let uri_str = format!("{}/v1/channels", configuration.base_path);
72 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
73
74 if let Some(ref user_agent) = configuration.user_agent {
75 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
76 }
77 if let Some(ref token) = configuration.bearer_access_token {
78 req_builder = req_builder.bearer_auth(token.to_owned());
79 };
80
81 let req = req_builder.build()?;
82 let resp = configuration.client.execute(req).await?;
83
84 let status = resp.status();
85 let content_type = resp
86 .headers()
87 .get("content-type")
88 .and_then(|v| v.to_str().ok())
89 .unwrap_or("application/octet-stream");
90 let content_type = super::ContentType::from(content_type);
91
92 if !status.is_client_error() && !status.is_server_error() {
93 let content = resp.text().await?;
94 match content_type {
95 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
96 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ChatChannels`"))),
97 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::ChatChannels`")))),
98 }
99 } else {
100 let content = resp.text().await?;
101 let entity: Option<GetChannelsError> = serde_json::from_str(&content).ok();
102 Err(Error::ResponseError(ResponseContent { status, content, entity }))
103 }
104}
105
106pub async fn get_channels_allowlist(configuration: &configuration::Configuration, channel: Option<&str>) -> Result<models::AllowlistView, Error<GetChannelsAllowlistError>> {
108 let p_channel = channel;
110
111 let uri_str = format!("{}/v1/channels/allowlist", configuration.base_path);
112 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
113
114 if let Some(ref param_value) = p_channel {
115 req_builder = req_builder.query(&[("channel", ¶m_value.to_string())]);
116 }
117 if let Some(ref user_agent) = configuration.user_agent {
118 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
119 }
120 if let Some(ref token) = configuration.bearer_access_token {
121 req_builder = req_builder.bearer_auth(token.to_owned());
122 };
123
124 let req = req_builder.build()?;
125 let resp = configuration.client.execute(req).await?;
126
127 let status = resp.status();
128 let content_type = resp
129 .headers()
130 .get("content-type")
131 .and_then(|v| v.to_str().ok())
132 .unwrap_or("application/octet-stream");
133 let content_type = super::ContentType::from(content_type);
134
135 if !status.is_client_error() && !status.is_server_error() {
136 let content = resp.text().await?;
137 match content_type {
138 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
139 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AllowlistView`"))),
140 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::AllowlistView`")))),
141 }
142 } else {
143 let content = resp.text().await?;
144 let entity: Option<GetChannelsAllowlistError> = serde_json::from_str(&content).ok();
145 Err(Error::ResponseError(ResponseContent { status, content, entity }))
146 }
147}
148
149pub async fn get_channels_inbox(configuration: &configuration::Configuration, since: Option<&str>, limit: Option<&str>) -> Result<models::InboxPage, Error<GetChannelsInboxError>> {
151 let p_since = since;
153 let p_limit = limit;
154
155 let uri_str = format!("{}/v1/channels/inbox", configuration.base_path);
156 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
157
158 if let Some(ref param_value) = p_since {
159 req_builder = req_builder.query(&[("since", ¶m_value.to_string())]);
160 }
161 if let Some(ref param_value) = p_limit {
162 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
163 }
164 if let Some(ref user_agent) = configuration.user_agent {
165 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
166 }
167 if let Some(ref token) = configuration.bearer_access_token {
168 req_builder = req_builder.bearer_auth(token.to_owned());
169 };
170
171 let req = req_builder.build()?;
172 let resp = configuration.client.execute(req).await?;
173
174 let status = resp.status();
175 let content_type = resp
176 .headers()
177 .get("content-type")
178 .and_then(|v| v.to_str().ok())
179 .unwrap_or("application/octet-stream");
180 let content_type = super::ContentType::from(content_type);
181
182 if !status.is_client_error() && !status.is_server_error() {
183 let content = resp.text().await?;
184 match content_type {
185 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
186 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InboxPage`"))),
187 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::InboxPage`")))),
188 }
189 } else {
190 let content = resp.text().await?;
191 let entity: Option<GetChannelsInboxError> = serde_json::from_str(&content).ok();
192 Err(Error::ResponseError(ResponseContent { status, content, entity }))
193 }
194}
195
196pub async fn get_channels_pairing(configuration: &configuration::Configuration, ) -> Result<models::PairingQueue, Error<GetChannelsPairingError>> {
198
199 let uri_str = format!("{}/v1/channels/pairing", configuration.base_path);
200 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
201
202 if let Some(ref user_agent) = configuration.user_agent {
203 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
204 }
205 if let Some(ref token) = configuration.bearer_access_token {
206 req_builder = req_builder.bearer_auth(token.to_owned());
207 };
208
209 let req = req_builder.build()?;
210 let resp = configuration.client.execute(req).await?;
211
212 let status = resp.status();
213 let content_type = resp
214 .headers()
215 .get("content-type")
216 .and_then(|v| v.to_str().ok())
217 .unwrap_or("application/octet-stream");
218 let content_type = super::ContentType::from(content_type);
219
220 if !status.is_client_error() && !status.is_server_error() {
221 let content = resp.text().await?;
222 match content_type {
223 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
224 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PairingQueue`"))),
225 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::PairingQueue`")))),
226 }
227 } else {
228 let content = resp.text().await?;
229 let entity: Option<GetChannelsPairingError> = serde_json::from_str(&content).ok();
230 Err(Error::ResponseError(ResponseContent { status, content, entity }))
231 }
232}
233
234pub async fn post_channels_by_channel_send(configuration: &configuration::Configuration, channel: &str) -> Result<(), Error<PostChannelsByChannelSendError>> {
236 let p_channel = channel;
238
239 let uri_str = format!("{}/v1/channels/{channel}/send", configuration.base_path, channel=crate::apis::urlencode(p_channel));
240 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
241
242 if let Some(ref user_agent) = configuration.user_agent {
243 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
244 }
245 if let Some(ref token) = configuration.bearer_access_token {
246 req_builder = req_builder.bearer_auth(token.to_owned());
247 };
248
249 let req = req_builder.build()?;
250 let resp = configuration.client.execute(req).await?;
251
252 let status = resp.status();
253
254 if !status.is_client_error() && !status.is_server_error() {
255 Ok(())
256 } else {
257 let content = resp.text().await?;
258 let entity: Option<PostChannelsByChannelSendError> = serde_json::from_str(&content).ok();
259 Err(Error::ResponseError(ResponseContent { status, content, entity }))
260 }
261}
262
263pub async fn post_channels_pairing_approve(configuration: &configuration::Configuration, approve_pairing_in: models::ApprovePairingIn) -> Result<models::PairingApproved, Error<PostChannelsPairingApproveError>> {
265 let p_approve_pairing_in = approve_pairing_in;
267
268 let uri_str = format!("{}/v1/channels/pairing/approve", configuration.base_path);
269 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
270
271 if let Some(ref user_agent) = configuration.user_agent {
272 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
273 }
274 if let Some(ref token) = configuration.bearer_access_token {
275 req_builder = req_builder.bearer_auth(token.to_owned());
276 };
277 req_builder = req_builder.json(&p_approve_pairing_in);
278
279 let req = req_builder.build()?;
280 let resp = configuration.client.execute(req).await?;
281
282 let status = resp.status();
283 let content_type = resp
284 .headers()
285 .get("content-type")
286 .and_then(|v| v.to_str().ok())
287 .unwrap_or("application/octet-stream");
288 let content_type = super::ContentType::from(content_type);
289
290 if !status.is_client_error() && !status.is_server_error() {
291 let content = resp.text().await?;
292 match content_type {
293 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
294 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PairingApproved`"))),
295 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::PairingApproved`")))),
296 }
297 } else {
298 let content = resp.text().await?;
299 let entity: Option<PostChannelsPairingApproveError> = serde_json::from_str(&content).ok();
300 Err(Error::ResponseError(ResponseContent { status, content, entity }))
301 }
302}
303
304pub async fn put_channels_allowlist(configuration: &configuration::Configuration, allowlist_put_in: models::AllowlistPutIn) -> Result<models::AllowlistView, Error<PutChannelsAllowlistError>> {
306 let p_allowlist_put_in = allowlist_put_in;
308
309 let uri_str = format!("{}/v1/channels/allowlist", configuration.base_path);
310 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
311
312 if let Some(ref user_agent) = configuration.user_agent {
313 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
314 }
315 if let Some(ref token) = configuration.bearer_access_token {
316 req_builder = req_builder.bearer_auth(token.to_owned());
317 };
318 req_builder = req_builder.json(&p_allowlist_put_in);
319
320 let req = req_builder.build()?;
321 let resp = configuration.client.execute(req).await?;
322
323 let status = resp.status();
324 let content_type = resp
325 .headers()
326 .get("content-type")
327 .and_then(|v| v.to_str().ok())
328 .unwrap_or("application/octet-stream");
329 let content_type = super::ContentType::from(content_type);
330
331 if !status.is_client_error() && !status.is_server_error() {
332 let content = resp.text().await?;
333 match content_type {
334 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
335 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AllowlistView`"))),
336 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::AllowlistView`")))),
337 }
338 } else {
339 let content = resp.text().await?;
340 let entity: Option<PutChannelsAllowlistError> = serde_json::from_str(&content).ok();
341 Err(Error::ResponseError(ResponseContent { status, content, entity }))
342 }
343}
344