deepl_openapi/apis/
manage_glossaries_api.rs

1/*
2 * DeepL API Documentation
3 *
4 * The DeepL API provides programmatic access to DeepL’s machine translation technology.
5 *
6 * The version of the OpenAPI document: 2.7.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`create_glossary`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateGlossaryError {
22    Status400(crate::models::ListGlossaryLanguages400Response),
23    Status401(),
24    Status403(),
25    Status404(),
26    Status413(),
27    Status415(),
28    Status429(),
29    Status456(),
30    Status500(),
31    Status503(),
32    Status529(),
33    UnknownValue(serde_json::Value),
34}
35
36/// struct for typed errors of method [`delete_glossary`]
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum DeleteGlossaryError {
40    Status400(crate::models::ListGlossaryLanguages400Response),
41    Status401(),
42    Status403(),
43    Status404(),
44    Status413(),
45    Status415(),
46    Status429(),
47    Status456(),
48    Status500(),
49    Status503(),
50    Status529(),
51    UnknownValue(serde_json::Value),
52}
53
54/// struct for typed errors of method [`get_glossary`]
55#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum GetGlossaryError {
58    Status400(crate::models::ListGlossaryLanguages400Response),
59    Status401(),
60    Status403(),
61    Status404(),
62    Status413(),
63    Status415(),
64    Status429(),
65    Status456(),
66    Status500(),
67    Status503(),
68    Status529(),
69    UnknownValue(serde_json::Value),
70}
71
72/// struct for typed errors of method [`get_glossary_entries`]
73#[derive(Debug, Clone, Serialize, Deserialize)]
74#[serde(untagged)]
75pub enum GetGlossaryEntriesError {
76    Status400(crate::models::ListGlossaryLanguages400Response),
77    Status401(),
78    Status403(),
79    Status404(),
80    Status413(),
81    Status415(),
82    Status429(),
83    Status456(),
84    Status500(),
85    Status503(),
86    Status529(),
87    UnknownValue(serde_json::Value),
88}
89
90/// struct for typed errors of method [`list_glossaries`]
91#[derive(Debug, Clone, Serialize, Deserialize)]
92#[serde(untagged)]
93pub enum ListGlossariesError {
94    Status400(crate::models::ListGlossaryLanguages400Response),
95    Status401(),
96    Status403(),
97    Status404(),
98    Status413(),
99    Status415(),
100    Status429(),
101    Status456(),
102    Status500(),
103    Status503(),
104    Status529(),
105    UnknownValue(serde_json::Value),
106}
107
108/// struct for typed errors of method [`list_glossary_languages`]
109#[derive(Debug, Clone, Serialize, Deserialize)]
110#[serde(untagged)]
111pub enum ListGlossaryLanguagesError {
112    Status400(crate::models::ListGlossaryLanguages400Response),
113    Status401(),
114    Status403(),
115    Status404(),
116    Status413(),
117    Status415(),
118    Status429(),
119    Status456(),
120    Status500(),
121    Status503(),
122    Status529(),
123    UnknownValue(serde_json::Value),
124}
125
126
127pub async fn create_glossary(configuration: &configuration::Configuration, name: &str, source_lang: crate::models::GlossarySourceLanguage, target_lang: crate::models::GlossaryTargetLanguage, entries: &str, entries_format: &str) -> Result<crate::models::Glossary, Error<CreateGlossaryError>> {
128    let local_var_configuration = configuration;
129
130    let local_var_client = &local_var_configuration.client;
131
132    let local_var_uri_str = format!("{}/glossaries", local_var_configuration.base_path);
133    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
134
135    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
136        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
137    }
138    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
139        let local_var_key = local_var_apikey.key.clone();
140        let local_var_value = match local_var_apikey.prefix {
141            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
142            None => local_var_key,
143        };
144        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
145    };
146    let mut local_var_form_params = std::collections::HashMap::new();
147    local_var_form_params.insert("name", name.to_string());
148    local_var_form_params.insert("source_lang", source_lang.to_string());
149    local_var_form_params.insert("target_lang", target_lang.to_string());
150    local_var_form_params.insert("entries", entries.to_string());
151    local_var_form_params.insert("entries_format", entries_format.to_string());
152    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
153
154    let local_var_req = local_var_req_builder.build()?;
155    let local_var_resp = local_var_client.execute(local_var_req).await?;
156
157    let local_var_status = local_var_resp.status();
158    let local_var_content = local_var_resp.text().await?;
159
160    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
161        serde_json::from_str(&local_var_content).map_err(Error::from)
162    } else {
163        let local_var_entity: Option<CreateGlossaryError> = serde_json::from_str(&local_var_content).ok();
164        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
165        Err(Error::ResponseError(local_var_error))
166    }
167}
168
169/// Deletes the specified glossary.
170pub async fn delete_glossary(configuration: &configuration::Configuration, glossary_id: &str) -> Result<(), Error<DeleteGlossaryError>> {
171    let local_var_configuration = configuration;
172
173    let local_var_client = &local_var_configuration.client;
174
175    let local_var_uri_str = format!("{}/glossaries/{glossary_id}", local_var_configuration.base_path, glossary_id=crate::apis::urlencode(glossary_id));
176    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
177
178    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
179        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
180    }
181    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
182        let local_var_key = local_var_apikey.key.clone();
183        let local_var_value = match local_var_apikey.prefix {
184            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
185            None => local_var_key,
186        };
187        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
188    };
189
190    let local_var_req = local_var_req_builder.build()?;
191    let local_var_resp = local_var_client.execute(local_var_req).await?;
192
193    let local_var_status = local_var_resp.status();
194    let local_var_content = local_var_resp.text().await?;
195
196    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
197        Ok(())
198    } else {
199        let local_var_entity: Option<DeleteGlossaryError> = serde_json::from_str(&local_var_content).ok();
200        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
201        Err(Error::ResponseError(local_var_error))
202    }
203}
204
205/// Retrieve meta information for a single glossary, omitting the glossary entries.
206pub async fn get_glossary(configuration: &configuration::Configuration, glossary_id: &str) -> Result<crate::models::Glossary, Error<GetGlossaryError>> {
207    let local_var_configuration = configuration;
208
209    let local_var_client = &local_var_configuration.client;
210
211    let local_var_uri_str = format!("{}/glossaries/{glossary_id}", local_var_configuration.base_path, glossary_id=crate::apis::urlencode(glossary_id));
212    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
213
214    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
215        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
216    }
217    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
218        let local_var_key = local_var_apikey.key.clone();
219        let local_var_value = match local_var_apikey.prefix {
220            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
221            None => local_var_key,
222        };
223        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
224    };
225
226    let local_var_req = local_var_req_builder.build()?;
227    let local_var_resp = local_var_client.execute(local_var_req).await?;
228
229    let local_var_status = local_var_resp.status();
230    let local_var_content = local_var_resp.text().await?;
231
232    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
233        serde_json::from_str(&local_var_content).map_err(Error::from)
234    } else {
235        let local_var_entity: Option<GetGlossaryError> = serde_json::from_str(&local_var_content).ok();
236        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
237        Err(Error::ResponseError(local_var_error))
238    }
239}
240
241/// List the entries of a single glossary in the format specified by the `Accept` header.
242pub async fn get_glossary_entries(configuration: &configuration::Configuration, glossary_id: &str, accept: Option<&str>) -> Result<(), Error<GetGlossaryEntriesError>> {
243    let local_var_configuration = configuration;
244
245    let local_var_client = &local_var_configuration.client;
246
247    let local_var_uri_str = format!("{}/glossaries/{glossary_id}/entries", local_var_configuration.base_path, glossary_id=crate::apis::urlencode(glossary_id));
248    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
249
250    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
251        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
252    }
253    if let Some(local_var_param_value) = accept {
254        local_var_req_builder = local_var_req_builder.header("Accept", local_var_param_value.to_string());
255    }
256    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
257        let local_var_key = local_var_apikey.key.clone();
258        let local_var_value = match local_var_apikey.prefix {
259            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
260            None => local_var_key,
261        };
262        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
263    };
264
265    let local_var_req = local_var_req_builder.build()?;
266    let local_var_resp = local_var_client.execute(local_var_req).await?;
267
268    let local_var_status = local_var_resp.status();
269    let local_var_content = local_var_resp.text().await?;
270
271    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
272        Ok(())
273    } else {
274        let local_var_entity: Option<GetGlossaryEntriesError> = serde_json::from_str(&local_var_content).ok();
275        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
276        Err(Error::ResponseError(local_var_error))
277    }
278}
279
280/// List all glossaries and their meta-information, but not the glossary entries.
281pub async fn list_glossaries(configuration: &configuration::Configuration, ) -> Result<crate::models::ListGlossaries200Response, Error<ListGlossariesError>> {
282    let local_var_configuration = configuration;
283
284    let local_var_client = &local_var_configuration.client;
285
286    let local_var_uri_str = format!("{}/glossaries", local_var_configuration.base_path);
287    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
288
289    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
290        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
291    }
292    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
293        let local_var_key = local_var_apikey.key.clone();
294        let local_var_value = match local_var_apikey.prefix {
295            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
296            None => local_var_key,
297        };
298        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
299    };
300
301    let local_var_req = local_var_req_builder.build()?;
302    let local_var_resp = local_var_client.execute(local_var_req).await?;
303
304    let local_var_status = local_var_resp.status();
305    let local_var_content = local_var_resp.text().await?;
306
307    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
308        serde_json::from_str(&local_var_content).map_err(Error::from)
309    } else {
310        let local_var_entity: Option<ListGlossariesError> = serde_json::from_str(&local_var_content).ok();
311        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
312        Err(Error::ResponseError(local_var_error))
313    }
314}
315
316/// Retrieve the list of language pairs supported by the glossary feature.
317pub async fn list_glossary_languages(configuration: &configuration::Configuration, ) -> Result<crate::models::ListGlossaryLanguages200Response, Error<ListGlossaryLanguagesError>> {
318    let local_var_configuration = configuration;
319
320    let local_var_client = &local_var_configuration.client;
321
322    let local_var_uri_str = format!("{}/glossary-language-pairs", local_var_configuration.base_path);
323    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
324
325    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
326        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
327    }
328    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
329        let local_var_key = local_var_apikey.key.clone();
330        let local_var_value = match local_var_apikey.prefix {
331            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
332            None => local_var_key,
333        };
334        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
335    };
336
337    let local_var_req = local_var_req_builder.build()?;
338    let local_var_resp = local_var_client.execute(local_var_req).await?;
339
340    let local_var_status = local_var_resp.status();
341    let local_var_content = local_var_resp.text().await?;
342
343    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
344        serde_json::from_str(&local_var_content).map_err(Error::from)
345    } else {
346        let local_var_entity: Option<ListGlossaryLanguagesError> = serde_json::from_str(&local_var_content).ok();
347        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
348        Err(Error::ResponseError(local_var_error))
349    }
350}
351