lol_esports_api/apis/
default_api.rs

1/*
2 * Lol Esports Api
3 *
4 * League of Legends Esports API
5 *
6 * The version of the OpenAPI document: 0.2.2
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`get_league_by_code`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetLeagueByCodeError {
22    Status404(models::EsportsServerError),
23    Status500(models::EsportsServerError),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`get_leagues`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum GetLeaguesError {
31    Status500(models::EsportsServerError),
32    UnknownValue(serde_json::Value),
33}
34
35/// struct for typed errors of method [`get_matches`]
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum GetMatchesError {
39    Status404(models::EsportsServerError),
40    Status500(models::EsportsServerError),
41    Status400(models::EsportsServerError),
42    UnknownValue(serde_json::Value),
43}
44
45/// struct for typed errors of method [`get_matches_for_tournament`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum GetMatchesForTournamentError {
49    Status404(models::EsportsServerError),
50    Status500(models::EsportsServerError),
51    UnknownValue(serde_json::Value),
52}
53
54/// struct for typed errors of method [`get_most_recent_tournament`]
55#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum GetMostRecentTournamentError {
58    Status404(models::EsportsServerError),
59    Status500(models::EsportsServerError),
60    UnknownValue(serde_json::Value),
61}
62
63/// struct for typed errors of method [`get_ongoing_tournanments`]
64#[derive(Debug, Clone, Serialize, Deserialize)]
65#[serde(untagged)]
66pub enum GetOngoingTournanmentsError {
67    Status500(models::EsportsServerError),
68    UnknownValue(serde_json::Value),
69}
70
71/// struct for typed errors of method [`get_players_on_team`]
72#[derive(Debug, Clone, Serialize, Deserialize)]
73#[serde(untagged)]
74pub enum GetPlayersOnTeamError {
75    Status404(models::EsportsServerError),
76    Status500(models::EsportsServerError),
77    UnknownValue(serde_json::Value),
78}
79
80/// struct for typed errors of method [`get_team_by_code`]
81#[derive(Debug, Clone, Serialize, Deserialize)]
82#[serde(untagged)]
83pub enum GetTeamByCodeError {
84    Status404(models::EsportsServerError),
85    Status500(models::EsportsServerError),
86    UnknownValue(serde_json::Value),
87}
88
89/// struct for typed errors of method [`get_teams`]
90#[derive(Debug, Clone, Serialize, Deserialize)]
91#[serde(untagged)]
92pub enum GetTeamsError {
93    Status500(models::EsportsServerError),
94    UnknownValue(serde_json::Value),
95}
96
97/// struct for typed errors of method [`get_tournament`]
98#[derive(Debug, Clone, Serialize, Deserialize)]
99#[serde(untagged)]
100pub enum GetTournamentError {
101    Status404(models::EsportsServerError),
102    Status500(models::EsportsServerError),
103    UnknownValue(serde_json::Value),
104}
105
106/// struct for typed errors of method [`get_tournaments_for_league`]
107#[derive(Debug, Clone, Serialize, Deserialize)]
108#[serde(untagged)]
109pub enum GetTournamentsForLeagueError {
110    Status404(models::EsportsServerError),
111    Status500(models::EsportsServerError),
112    UnknownValue(serde_json::Value),
113}
114
115
116pub async fn get_league_by_code(configuration: &configuration::Configuration, league_id: &str) -> Result<models::League, Error<GetLeagueByCodeError>> {
117    // add a prefix to parameters to efficiently prevent name collisions
118    let p_path_league_id = league_id;
119
120    let uri_str = format!("{}/leagues/{leagueId}", configuration.base_path, leagueId=crate::apis::urlencode(p_path_league_id));
121    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
122
123    if let Some(ref user_agent) = configuration.user_agent {
124        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
125    }
126
127    let req = req_builder.build()?;
128    let resp = configuration.client.execute(req).await?;
129
130    let status = resp.status();
131    let content_type = resp
132        .headers()
133        .get("content-type")
134        .and_then(|v| v.to_str().ok())
135        .unwrap_or("application/octet-stream");
136    let content_type = super::ContentType::from(content_type);
137
138    if !status.is_client_error() && !status.is_server_error() {
139        let content = resp.text().await?;
140        match content_type {
141            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
142            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::League`"))),
143            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::League`")))),
144        }
145    } else {
146        let content = resp.text().await?;
147        let entity: Option<GetLeagueByCodeError> = serde_json::from_str(&content).ok();
148        Err(Error::ResponseError(ResponseContent { status, content, entity }))
149    }
150}
151
152pub async fn get_leagues(configuration: &configuration::Configuration, ) -> Result<Vec<models::League>, Error<GetLeaguesError>> {
153
154    let uri_str = format!("{}/leagues", configuration.base_path);
155    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
156
157    if let Some(ref user_agent) = configuration.user_agent {
158        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
159    }
160
161    let req = req_builder.build()?;
162    let resp = configuration.client.execute(req).await?;
163
164    let status = resp.status();
165    let content_type = resp
166        .headers()
167        .get("content-type")
168        .and_then(|v| v.to_str().ok())
169        .unwrap_or("application/octet-stream");
170    let content_type = super::ContentType::from(content_type);
171
172    if !status.is_client_error() && !status.is_server_error() {
173        let content = resp.text().await?;
174        match content_type {
175            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
176            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::League&gt;`"))),
177            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::League&gt;`")))),
178        }
179    } else {
180        let content = resp.text().await?;
181        let entity: Option<GetLeaguesError> = serde_json::from_str(&content).ok();
182        Err(Error::ResponseError(ResponseContent { status, content, entity }))
183    }
184}
185
186/// Get matches, one of tournament or league is required
187pub async fn get_matches(configuration: &configuration::Configuration, league_id: Option<&str>, tournament_id: Option<&str>) -> Result<Vec<models::Match>, Error<GetMatchesError>> {
188    // add a prefix to parameters to efficiently prevent name collisions
189    let p_query_league_id = league_id;
190    let p_query_tournament_id = tournament_id;
191
192    let uri_str = format!("{}/matches", configuration.base_path);
193    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
194
195    if let Some(ref param_value) = p_query_league_id {
196        req_builder = req_builder.query(&[("leagueId", &param_value.to_string())]);
197    }
198    if let Some(ref param_value) = p_query_tournament_id {
199        req_builder = req_builder.query(&[("tournamentId", &param_value.to_string())]);
200    }
201    if let Some(ref user_agent) = configuration.user_agent {
202        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
203    }
204
205    let req = req_builder.build()?;
206    let resp = configuration.client.execute(req).await?;
207
208    let status = resp.status();
209    let content_type = resp
210        .headers()
211        .get("content-type")
212        .and_then(|v| v.to_str().ok())
213        .unwrap_or("application/octet-stream");
214    let content_type = super::ContentType::from(content_type);
215
216    if !status.is_client_error() && !status.is_server_error() {
217        let content = resp.text().await?;
218        match content_type {
219            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
220            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Match&gt;`"))),
221            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::Match&gt;`")))),
222        }
223    } else {
224        let content = resp.text().await?;
225        let entity: Option<GetMatchesError> = serde_json::from_str(&content).ok();
226        Err(Error::ResponseError(ResponseContent { status, content, entity }))
227    }
228}
229
230pub async fn get_matches_for_tournament(configuration: &configuration::Configuration, tournament_id: &str) -> Result<Vec<models::Match>, Error<GetMatchesForTournamentError>> {
231    // add a prefix to parameters to efficiently prevent name collisions
232    let p_path_tournament_id = tournament_id;
233
234    let uri_str = format!("{}/matches/{tournamentId}", configuration.base_path, tournamentId=crate::apis::urlencode(p_path_tournament_id));
235    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
236
237    if let Some(ref user_agent) = configuration.user_agent {
238        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
239    }
240
241    let req = req_builder.build()?;
242    let resp = configuration.client.execute(req).await?;
243
244    let status = resp.status();
245    let content_type = resp
246        .headers()
247        .get("content-type")
248        .and_then(|v| v.to_str().ok())
249        .unwrap_or("application/octet-stream");
250    let content_type = super::ContentType::from(content_type);
251
252    if !status.is_client_error() && !status.is_server_error() {
253        let content = resp.text().await?;
254        match content_type {
255            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
256            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Match&gt;`"))),
257            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::Match&gt;`")))),
258        }
259    } else {
260        let content = resp.text().await?;
261        let entity: Option<GetMatchesForTournamentError> = serde_json::from_str(&content).ok();
262        Err(Error::ResponseError(ResponseContent { status, content, entity }))
263    }
264}
265
266pub async fn get_most_recent_tournament(configuration: &configuration::Configuration, league_id: &str) -> Result<models::Tournament, Error<GetMostRecentTournamentError>> {
267    // add a prefix to parameters to efficiently prevent name collisions
268    let p_path_league_id = league_id;
269
270    let uri_str = format!("{}/most-recent-tournament/{leagueId}", configuration.base_path, leagueId=crate::apis::urlencode(p_path_league_id));
271    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
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
277    let req = req_builder.build()?;
278    let resp = configuration.client.execute(req).await?;
279
280    let status = resp.status();
281    let content_type = resp
282        .headers()
283        .get("content-type")
284        .and_then(|v| v.to_str().ok())
285        .unwrap_or("application/octet-stream");
286    let content_type = super::ContentType::from(content_type);
287
288    if !status.is_client_error() && !status.is_server_error() {
289        let content = resp.text().await?;
290        match content_type {
291            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
292            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Tournament`"))),
293            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::Tournament`")))),
294        }
295    } else {
296        let content = resp.text().await?;
297        let entity: Option<GetMostRecentTournamentError> = serde_json::from_str(&content).ok();
298        Err(Error::ResponseError(ResponseContent { status, content, entity }))
299    }
300}
301
302pub async fn get_ongoing_tournanments(configuration: &configuration::Configuration, ) -> Result<Vec<models::Tournament>, Error<GetOngoingTournanmentsError>> {
303
304    let uri_str = format!("{}/ongoing-tournaments", configuration.base_path);
305    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
306
307    if let Some(ref user_agent) = configuration.user_agent {
308        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
309    }
310
311    let req = req_builder.build()?;
312    let resp = configuration.client.execute(req).await?;
313
314    let status = resp.status();
315    let content_type = resp
316        .headers()
317        .get("content-type")
318        .and_then(|v| v.to_str().ok())
319        .unwrap_or("application/octet-stream");
320    let content_type = super::ContentType::from(content_type);
321
322    if !status.is_client_error() && !status.is_server_error() {
323        let content = resp.text().await?;
324        match content_type {
325            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
326            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Tournament&gt;`"))),
327            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::Tournament&gt;`")))),
328        }
329    } else {
330        let content = resp.text().await?;
331        let entity: Option<GetOngoingTournanmentsError> = serde_json::from_str(&content).ok();
332        Err(Error::ResponseError(ResponseContent { status, content, entity }))
333    }
334}
335
336pub async fn get_players_on_team(configuration: &configuration::Configuration, team_id: &str) -> Result<Vec<models::Player>, Error<GetPlayersOnTeamError>> {
337    // add a prefix to parameters to efficiently prevent name collisions
338    let p_path_team_id = team_id;
339
340    let uri_str = format!("{}/players/{teamId}", configuration.base_path, teamId=crate::apis::urlencode(p_path_team_id));
341    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
342
343    if let Some(ref user_agent) = configuration.user_agent {
344        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
345    }
346
347    let req = req_builder.build()?;
348    let resp = configuration.client.execute(req).await?;
349
350    let status = resp.status();
351    let content_type = resp
352        .headers()
353        .get("content-type")
354        .and_then(|v| v.to_str().ok())
355        .unwrap_or("application/octet-stream");
356    let content_type = super::ContentType::from(content_type);
357
358    if !status.is_client_error() && !status.is_server_error() {
359        let content = resp.text().await?;
360        match content_type {
361            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
362            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Player&gt;`"))),
363            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::Player&gt;`")))),
364        }
365    } else {
366        let content = resp.text().await?;
367        let entity: Option<GetPlayersOnTeamError> = serde_json::from_str(&content).ok();
368        Err(Error::ResponseError(ResponseContent { status, content, entity }))
369    }
370}
371
372pub async fn get_team_by_code(configuration: &configuration::Configuration, team_id: &str) -> Result<models::Team, Error<GetTeamByCodeError>> {
373    // add a prefix to parameters to efficiently prevent name collisions
374    let p_path_team_id = team_id;
375
376    let uri_str = format!("{}/teams/{teamId}", configuration.base_path, teamId=crate::apis::urlencode(p_path_team_id));
377    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
378
379    if let Some(ref user_agent) = configuration.user_agent {
380        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
381    }
382
383    let req = req_builder.build()?;
384    let resp = configuration.client.execute(req).await?;
385
386    let status = resp.status();
387    let content_type = resp
388        .headers()
389        .get("content-type")
390        .and_then(|v| v.to_str().ok())
391        .unwrap_or("application/octet-stream");
392    let content_type = super::ContentType::from(content_type);
393
394    if !status.is_client_error() && !status.is_server_error() {
395        let content = resp.text().await?;
396        match content_type {
397            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
398            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Team`"))),
399            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::Team`")))),
400        }
401    } else {
402        let content = resp.text().await?;
403        let entity: Option<GetTeamByCodeError> = serde_json::from_str(&content).ok();
404        Err(Error::ResponseError(ResponseContent { status, content, entity }))
405    }
406}
407
408pub async fn get_teams(configuration: &configuration::Configuration, ) -> Result<Vec<models::Team>, Error<GetTeamsError>> {
409
410    let uri_str = format!("{}/teams", configuration.base_path);
411    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
412
413    if let Some(ref user_agent) = configuration.user_agent {
414        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
415    }
416
417    let req = req_builder.build()?;
418    let resp = configuration.client.execute(req).await?;
419
420    let status = resp.status();
421    let content_type = resp
422        .headers()
423        .get("content-type")
424        .and_then(|v| v.to_str().ok())
425        .unwrap_or("application/octet-stream");
426    let content_type = super::ContentType::from(content_type);
427
428    if !status.is_client_error() && !status.is_server_error() {
429        let content = resp.text().await?;
430        match content_type {
431            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
432            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Team&gt;`"))),
433            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::Team&gt;`")))),
434        }
435    } else {
436        let content = resp.text().await?;
437        let entity: Option<GetTeamsError> = serde_json::from_str(&content).ok();
438        Err(Error::ResponseError(ResponseContent { status, content, entity }))
439    }
440}
441
442pub async fn get_tournament(configuration: &configuration::Configuration, tournament_id: &str) -> Result<models::Tournament, Error<GetTournamentError>> {
443    // add a prefix to parameters to efficiently prevent name collisions
444    let p_path_tournament_id = tournament_id;
445
446    let uri_str = format!("{}/tournament/{tournamentId}", configuration.base_path, tournamentId=crate::apis::urlencode(p_path_tournament_id));
447    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
448
449    if let Some(ref user_agent) = configuration.user_agent {
450        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
451    }
452
453    let req = req_builder.build()?;
454    let resp = configuration.client.execute(req).await?;
455
456    let status = resp.status();
457    let content_type = resp
458        .headers()
459        .get("content-type")
460        .and_then(|v| v.to_str().ok())
461        .unwrap_or("application/octet-stream");
462    let content_type = super::ContentType::from(content_type);
463
464    if !status.is_client_error() && !status.is_server_error() {
465        let content = resp.text().await?;
466        match content_type {
467            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
468            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Tournament`"))),
469            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::Tournament`")))),
470        }
471    } else {
472        let content = resp.text().await?;
473        let entity: Option<GetTournamentError> = serde_json::from_str(&content).ok();
474        Err(Error::ResponseError(ResponseContent { status, content, entity }))
475    }
476}
477
478pub async fn get_tournaments_for_league(configuration: &configuration::Configuration, league_id: &str) -> Result<Vec<models::Tournament>, Error<GetTournamentsForLeagueError>> {
479    // add a prefix to parameters to efficiently prevent name collisions
480    let p_path_league_id = league_id;
481
482    let uri_str = format!("{}/tournaments/{leagueId}", configuration.base_path, leagueId=crate::apis::urlencode(p_path_league_id));
483    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
484
485    if let Some(ref user_agent) = configuration.user_agent {
486        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
487    }
488
489    let req = req_builder.build()?;
490    let resp = configuration.client.execute(req).await?;
491
492    let status = resp.status();
493    let content_type = resp
494        .headers()
495        .get("content-type")
496        .and_then(|v| v.to_str().ok())
497        .unwrap_or("application/octet-stream");
498    let content_type = super::ContentType::from(content_type);
499
500    if !status.is_client_error() && !status.is_server_error() {
501        let content = resp.text().await?;
502        match content_type {
503            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
504            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Tournament&gt;`"))),
505            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::Tournament&gt;`")))),
506        }
507    } else {
508        let content = resp.text().await?;
509        let entity: Option<GetTournamentsForLeagueError> = serde_json::from_str(&content).ok();
510        Err(Error::ResponseError(ResponseContent { status, content, entity }))
511    }
512}
513