mistral_openapi_client/apis/
beta_libraries_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 LibrariesCreateV1Error {
22 Status422(models::HttpValidationError),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum LibrariesDeleteV1Error {
30 Status422(models::HttpValidationError),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum LibrariesGetV1Error {
38 Status422(models::HttpValidationError),
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum LibrariesListV1Error {
46 UnknownValue(serde_json::Value),
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
51#[serde(untagged)]
52pub enum LibrariesUpdateV1Error {
53 Status422(models::HttpValidationError),
54 UnknownValue(serde_json::Value),
55}
56
57
58pub async fn libraries_create_v1(configuration: &configuration::Configuration, library_in: models::LibraryIn) -> Result<models::LibraryOut, Error<LibrariesCreateV1Error>> {
60 let p_body_library_in = library_in;
62
63 let uri_str = format!("{}/v1/libraries", configuration.base_path);
64 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
65
66 if let Some(ref user_agent) = configuration.user_agent {
67 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
68 }
69 if let Some(ref token) = configuration.bearer_access_token {
70 req_builder = req_builder.bearer_auth(token.to_owned());
71 };
72 req_builder = req_builder.json(&p_body_library_in);
73
74 let req = req_builder.build()?;
75 let resp = configuration.client.execute(req).await?;
76
77 let status = resp.status();
78 let content_type = resp
79 .headers()
80 .get("content-type")
81 .and_then(|v| v.to_str().ok())
82 .unwrap_or("application/octet-stream");
83 let content_type = super::ContentType::from(content_type);
84
85 if !status.is_client_error() && !status.is_server_error() {
86 let content = resp.text().await?;
87 match content_type {
88 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
89 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LibraryOut`"))),
90 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::LibraryOut`")))),
91 }
92 } else {
93 let content = resp.text().await?;
94 let entity: Option<LibrariesCreateV1Error> = serde_json::from_str(&content).ok();
95 Err(Error::ResponseError(ResponseContent { status, content, entity }))
96 }
97}
98
99pub async fn libraries_delete_v1(configuration: &configuration::Configuration, library_id: &str) -> Result<models::LibraryOut, Error<LibrariesDeleteV1Error>> {
101 let p_path_library_id = library_id;
103
104 let uri_str = format!("{}/v1/libraries/{library_id}", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id));
105 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
106
107 if let Some(ref user_agent) = configuration.user_agent {
108 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
109 }
110 if let Some(ref token) = configuration.bearer_access_token {
111 req_builder = req_builder.bearer_auth(token.to_owned());
112 };
113
114 let req = req_builder.build()?;
115 let resp = configuration.client.execute(req).await?;
116
117 let status = resp.status();
118 let content_type = resp
119 .headers()
120 .get("content-type")
121 .and_then(|v| v.to_str().ok())
122 .unwrap_or("application/octet-stream");
123 let content_type = super::ContentType::from(content_type);
124
125 if !status.is_client_error() && !status.is_server_error() {
126 let content = resp.text().await?;
127 match content_type {
128 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
129 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LibraryOut`"))),
130 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::LibraryOut`")))),
131 }
132 } else {
133 let content = resp.text().await?;
134 let entity: Option<LibrariesDeleteV1Error> = serde_json::from_str(&content).ok();
135 Err(Error::ResponseError(ResponseContent { status, content, entity }))
136 }
137}
138
139pub async fn libraries_get_v1(configuration: &configuration::Configuration, library_id: &str) -> Result<models::LibraryOut, Error<LibrariesGetV1Error>> {
141 let p_path_library_id = library_id;
143
144 let uri_str = format!("{}/v1/libraries/{library_id}", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id));
145 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
146
147 if let Some(ref user_agent) = configuration.user_agent {
148 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
149 }
150 if let Some(ref token) = configuration.bearer_access_token {
151 req_builder = req_builder.bearer_auth(token.to_owned());
152 };
153
154 let req = req_builder.build()?;
155 let resp = configuration.client.execute(req).await?;
156
157 let status = resp.status();
158 let content_type = resp
159 .headers()
160 .get("content-type")
161 .and_then(|v| v.to_str().ok())
162 .unwrap_or("application/octet-stream");
163 let content_type = super::ContentType::from(content_type);
164
165 if !status.is_client_error() && !status.is_server_error() {
166 let content = resp.text().await?;
167 match content_type {
168 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
169 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LibraryOut`"))),
170 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::LibraryOut`")))),
171 }
172 } else {
173 let content = resp.text().await?;
174 let entity: Option<LibrariesGetV1Error> = serde_json::from_str(&content).ok();
175 Err(Error::ResponseError(ResponseContent { status, content, entity }))
176 }
177}
178
179pub async fn libraries_list_v1(configuration: &configuration::Configuration, ) -> Result<models::ListLibraryOut, Error<LibrariesListV1Error>> {
181
182 let uri_str = format!("{}/v1/libraries", configuration.base_path);
183 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
184
185 if let Some(ref user_agent) = configuration.user_agent {
186 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
187 }
188 if let Some(ref token) = configuration.bearer_access_token {
189 req_builder = req_builder.bearer_auth(token.to_owned());
190 };
191
192 let req = req_builder.build()?;
193 let resp = configuration.client.execute(req).await?;
194
195 let status = resp.status();
196 let content_type = resp
197 .headers()
198 .get("content-type")
199 .and_then(|v| v.to_str().ok())
200 .unwrap_or("application/octet-stream");
201 let content_type = super::ContentType::from(content_type);
202
203 if !status.is_client_error() && !status.is_server_error() {
204 let content = resp.text().await?;
205 match content_type {
206 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
207 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListLibraryOut`"))),
208 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::ListLibraryOut`")))),
209 }
210 } else {
211 let content = resp.text().await?;
212 let entity: Option<LibrariesListV1Error> = serde_json::from_str(&content).ok();
213 Err(Error::ResponseError(ResponseContent { status, content, entity }))
214 }
215}
216
217pub async fn libraries_update_v1(configuration: &configuration::Configuration, library_id: &str, library_in_update: models::LibraryInUpdate) -> Result<models::LibraryOut, Error<LibrariesUpdateV1Error>> {
219 let p_path_library_id = library_id;
221 let p_body_library_in_update = library_in_update;
222
223 let uri_str = format!("{}/v1/libraries/{library_id}", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id));
224 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
225
226 if let Some(ref user_agent) = configuration.user_agent {
227 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
228 }
229 if let Some(ref token) = configuration.bearer_access_token {
230 req_builder = req_builder.bearer_auth(token.to_owned());
231 };
232 req_builder = req_builder.json(&p_body_library_in_update);
233
234 let req = req_builder.build()?;
235 let resp = configuration.client.execute(req).await?;
236
237 let status = resp.status();
238 let content_type = resp
239 .headers()
240 .get("content-type")
241 .and_then(|v| v.to_str().ok())
242 .unwrap_or("application/octet-stream");
243 let content_type = super::ContentType::from(content_type);
244
245 if !status.is_client_error() && !status.is_server_error() {
246 let content = resp.text().await?;
247 match content_type {
248 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
249 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LibraryOut`"))),
250 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::LibraryOut`")))),
251 }
252 } else {
253 let content = resp.text().await?;
254 let entity: Option<LibrariesUpdateV1Error> = serde_json::from_str(&content).ok();
255 Err(Error::ResponseError(ResponseContent { status, content, entity }))
256 }
257}
258