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 DeleteKeyBindingError {
22 Status401(models::ApiError),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum GetDefaultKeyBindingsError {
30 Status401(models::ApiError),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum ListKeyBindingsError {
38 Status401(models::ApiError),
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum ResetAllKeyBindingsError {
46 Status401(models::ApiError),
47 UnknownValue(serde_json::Value),
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum UpdateKeyBindingError {
54 Status401(models::ApiError),
55 UnknownValue(serde_json::Value),
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum ValidateKeyBindingError {
62 Status401(models::ApiError),
63 UnknownValue(serde_json::Value),
64}
65
66
67pub async fn delete_key_binding(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteKeyBindingError>> {
68 let p_path_id = id;
70
71 let uri_str = format!("{}/v1/keybindings/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
72 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &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
86 if !status.is_client_error() && !status.is_server_error() {
87 Ok(())
88 } else {
89 let content = resp.text().await?;
90 let entity: Option<DeleteKeyBindingError> = serde_json::from_str(&content).ok();
91 Err(Error::ResponseError(ResponseContent { status, content, entity }))
92 }
93}
94
95pub async fn get_default_key_bindings(configuration: &configuration::Configuration, ) -> Result<models::KeyBindingListResponse, Error<GetDefaultKeyBindingsError>> {
96
97 let uri_str = format!("{}/v1/keybindings/defaults", configuration.base_path);
98 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
99
100 if let Some(ref user_agent) = configuration.user_agent {
101 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
102 }
103 if let Some(ref token) = configuration.bearer_access_token {
104 req_builder = req_builder.bearer_auth(token.to_owned());
105 };
106
107 let req = req_builder.build()?;
108 let resp = configuration.client.execute(req).await?;
109
110 let status = resp.status();
111 let content_type = resp
112 .headers()
113 .get("content-type")
114 .and_then(|v| v.to_str().ok())
115 .unwrap_or("application/octet-stream");
116 let content_type = super::ContentType::from(content_type);
117
118 if !status.is_client_error() && !status.is_server_error() {
119 let content = resp.text().await?;
120 match content_type {
121 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
122 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::KeyBindingListResponse`"))),
123 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::KeyBindingListResponse`")))),
124 }
125 } else {
126 let content = resp.text().await?;
127 let entity: Option<GetDefaultKeyBindingsError> = serde_json::from_str(&content).ok();
128 Err(Error::ResponseError(ResponseContent { status, content, entity }))
129 }
130}
131
132pub async fn list_key_bindings(configuration: &configuration::Configuration, ) -> Result<models::KeyBindingListResponse, Error<ListKeyBindingsError>> {
133
134 let uri_str = format!("{}/v1/keybindings", configuration.base_path);
135 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
136
137 if let Some(ref user_agent) = configuration.user_agent {
138 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
139 }
140 if let Some(ref token) = configuration.bearer_access_token {
141 req_builder = req_builder.bearer_auth(token.to_owned());
142 };
143
144 let req = req_builder.build()?;
145 let resp = configuration.client.execute(req).await?;
146
147 let status = resp.status();
148 let content_type = resp
149 .headers()
150 .get("content-type")
151 .and_then(|v| v.to_str().ok())
152 .unwrap_or("application/octet-stream");
153 let content_type = super::ContentType::from(content_type);
154
155 if !status.is_client_error() && !status.is_server_error() {
156 let content = resp.text().await?;
157 match content_type {
158 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
159 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::KeyBindingListResponse`"))),
160 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::KeyBindingListResponse`")))),
161 }
162 } else {
163 let content = resp.text().await?;
164 let entity: Option<ListKeyBindingsError> = serde_json::from_str(&content).ok();
165 Err(Error::ResponseError(ResponseContent { status, content, entity }))
166 }
167}
168
169pub async fn reset_all_key_bindings(configuration: &configuration::Configuration, ) -> Result<(), Error<ResetAllKeyBindingsError>> {
170
171 let uri_str = format!("{}/v1/keybindings/reset", configuration.base_path);
172 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
173
174 if let Some(ref user_agent) = configuration.user_agent {
175 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
176 }
177 if let Some(ref token) = configuration.bearer_access_token {
178 req_builder = req_builder.bearer_auth(token.to_owned());
179 };
180
181 let req = req_builder.build()?;
182 let resp = configuration.client.execute(req).await?;
183
184 let status = resp.status();
185
186 if !status.is_client_error() && !status.is_server_error() {
187 Ok(())
188 } else {
189 let content = resp.text().await?;
190 let entity: Option<ResetAllKeyBindingsError> = serde_json::from_str(&content).ok();
191 Err(Error::ResponseError(ResponseContent { status, content, entity }))
192 }
193}
194
195pub async fn update_key_binding(configuration: &configuration::Configuration, id: &str, update_key_binding_request: models::UpdateKeyBindingRequest) -> Result<models::KeyBinding, Error<UpdateKeyBindingError>> {
196 let p_path_id = id;
198 let p_body_update_key_binding_request = update_key_binding_request;
199
200 let uri_str = format!("{}/v1/keybindings/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
201 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
202
203 if let Some(ref user_agent) = configuration.user_agent {
204 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
205 }
206 if let Some(ref token) = configuration.bearer_access_token {
207 req_builder = req_builder.bearer_auth(token.to_owned());
208 };
209 req_builder = req_builder.json(&p_body_update_key_binding_request);
210
211 let req = req_builder.build()?;
212 let resp = configuration.client.execute(req).await?;
213
214 let status = resp.status();
215 let content_type = resp
216 .headers()
217 .get("content-type")
218 .and_then(|v| v.to_str().ok())
219 .unwrap_or("application/octet-stream");
220 let content_type = super::ContentType::from(content_type);
221
222 if !status.is_client_error() && !status.is_server_error() {
223 let content = resp.text().await?;
224 match content_type {
225 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
226 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::KeyBinding`"))),
227 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::KeyBinding`")))),
228 }
229 } else {
230 let content = resp.text().await?;
231 let entity: Option<UpdateKeyBindingError> = serde_json::from_str(&content).ok();
232 Err(Error::ResponseError(ResponseContent { status, content, entity }))
233 }
234}
235
236pub async fn validate_key_binding(configuration: &configuration::Configuration, validate_key_binding_request: models::ValidateKeyBindingRequest) -> Result<models::ValidateKeyBindingResponse, Error<ValidateKeyBindingError>> {
237 let p_body_validate_key_binding_request = validate_key_binding_request;
239
240 let uri_str = format!("{}/v1/keybindings/validate", configuration.base_path);
241 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
242
243 if let Some(ref user_agent) = configuration.user_agent {
244 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
245 }
246 if let Some(ref token) = configuration.bearer_access_token {
247 req_builder = req_builder.bearer_auth(token.to_owned());
248 };
249 req_builder = req_builder.json(&p_body_validate_key_binding_request);
250
251 let req = req_builder.build()?;
252 let resp = configuration.client.execute(req).await?;
253
254 let status = resp.status();
255 let content_type = resp
256 .headers()
257 .get("content-type")
258 .and_then(|v| v.to_str().ok())
259 .unwrap_or("application/octet-stream");
260 let content_type = super::ContentType::from(content_type);
261
262 if !status.is_client_error() && !status.is_server_error() {
263 let content = resp.text().await?;
264 match content_type {
265 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
266 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ValidateKeyBindingResponse`"))),
267 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::ValidateKeyBindingResponse`")))),
268 }
269 } else {
270 let content = resp.text().await?;
271 let entity: Option<ValidateKeyBindingError> = serde_json::from_str(&content).ok();
272 Err(Error::ResponseError(ResponseContent { status, content, entity }))
273 }
274}
275