mistral_openapi_client/apis/
beta_libraries_accesses_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 LibrariesShareCreateV1Error {
22 Status422(models::HttpValidationError),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum LibrariesShareDeleteV1Error {
30 Status422(models::HttpValidationError),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum LibrariesShareListV1Error {
38 Status422(models::HttpValidationError),
39 UnknownValue(serde_json::Value),
40}
41
42
43pub async fn libraries_share_create_v1(configuration: &configuration::Configuration, library_id: &str, sharing_in: models::SharingIn) -> Result<models::SharingOut, Error<LibrariesShareCreateV1Error>> {
45 let p_path_library_id = library_id;
47 let p_body_sharing_in = sharing_in;
48
49 let uri_str = format!("{}/v1/libraries/{library_id}/share", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id));
50 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
51
52 if let Some(ref user_agent) = configuration.user_agent {
53 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
54 }
55 if let Some(ref token) = configuration.bearer_access_token {
56 req_builder = req_builder.bearer_auth(token.to_owned());
57 };
58 req_builder = req_builder.json(&p_body_sharing_in);
59
60 let req = req_builder.build()?;
61 let resp = configuration.client.execute(req).await?;
62
63 let status = resp.status();
64 let content_type = resp
65 .headers()
66 .get("content-type")
67 .and_then(|v| v.to_str().ok())
68 .unwrap_or("application/octet-stream");
69 let content_type = super::ContentType::from(content_type);
70
71 if !status.is_client_error() && !status.is_server_error() {
72 let content = resp.text().await?;
73 match content_type {
74 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
75 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SharingOut`"))),
76 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::SharingOut`")))),
77 }
78 } else {
79 let content = resp.text().await?;
80 let entity: Option<LibrariesShareCreateV1Error> = serde_json::from_str(&content).ok();
81 Err(Error::ResponseError(ResponseContent { status, content, entity }))
82 }
83}
84
85pub async fn libraries_share_delete_v1(configuration: &configuration::Configuration, library_id: &str, sharing_delete: models::SharingDelete) -> Result<models::SharingOut, Error<LibrariesShareDeleteV1Error>> {
87 let p_path_library_id = library_id;
89 let p_body_sharing_delete = sharing_delete;
90
91 let uri_str = format!("{}/v1/libraries/{library_id}/share", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id));
92 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
93
94 if let Some(ref user_agent) = configuration.user_agent {
95 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
96 }
97 if let Some(ref token) = configuration.bearer_access_token {
98 req_builder = req_builder.bearer_auth(token.to_owned());
99 };
100 req_builder = req_builder.json(&p_body_sharing_delete);
101
102 let req = req_builder.build()?;
103 let resp = configuration.client.execute(req).await?;
104
105 let status = resp.status();
106 let content_type = resp
107 .headers()
108 .get("content-type")
109 .and_then(|v| v.to_str().ok())
110 .unwrap_or("application/octet-stream");
111 let content_type = super::ContentType::from(content_type);
112
113 if !status.is_client_error() && !status.is_server_error() {
114 let content = resp.text().await?;
115 match content_type {
116 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
117 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SharingOut`"))),
118 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::SharingOut`")))),
119 }
120 } else {
121 let content = resp.text().await?;
122 let entity: Option<LibrariesShareDeleteV1Error> = serde_json::from_str(&content).ok();
123 Err(Error::ResponseError(ResponseContent { status, content, entity }))
124 }
125}
126
127pub async fn libraries_share_list_v1(configuration: &configuration::Configuration, library_id: &str) -> Result<models::ListSharingOut, Error<LibrariesShareListV1Error>> {
129 let p_path_library_id = library_id;
131
132 let uri_str = format!("{}/v1/libraries/{library_id}/share", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id));
133 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
134
135 if let Some(ref user_agent) = configuration.user_agent {
136 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
137 }
138 if let Some(ref token) = configuration.bearer_access_token {
139 req_builder = req_builder.bearer_auth(token.to_owned());
140 };
141
142 let req = req_builder.build()?;
143 let resp = configuration.client.execute(req).await?;
144
145 let status = resp.status();
146 let content_type = resp
147 .headers()
148 .get("content-type")
149 .and_then(|v| v.to_str().ok())
150 .unwrap_or("application/octet-stream");
151 let content_type = super::ContentType::from(content_type);
152
153 if !status.is_client_error() && !status.is_server_error() {
154 let content = resp.text().await?;
155 match content_type {
156 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
157 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListSharingOut`"))),
158 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::ListSharingOut`")))),
159 }
160 } else {
161 let content = resp.text().await?;
162 let entity: Option<LibrariesShareListV1Error> = serde_json::from_str(&content).ok();
163 Err(Error::ResponseError(ResponseContent { status, content, entity }))
164 }
165}
166