nhl_stats/sync/
players_api.rs

1/*
2 * NHL API
3 *
4 * Documenting the publicly accessible portions of the NHL API.
5 *
6 * The version of the OpenAPI document: 1.0.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11use std::rc::Rc;
12use std::borrow::Borrow;
13
14use reqwest;
15
16use super::{Error, configuration};
17
18pub struct PlayersApiClient {
19    configuration: Rc<configuration::Configuration>,
20}
21
22impl PlayersApiClient {
23    pub fn new(configuration: Rc<configuration::Configuration>) -> PlayersApiClient {
24        PlayersApiClient {
25            configuration: configuration,
26        }
27    }
28}
29
30pub trait PlayersApi {
31    fn get_player(&self, id: u32) -> Result<crate::models::Players, Error>;
32    fn get_player_stats(&self, id: u32, stats: crate::models::EnumStatTypes, season: &str) -> Result<crate::models::PlayerStats, Error>;
33}
34
35impl PlayersApi for PlayersApiClient {
36    fn get_player(&self, id: u32) -> Result<crate::models::Players, Error> {
37        let configuration: &configuration::Configuration = self.configuration.borrow();
38        let client = &configuration.client;
39
40        let uri_str = format!("{}/people/{id}", configuration.base_path, id=id);
41        let mut req_builder = client.get(uri_str.as_str());
42
43        if let Some(ref user_agent) = configuration.user_agent {
44            req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
45        }
46
47        // send request
48        let req = req_builder.build()?;
49
50        Ok(client.execute(req)?.error_for_status()?.json()?)
51    }
52
53    fn get_player_stats(&self, id: u32, stats: crate::models::EnumStatTypes, season: &str) -> Result<crate::models::PlayerStats, Error> {
54        let configuration: &configuration::Configuration = self.configuration.borrow();
55        let client = &configuration.client;
56
57        let uri_str = format!("{}/people/{id}/stats", configuration.base_path, id=id);
58        let mut req_builder = client.get(uri_str.as_str());
59
60        req_builder = req_builder.query(&[("stats", &stats.to_string())]);
61        req_builder = req_builder.query(&[("season", &season.to_string())]);
62        if let Some(ref user_agent) = configuration.user_agent {
63            req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
64        }
65
66        // send request
67        let req = req_builder.build()?;
68
69        Ok(client.execute(req)?.error_for_status()?.json()?)
70    }
71
72}