deepl_openapi/apis/
meta_information_api.rs1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetLanguagesError {
22 Status400(),
23 Status403(),
24 Status404(),
25 Status413(),
26 Status429(),
27 Status456(),
28 Status500(),
29 Status504(),
30 Status529(),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetUsageError {
38 Status400(),
39 Status403(),
40 Status404(),
41 Status413(),
42 Status429(),
43 Status456(),
44 Status500(),
45 Status504(),
46 Status529(),
47 UnknownValue(serde_json::Value),
48}
49
50
51pub async fn get_languages(configuration: &configuration::Configuration, r#type: Option<&str>) -> Result<Vec<crate::models::GetLanguages200ResponseInner>, Error<GetLanguagesError>> {
53 let local_var_configuration = configuration;
54
55 let local_var_client = &local_var_configuration.client;
56
57 let local_var_uri_str = format!("{}/languages", local_var_configuration.base_path);
58 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
59
60 if let Some(ref local_var_str) = r#type {
61 local_var_req_builder = local_var_req_builder.query(&[("type", &local_var_str.to_string())]);
62 }
63 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
64 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
65 }
66 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
67 let local_var_key = local_var_apikey.key.clone();
68 let local_var_value = match local_var_apikey.prefix {
69 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
70 None => local_var_key,
71 };
72 local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
73 };
74
75 let local_var_req = local_var_req_builder.build()?;
76 let local_var_resp = local_var_client.execute(local_var_req).await?;
77
78 let local_var_status = local_var_resp.status();
79 let local_var_content = local_var_resp.text().await?;
80
81 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
82 serde_json::from_str(&local_var_content).map_err(Error::from)
83 } else {
84 let local_var_entity: Option<GetLanguagesError> = serde_json::from_str(&local_var_content).ok();
85 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
86 Err(Error::ResponseError(local_var_error))
87 }
88}
89
90pub async fn get_usage(configuration: &configuration::Configuration, ) -> Result<crate::models::GetUsage200Response, Error<GetUsageError>> {
92 let local_var_configuration = configuration;
93
94 let local_var_client = &local_var_configuration.client;
95
96 let local_var_uri_str = format!("{}/usage", local_var_configuration.base_path);
97 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
98
99 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
100 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
101 }
102 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
103 let local_var_key = local_var_apikey.key.clone();
104 let local_var_value = match local_var_apikey.prefix {
105 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
106 None => local_var_key,
107 };
108 local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
109 };
110
111 let local_var_req = local_var_req_builder.build()?;
112 let local_var_resp = local_var_client.execute(local_var_req).await?;
113
114 let local_var_status = local_var_resp.status();
115 let local_var_content = local_var_resp.text().await?;
116
117 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
118 serde_json::from_str(&local_var_content).map_err(Error::from)
119 } else {
120 let local_var_entity: Option<GetUsageError> = serde_json::from_str(&local_var_content).ok();
121 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
122 Err(Error::ResponseError(local_var_error))
123 }
124}
125