chesscom_openapi/apis/
default_api.rs

1/*
2 * Chess
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: 1.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
19/*
20/// struct for typed errors of method `get_chess_games_archives`
21#[derive(Debug, Clone, Serialize, Deserialize)]
22#[serde(untagged)]
23pub enum GetChessGamesArchivesError {
24    Status404(crate::models::Error),
25    Status429(crate::models::Error),
26    UnknownValue(serde_json::Value),
27}
28
29/// struct for typed errors of method `get_chess_games_for_month`
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum GetChessGamesForMonthError {
33    Status404(crate::models::Error),
34    Status429(crate::models::Error),
35    UnknownValue(serde_json::Value),
36}
37
38/// struct for typed errors of method `get_chess_games_for_month_pgn`
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum GetChessGamesForMonthPgnError {
42    Status404(crate::models::Error),
43    Status429(crate::models::Error),
44    UnknownValue(serde_json::Value),
45}
46
47/// struct for typed errors of method `get_daily_chess_games`
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum GetDailyChessGamesError {
51    Status404(crate::models::Error),
52    Status429(crate::models::Error),
53    UnknownValue(serde_json::Value),
54}
55
56/// struct for typed errors of method `get_daily_chess_games_to_move`
57#[derive(Debug, Clone, Serialize, Deserialize)]
58#[serde(untagged)]
59pub enum GetDailyChessGamesToMoveError {
60    Status404(crate::models::Error),
61    Status429(crate::models::Error),
62    UnknownValue(serde_json::Value),
63}
64
65/// struct for typed errors of method `get_player_online_status`
66#[derive(Debug, Clone, Serialize, Deserialize)]
67#[serde(untagged)]
68pub enum GetPlayerOnlineStatusError {
69    Status404(crate::models::Error),
70    Status429(crate::models::Error),
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method `get_player_profile`
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum GetPlayerProfileError {
78    Status404(crate::models::Error),
79    Status429(crate::models::Error),
80    UnknownValue(serde_json::Value),
81}
82
83/// struct for typed errors of method `get_player_stats`
84#[derive(Debug, Clone, Serialize, Deserialize)]
85#[serde(untagged)]
86pub enum GetPlayerStatsError {
87    Status404(crate::models::Error),
88    Status429(crate::models::Error),
89    UnknownValue(serde_json::Value),
90}
91
92/// struct for typed errors of method `get_titled_players`
93#[derive(Debug, Clone, Serialize, Deserialize)]
94#[serde(untagged)]
95pub enum GetTitledPlayersError {
96    Status404(crate::models::Error),
97    Status429(crate::models::Error),
98    UnknownValue(serde_json::Value),
99}
100
101*/
102
103/// Errors that may be returned by the API
104#[derive(Debug, Clone, Serialize, Deserialize)]
105#[serde(untagged)]
106pub enum ApiError {
107    Status404(crate::models::Error),
108    Status429(crate::models::Error),
109    UnknownValue(serde_json::Value),
110}
111
112/// Get list of monthly archives available for this player
113pub async fn get_chess_games_archives(configuration: &configuration::Configuration, username: &str) -> Result<crate::models::InlineResponse2003, Error<ApiError>> {
114
115    let local_var_client = &configuration.client;
116
117    let local_var_uri_str = format!("{}/pub/player/{username}/games/archives", configuration.base_path, username=crate::apis::urlencode(username));
118    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
119
120    if let Some(ref local_var_user_agent) = configuration.user_agent {
121        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
122    }
123
124    let local_var_req = local_var_req_builder.build()?;
125    let local_var_resp = local_var_client.execute(local_var_req).await?;
126
127    let local_var_status = local_var_resp.status();
128    let local_var_content = local_var_resp.text().await?;
129
130    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
131        serde_json::from_str(&local_var_content).map_err(Error::from)
132    } else {
133        let local_var_entity: Option<ApiError> = serde_json::from_str(&local_var_content).ok();
134        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
135        Err(Error::ResponseError(local_var_error))
136    }
137}
138
139/// Get list of Live and Daily Chess games that a player has finished
140pub async fn get_chess_games_for_month(configuration: &configuration::Configuration, username: &str, year: &str, month: &str) -> Result<crate::models::InlineResponse2004, Error<ApiError>> {
141
142    let local_var_client = &configuration.client;
143
144    let local_var_uri_str = format!("{}/pub/player/{username}/games/{year}/{month}", configuration.base_path, username=crate::apis::urlencode(username), year=crate::apis::urlencode(year), month=crate::apis::urlencode(month));
145    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
146
147    if let Some(ref local_var_user_agent) = configuration.user_agent {
148        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
149    }
150
151    let local_var_req = local_var_req_builder.build()?;
152    let local_var_resp = local_var_client.execute(local_var_req).await?;
153
154    let local_var_status = local_var_resp.status();
155    let local_var_content = local_var_resp.text().await?;
156
157    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
158        serde_json::from_str(&local_var_content).map_err(Error::from)
159    } else {
160        let local_var_entity: Option<ApiError> = serde_json::from_str(&local_var_content).ok();
161        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
162        Err(Error::ResponseError(local_var_error))
163    }
164}
165
166/// Get standard multi-game format PGN containing all games for a month
167pub async fn get_chess_games_for_month_pgn(configuration: &configuration::Configuration, username: &str, year: &str, month: &str) -> Result<String, Error<ApiError>> {
168
169    let local_var_client = &configuration.client;
170
171    let local_var_uri_str = format!("{}/pub/player/{username}/games/{year}/{month}/pgn", configuration.base_path, username=crate::apis::urlencode(username), year=crate::apis::urlencode(year), month=crate::apis::urlencode(month));
172    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
173
174    if let Some(ref local_var_user_agent) = configuration.user_agent {
175        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
176    }
177
178    let local_var_req = local_var_req_builder.build()?;
179    let local_var_resp = local_var_client.execute(local_var_req).await?;
180
181    let local_var_status = local_var_resp.status();
182    let local_var_content = local_var_resp.text().await?;
183
184    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
185        serde_json::from_str(&local_var_content).map_err(Error::from)
186    } else {
187        let local_var_entity: Option<ApiError> = serde_json::from_str(&local_var_content).ok();
188        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
189        Err(Error::ResponseError(local_var_error))
190    }
191}
192
193/// Get list of Daily Chess games that a player is currently playing
194pub async fn get_daily_chess_games(configuration: &configuration::Configuration, username: &str) -> Result<crate::models::InlineResponse2001, Error<ApiError>> {
195
196    let local_var_client = &configuration.client;
197
198    let local_var_uri_str = format!("{}/pub/player/{username}/games", configuration.base_path, username=crate::apis::urlencode(username));
199    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
200
201    if let Some(ref local_var_user_agent) = configuration.user_agent {
202        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
203    }
204
205    let local_var_req = local_var_req_builder.build()?;
206    let local_var_resp = local_var_client.execute(local_var_req).await?;
207
208    let local_var_status = local_var_resp.status();
209    let local_var_content = local_var_resp.text().await?;
210
211    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
212        serde_json::from_str(&local_var_content).map_err(Error::from)
213    } else {
214        let local_var_entity: Option<ApiError> = serde_json::from_str(&local_var_content).ok();
215        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
216        Err(Error::ResponseError(local_var_error))
217    }
218}
219
220/// Get list of Daily Chess games where it is the player's turn to move
221pub async fn get_daily_chess_games_to_move(configuration: &configuration::Configuration, username: &str) -> Result<crate::models::InlineResponse2002, Error<ApiError>> {
222
223    let local_var_client = &configuration.client;
224
225    let local_var_uri_str = format!("{}/pub/player/{username}/games/to-move", configuration.base_path, username=crate::apis::urlencode(username));
226    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
227
228    if let Some(ref local_var_user_agent) = configuration.user_agent {
229        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
230    }
231
232    let local_var_req = local_var_req_builder.build()?;
233    let local_var_resp = local_var_client.execute(local_var_req).await?;
234
235    let local_var_status = local_var_resp.status();
236    let local_var_content = local_var_resp.text().await?;
237
238    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
239        serde_json::from_str(&local_var_content).map_err(Error::from)
240    } else {
241        let local_var_entity: Option<ApiError> = serde_json::from_str(&local_var_content).ok();
242        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
243        Err(Error::ResponseError(local_var_error))
244    }
245}
246
247/// Tells if a user has been online in the last five minutes.
248pub async fn get_player_online_status(configuration: &configuration::Configuration, username: &str) -> Result<crate::models::InlineResponse200, Error<ApiError>> {
249
250    let local_var_client = &configuration.client;
251
252    let local_var_uri_str = format!("{}/pub/player/{username}/is-online", configuration.base_path, username=crate::apis::urlencode(username));
253    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
254
255    if let Some(ref local_var_user_agent) = configuration.user_agent {
256        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
257    }
258
259    let local_var_req = local_var_req_builder.build()?;
260    let local_var_resp = local_var_client.execute(local_var_req).await?;
261
262    let local_var_status = local_var_resp.status();
263    let local_var_content = local_var_resp.text().await?;
264
265    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
266        serde_json::from_str(&local_var_content).map_err(Error::from)
267    } else {
268        let local_var_entity: Option<ApiError> = serde_json::from_str(&local_var_content).ok();
269        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
270        Err(Error::ResponseError(local_var_error))
271    }
272}
273
274/// Get additional details about a player in a game.
275pub async fn get_player_profile(configuration: &configuration::Configuration, username: &str) -> Result<crate::models::Profile, Error<ApiError>> {
276
277    let local_var_client = &configuration.client;
278
279    let local_var_uri_str = format!("{}/pub/player/{username}", configuration.base_path, username=crate::apis::urlencode(username));
280    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
281
282    if let Some(ref local_var_user_agent) = configuration.user_agent {
283        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
284    }
285
286    let local_var_req = local_var_req_builder.build()?;
287    let local_var_resp = local_var_client.execute(local_var_req).await?;
288
289    let local_var_status = local_var_resp.status();
290    let local_var_content = local_var_resp.text().await?;
291
292    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
293        serde_json::from_str(&local_var_content).map_err(Error::from)
294    } else {
295        let local_var_entity: Option<ApiError> = serde_json::from_str(&local_var_content).ok();
296        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
297        Err(Error::ResponseError(local_var_error))
298    }
299}
300
301/// Get ratings, win/loss, and other stats about a player's game play, tactics, lessons and Puzzle Rush score.
302pub async fn get_player_stats(configuration: &configuration::Configuration, username: &str) -> Result<crate::models::PlayerStats, Error<ApiError>> {
303
304    let local_var_client = &configuration.client;
305
306    let local_var_uri_str = format!("{}/pub/player/{username}/stats", configuration.base_path, username=crate::apis::urlencode(username));
307    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
308
309    if let Some(ref local_var_user_agent) = configuration.user_agent {
310        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
311    }
312
313    let local_var_req = local_var_req_builder.build()?;
314    let local_var_resp = local_var_client.execute(local_var_req).await?;
315
316    let local_var_status = local_var_resp.status();
317    let local_var_content = local_var_resp.text().await?;
318
319    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
320        serde_json::from_str(&local_var_content).map_err(Error::from)
321    } else {
322        let local_var_entity: Option<ApiError> = serde_json::from_str(&local_var_content).ok();
323        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
324        Err(Error::ResponseError(local_var_error))
325    }
326}
327
328/// List of titled-player usernames.
329pub async fn get_titled_players(configuration: &configuration::Configuration, title: crate::models::Title) -> Result<Vec<String>, Error<ApiError>> {
330
331    let local_var_client = &configuration.client;
332
333    let local_var_uri_str = format!("{}/pub/titled/{title}", configuration.base_path, title=title);
334    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
335
336    if let Some(ref local_var_user_agent) = configuration.user_agent {
337        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
338    }
339
340    let local_var_req = local_var_req_builder.build()?;
341    let local_var_resp = local_var_client.execute(local_var_req).await?;
342
343    let local_var_status = local_var_resp.status();
344    let local_var_content = local_var_resp.text().await?;
345
346    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
347        serde_json::from_str(&local_var_content).map_err(Error::from)
348    } else {
349        let local_var_entity: Option<ApiError> = serde_json::from_str(&local_var_content).ok();
350        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
351        Err(Error::ResponseError(local_var_error))
352    }
353}
354