langfuse_client_base/apis/
media_api.rs1use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum MediaGetError {
20 Status400(serde_json::Value),
21 Status401(serde_json::Value),
22 Status403(serde_json::Value),
23 Status404(serde_json::Value),
24 Status405(serde_json::Value),
25 UnknownValue(serde_json::Value),
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum MediaGetUploadUrlError {
32 Status400(serde_json::Value),
33 Status401(serde_json::Value),
34 Status403(serde_json::Value),
35 Status404(serde_json::Value),
36 Status405(serde_json::Value),
37 UnknownValue(serde_json::Value),
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum MediaPatchError {
44 Status400(serde_json::Value),
45 Status401(serde_json::Value),
46 Status403(serde_json::Value),
47 Status404(serde_json::Value),
48 Status405(serde_json::Value),
49 UnknownValue(serde_json::Value),
50}
51
52pub async fn media_get(
54 configuration: &configuration::Configuration,
55 media_id: &str,
56) -> Result<models::GetMediaResponse, Error<MediaGetError>> {
57 let p_path_media_id = media_id;
59
60 let uri_str = format!(
61 "{}/api/public/media/{mediaId}",
62 configuration.base_path,
63 mediaId = crate::apis::urlencode(p_path_media_id)
64 );
65 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
66
67 if let Some(ref user_agent) = configuration.user_agent {
68 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
69 }
70 if let Some(ref auth_conf) = configuration.basic_auth {
71 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
72 };
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::GetMediaResponse`"))),
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::GetMediaResponse`")))),
91 }
92 } else {
93 let content = resp.text().await?;
94 let entity: Option<MediaGetError> = serde_json::from_str(&content).ok();
95 Err(Error::ResponseError(ResponseContent {
96 status,
97 content,
98 entity,
99 }))
100 }
101}
102
103pub async fn media_get_upload_url(
105 configuration: &configuration::Configuration,
106 get_media_upload_url_request: models::GetMediaUploadUrlRequest,
107) -> Result<models::GetMediaUploadUrlResponse, Error<MediaGetUploadUrlError>> {
108 let p_body_get_media_upload_url_request = get_media_upload_url_request;
110
111 let uri_str = format!("{}/api/public/media", configuration.base_path);
112 let mut req_builder = configuration
113 .client
114 .request(reqwest::Method::POST, &uri_str);
115
116 if let Some(ref user_agent) = configuration.user_agent {
117 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
118 }
119 if let Some(ref auth_conf) = configuration.basic_auth {
120 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
121 };
122 req_builder = req_builder.json(&p_body_get_media_upload_url_request);
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::GetMediaUploadUrlResponse`"))),
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::GetMediaUploadUrlResponse`")))),
141 }
142 } else {
143 let content = resp.text().await?;
144 let entity: Option<MediaGetUploadUrlError> = serde_json::from_str(&content).ok();
145 Err(Error::ResponseError(ResponseContent {
146 status,
147 content,
148 entity,
149 }))
150 }
151}
152
153pub async fn media_patch(
155 configuration: &configuration::Configuration,
156 media_id: &str,
157 patch_media_body: models::PatchMediaBody,
158) -> Result<(), Error<MediaPatchError>> {
159 let p_path_media_id = media_id;
161 let p_body_patch_media_body = patch_media_body;
162
163 let uri_str = format!(
164 "{}/api/public/media/{mediaId}",
165 configuration.base_path,
166 mediaId = crate::apis::urlencode(p_path_media_id)
167 );
168 let mut req_builder = configuration
169 .client
170 .request(reqwest::Method::PATCH, &uri_str);
171
172 if let Some(ref user_agent) = configuration.user_agent {
173 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
174 }
175 if let Some(ref auth_conf) = configuration.basic_auth {
176 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
177 };
178 req_builder = req_builder.json(&p_body_patch_media_body);
179
180 let req = req_builder.build()?;
181 let resp = configuration.client.execute(req).await?;
182
183 let status = resp.status();
184
185 if !status.is_client_error() && !status.is_server_error() {
186 Ok(())
187 } else {
188 let content = resp.text().await?;
189 let entity: Option<MediaPatchError> = serde_json::from_str(&content).ok();
190 Err(Error::ResponseError(ResponseContent {
191 status,
192 content,
193 entity,
194 }))
195 }
196}