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 CreateRequestError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum CreateRequestByStatusError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum CreateRequestRetryError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum DeleteRequestError {
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetRequestError {
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetRequestByRequestIdError {
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum GetRequestCountError {
64 UnknownValue(serde_json::Value),
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum UpdateRequestError {
71 UnknownValue(serde_json::Value),
72}
73
74
75pub async fn create_request(configuration: &configuration::Configuration, create_request_request: models::CreateRequestRequest) -> Result<models::MediaRequest, Error<CreateRequestError>> {
77 let p_body_create_request_request = create_request_request;
79
80 let uri_str = format!("{}/request", configuration.base_path);
81 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
82
83 if let Some(ref user_agent) = configuration.user_agent {
84 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
85 }
86 if let Some(ref apikey) = configuration.api_key {
87 let key = apikey.key.clone();
88 let value = match apikey.prefix {
89 Some(ref prefix) => format!("{} {}", prefix, key),
90 None => key,
91 };
92 req_builder = req_builder.header("X-Api-Key", value);
93 };
94 req_builder = req_builder.json(&p_body_create_request_request);
95
96 let req = req_builder.build()?;
97 let resp = configuration.client.execute(req).await?;
98
99 let status = resp.status();
100 let content_type = resp
101 .headers()
102 .get("content-type")
103 .and_then(|v| v.to_str().ok())
104 .unwrap_or("application/octet-stream");
105 let content_type = super::ContentType::from(content_type);
106
107 if !status.is_client_error() && !status.is_server_error() {
108 let content = resp.text().await?;
109 match content_type {
110 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
111 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MediaRequest`"))),
112 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::MediaRequest`")))),
113 }
114 } else {
115 let content = resp.text().await?;
116 let entity: Option<CreateRequestError> = serde_json::from_str(&content).ok();
117 Err(Error::ResponseError(ResponseContent { status, content, entity }))
118 }
119}
120
121pub async fn create_request_by_status(configuration: &configuration::Configuration, request_id: &str, status: &str) -> Result<models::MediaRequest, Error<CreateRequestByStatusError>> {
123 let p_path_request_id = request_id;
125 let p_path_status = status;
126
127 let uri_str = format!("{}/request/{requestId}/{status}", configuration.base_path, requestId=crate::apis::urlencode(p_path_request_id), status=crate::apis::urlencode(p_path_status));
128 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
129
130 if let Some(ref user_agent) = configuration.user_agent {
131 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
132 }
133 if let Some(ref apikey) = configuration.api_key {
134 let key = apikey.key.clone();
135 let value = match apikey.prefix {
136 Some(ref prefix) => format!("{} {}", prefix, key),
137 None => key,
138 };
139 req_builder = req_builder.header("X-Api-Key", value);
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::MediaRequest`"))),
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::MediaRequest`")))),
159 }
160 } else {
161 let content = resp.text().await?;
162 let entity: Option<CreateRequestByStatusError> = serde_json::from_str(&content).ok();
163 Err(Error::ResponseError(ResponseContent { status, content, entity }))
164 }
165}
166
167pub async fn create_request_retry(configuration: &configuration::Configuration, request_id: &str) -> Result<models::MediaRequest, Error<CreateRequestRetryError>> {
169 let p_path_request_id = request_id;
171
172 let uri_str = format!("{}/request/{requestId}/retry", configuration.base_path, requestId=crate::apis::urlencode(p_path_request_id));
173 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
174
175 if let Some(ref user_agent) = configuration.user_agent {
176 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
177 }
178 if let Some(ref apikey) = configuration.api_key {
179 let key = apikey.key.clone();
180 let value = match apikey.prefix {
181 Some(ref prefix) => format!("{} {}", prefix, key),
182 None => key,
183 };
184 req_builder = req_builder.header("X-Api-Key", value);
185 };
186
187 let req = req_builder.build()?;
188 let resp = configuration.client.execute(req).await?;
189
190 let status = resp.status();
191 let content_type = resp
192 .headers()
193 .get("content-type")
194 .and_then(|v| v.to_str().ok())
195 .unwrap_or("application/octet-stream");
196 let content_type = super::ContentType::from(content_type);
197
198 if !status.is_client_error() && !status.is_server_error() {
199 let content = resp.text().await?;
200 match content_type {
201 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
202 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MediaRequest`"))),
203 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::MediaRequest`")))),
204 }
205 } else {
206 let content = resp.text().await?;
207 let entity: Option<CreateRequestRetryError> = serde_json::from_str(&content).ok();
208 Err(Error::ResponseError(ResponseContent { status, content, entity }))
209 }
210}
211
212pub async fn delete_request(configuration: &configuration::Configuration, request_id: &str) -> Result<(), Error<DeleteRequestError>> {
214 let p_path_request_id = request_id;
216
217 let uri_str = format!("{}/request/{requestId}", configuration.base_path, requestId=crate::apis::urlencode(p_path_request_id));
218 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
219
220 if let Some(ref user_agent) = configuration.user_agent {
221 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
222 }
223 if let Some(ref apikey) = configuration.api_key {
224 let key = apikey.key.clone();
225 let value = match apikey.prefix {
226 Some(ref prefix) => format!("{} {}", prefix, key),
227 None => key,
228 };
229 req_builder = req_builder.header("X-Api-Key", value);
230 };
231
232 let req = req_builder.build()?;
233 let resp = configuration.client.execute(req).await?;
234
235 let status = resp.status();
236
237 if !status.is_client_error() && !status.is_server_error() {
238 Ok(())
239 } else {
240 let content = resp.text().await?;
241 let entity: Option<DeleteRequestError> = serde_json::from_str(&content).ok();
242 Err(Error::ResponseError(ResponseContent { status, content, entity }))
243 }
244}
245
246pub async fn get_request(configuration: &configuration::Configuration, take: Option<f64>, skip: Option<f64>, filter: Option<&str>, sort: Option<&str>, requested_by: Option<f64>) -> Result<models::GetUserRequests2XxResponse, Error<GetRequestError>> {
248 let p_query_take = take;
250 let p_query_skip = skip;
251 let p_query_filter = filter;
252 let p_query_sort = sort;
253 let p_query_requested_by = requested_by;
254
255 let uri_str = format!("{}/request", configuration.base_path);
256 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
257
258 if let Some(ref param_value) = p_query_take {
259 req_builder = req_builder.query(&[("take", ¶m_value.to_string())]);
260 }
261 if let Some(ref param_value) = p_query_skip {
262 req_builder = req_builder.query(&[("skip", ¶m_value.to_string())]);
263 }
264 if let Some(ref param_value) = p_query_filter {
265 req_builder = req_builder.query(&[("filter", ¶m_value.to_string())]);
266 }
267 if let Some(ref param_value) = p_query_sort {
268 req_builder = req_builder.query(&[("sort", ¶m_value.to_string())]);
269 }
270 if let Some(ref param_value) = p_query_requested_by {
271 req_builder = req_builder.query(&[("requestedBy", ¶m_value.to_string())]);
272 }
273 if let Some(ref user_agent) = configuration.user_agent {
274 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
275 }
276 if let Some(ref apikey) = configuration.api_key {
277 let key = apikey.key.clone();
278 let value = match apikey.prefix {
279 Some(ref prefix) => format!("{} {}", prefix, key),
280 None => key,
281 };
282 req_builder = req_builder.header("X-Api-Key", value);
283 };
284
285 let req = req_builder.build()?;
286 let resp = configuration.client.execute(req).await?;
287
288 let status = resp.status();
289 let content_type = resp
290 .headers()
291 .get("content-type")
292 .and_then(|v| v.to_str().ok())
293 .unwrap_or("application/octet-stream");
294 let content_type = super::ContentType::from(content_type);
295
296 if !status.is_client_error() && !status.is_server_error() {
297 let content = resp.text().await?;
298 match content_type {
299 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
300 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetUserRequests2XxResponse`"))),
301 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::GetUserRequests2XxResponse`")))),
302 }
303 } else {
304 let content = resp.text().await?;
305 let entity: Option<GetRequestError> = serde_json::from_str(&content).ok();
306 Err(Error::ResponseError(ResponseContent { status, content, entity }))
307 }
308}
309
310pub async fn get_request_by_request_id(configuration: &configuration::Configuration, request_id: &str) -> Result<models::MediaRequest, Error<GetRequestByRequestIdError>> {
312 let p_path_request_id = request_id;
314
315 let uri_str = format!("{}/request/{requestId}", configuration.base_path, requestId=crate::apis::urlencode(p_path_request_id));
316 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
317
318 if let Some(ref user_agent) = configuration.user_agent {
319 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
320 }
321 if let Some(ref apikey) = configuration.api_key {
322 let key = apikey.key.clone();
323 let value = match apikey.prefix {
324 Some(ref prefix) => format!("{} {}", prefix, key),
325 None => key,
326 };
327 req_builder = req_builder.header("X-Api-Key", value);
328 };
329
330 let req = req_builder.build()?;
331 let resp = configuration.client.execute(req).await?;
332
333 let status = resp.status();
334 let content_type = resp
335 .headers()
336 .get("content-type")
337 .and_then(|v| v.to_str().ok())
338 .unwrap_or("application/octet-stream");
339 let content_type = super::ContentType::from(content_type);
340
341 if !status.is_client_error() && !status.is_server_error() {
342 let content = resp.text().await?;
343 match content_type {
344 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
345 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MediaRequest`"))),
346 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::MediaRequest`")))),
347 }
348 } else {
349 let content = resp.text().await?;
350 let entity: Option<GetRequestByRequestIdError> = serde_json::from_str(&content).ok();
351 Err(Error::ResponseError(ResponseContent { status, content, entity }))
352 }
353}
354
355pub async fn get_request_count(configuration: &configuration::Configuration, ) -> Result<models::GetRequestCount2XxResponse, Error<GetRequestCountError>> {
357
358 let uri_str = format!("{}/request/count", configuration.base_path);
359 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
360
361 if let Some(ref user_agent) = configuration.user_agent {
362 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
363 }
364 if let Some(ref apikey) = configuration.api_key {
365 let key = apikey.key.clone();
366 let value = match apikey.prefix {
367 Some(ref prefix) => format!("{} {}", prefix, key),
368 None => key,
369 };
370 req_builder = req_builder.header("X-Api-Key", value);
371 };
372
373 let req = req_builder.build()?;
374 let resp = configuration.client.execute(req).await?;
375
376 let status = resp.status();
377 let content_type = resp
378 .headers()
379 .get("content-type")
380 .and_then(|v| v.to_str().ok())
381 .unwrap_or("application/octet-stream");
382 let content_type = super::ContentType::from(content_type);
383
384 if !status.is_client_error() && !status.is_server_error() {
385 let content = resp.text().await?;
386 match content_type {
387 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
388 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetRequestCount2XxResponse`"))),
389 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::GetRequestCount2XxResponse`")))),
390 }
391 } else {
392 let content = resp.text().await?;
393 let entity: Option<GetRequestCountError> = serde_json::from_str(&content).ok();
394 Err(Error::ResponseError(ResponseContent { status, content, entity }))
395 }
396}
397
398pub async fn update_request(configuration: &configuration::Configuration, request_id: &str, update_request_request: models::UpdateRequestRequest) -> Result<models::MediaRequest, Error<UpdateRequestError>> {
400 let p_path_request_id = request_id;
402 let p_body_update_request_request = update_request_request;
403
404 let uri_str = format!("{}/request/{requestId}", configuration.base_path, requestId=crate::apis::urlencode(p_path_request_id));
405 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
406
407 if let Some(ref user_agent) = configuration.user_agent {
408 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
409 }
410 if let Some(ref apikey) = configuration.api_key {
411 let key = apikey.key.clone();
412 let value = match apikey.prefix {
413 Some(ref prefix) => format!("{} {}", prefix, key),
414 None => key,
415 };
416 req_builder = req_builder.header("X-Api-Key", value);
417 };
418 req_builder = req_builder.json(&p_body_update_request_request);
419
420 let req = req_builder.build()?;
421 let resp = configuration.client.execute(req).await?;
422
423 let status = resp.status();
424 let content_type = resp
425 .headers()
426 .get("content-type")
427 .and_then(|v| v.to_str().ok())
428 .unwrap_or("application/octet-stream");
429 let content_type = super::ContentType::from(content_type);
430
431 if !status.is_client_error() && !status.is_server_error() {
432 let content = resp.text().await?;
433 match content_type {
434 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
435 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MediaRequest`"))),
436 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::MediaRequest`")))),
437 }
438 } else {
439 let content = resp.text().await?;
440 let entity: Option<UpdateRequestError> = serde_json::from_str(&content).ok();
441 Err(Error::ResponseError(ResponseContent { status, content, entity }))
442 }
443}
444