From 8934790c1cab013536f06935486acc495e75f30d Mon Sep 17 00:00:00 2001 From: Mingwei Samuel Date: Fri, 21 May 2021 17:31:52 -0700 Subject: [PATCH] Upgrade srcgen to use requests --- Cargo.toml | 1 - src/config.rs | 33 ++- src/consts/champion.rs | 14 +- src/consts/game_mode.rs | 2 +- src/consts/map.rs | 2 +- src/consts/queue.rs | 2 +- src/consts/season.rs | 2 +- src/endpoints.rs | 387 ++++++++++++++++++++-------------- src/req/regional_requester.rs | 10 +- src/riot_api.rs | 21 +- srcgen/dotUtils.js | 27 +-- srcgen/endpoints.rs.dt | 18 +- 12 files changed, 298 insertions(+), 221 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 37dfd2a..c2d7bd9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,6 @@ serde_repr = "0.1" strum = "0.20" strum_macros = "0.20" tokio = { version = "1", default-features = false, features = [ "time" ] } -url = "2" [dev-dependencies] colored = "2" diff --git a/src/config.rs b/src/config.rs index 1587bf0..c783aed 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,13 +2,14 @@ use std::time::Duration; use reqwest::ClientBuilder; -use reqwest::header::{HeaderMap, HeaderValue}; +use reqwest::header::{ HeaderMap, HeaderValue }; /// Configuration for instantiating RiotApi. /// /// #[derive(Debug)] pub struct RiotApiConfig { + pub(crate) base_url: String, pub(crate) retries: u8, pub(crate) burst_pct: f32, pub(crate) duration_overhead: Duration, @@ -22,10 +23,15 @@ impl RiotApiConfig { /// this default header with the Riot API key as the value. const RIOT_KEY_HEADER: &'static str = "X-Riot-Token"; + /// `"https://{}.api.riotgames.com"` + /// + /// Default base URL, including `{}` placeholder for region platform. + pub const DEFAULT_BASE_URL: &'static str = "https://{}.api.riotgames.com"; + /// `3` /// /// Default number of retries. - pub const PRECONFIG_RETRIES: u8 = 3; + pub const DEFAULT_RETRIES: u8 = 3; /// `0.99` /// @@ -48,14 +54,14 @@ impl RiotApiConfig { /// Creates a new `RiotApiConfig` with the given `api_key` with the following /// configuration: /// - /// * `retries = 3` (`RiotApiConfig::PRECONFIG_RETRIES`). + /// * `retries = 3` (`RiotApiConfig::DEFAULT_RETRIES`). /// * `purst_pct = 0.99` (`preconfig_burst`). /// * `duration_overhead = 989 ms` (`preconfig_burst`). /// /// `api_key` should be a Riot Games API key from /// [https://developer.riotgames.com/](https://developer.riotgames.com/), /// and should look like `"RGAPI-01234567-89ab-cdef-0123-456789abcdef"`. - pub fn with_key>(api_key: T) -> Self { + pub fn with_key(api_key: impl AsRef<[u8]>) -> Self { let mut default_headers = HeaderMap::new(); default_headers.insert( Self::RIOT_KEY_HEADER, @@ -63,7 +69,8 @@ impl RiotApiConfig { ); Self { - retries: Self::PRECONFIG_RETRIES, + base_url: Self::DEFAULT_BASE_URL.into(), + retries: Self::DEFAULT_RETRIES, burst_pct: Self::PRECONFIG_BURST_BURST_PCT, duration_overhead: Self::PRECONFIG_BURST_DURATION_OVERHEAD, client_builder: Some( @@ -78,12 +85,13 @@ impl RiotApiConfig { /// The client builder default headers should include a value for /// `RiotApiConfig::RIOT_KEY_HEADER`, otherwise authentication will fail. /// - /// * `retries = 3` (`RiotApiConfig::PRECONFIG_RETRIES`). + /// * `retries = 3` (`RiotApiConfig::DEFAULT_RETRIES`). /// * `purst_pct = 0.99` (`preconfig_burst`). /// * `duration_overhead = 989 ms` (`preconfig_burst`). pub fn with_client_builder(client_builder: ClientBuilder) -> Self { Self { - retries: Self::PRECONFIG_RETRIES, + base_url: Self::DEFAULT_BASE_URL.to_owned(), + retries: Self::DEFAULT_RETRIES, burst_pct: Self::PRECONFIG_BURST_BURST_PCT, duration_overhead: Self::PRECONFIG_BURST_DURATION_OVERHEAD, client_builder: Some(client_builder), @@ -118,6 +126,17 @@ impl RiotApiConfig { self } + /// Set the base url for requests. The string should contain a `"{}"` + /// literal which will be replaced with the region platform name. (However + /// multiple or zero `"{}"`s may be included if needed). + /// + /// # Returns + /// `self`, for chaining. + pub fn set_base_url(mut self, base_url: impl Into) -> Self { + self.base_url = base_url.into(); + self + } + /// Set number of times to retry requests. Naturally, only retryable requests /// will be retried: responses with status codes 5xx or 429 (after waiting /// for retry-after headers). A value of `0` means one request will be sent diff --git a/src/consts/champion.rs b/src/consts/champion.rs index 761cb60..bfc2f2f 100644 --- a/src/consts/champion.rs +++ b/src/consts/champion.rs @@ -1,9 +1,9 @@ -/////////////////////////////////////////////// -// // -// ! // -// This file is automatically generated! // -// Do not directly edit! // -// // +/////////////////////////////////////////////// +// // +// ! // +// This file is automatically generated! // +// Do not directly edit! // +// // /////////////////////////////////////////////// use num_enum::{ IntoPrimitive, TryFromPrimitive }; @@ -16,7 +16,7 @@ use strum_macros::{ EnumString, EnumIter, Display, AsRefStr, IntoStaticStr }; /// NAME (`IDENTIFIER`, ID). /// /// Implements [IntoEnumIterator](super::IntoEnumIterator). -#[cfg_attr(feature = "nightly", non_exhaustive)] +#[non_exhaustive] #[derive(Debug, Copy, Clone)] #[derive(IntoPrimitive, TryFromPrimitive)] #[derive(Serialize_repr, Deserialize_repr)] diff --git a/src/consts/game_mode.rs b/src/consts/game_mode.rs index 8aef46f..12f5b72 100644 --- a/src/consts/game_mode.rs +++ b/src/consts/game_mode.rs @@ -10,7 +10,7 @@ use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr }; /// League of Legends game mode, such as Classic, /// ARAM, URF, One For All, Ascension, etc. -#[cfg_attr(feature = "nightly", non_exhaustive)] +#[non_exhaustive] #[derive(Debug, Copy, Clone)] #[derive(Eq, PartialEq, Hash)] #[derive(EnumString, Display, AsRefStr, IntoStaticStr)] diff --git a/src/consts/map.rs b/src/consts/map.rs index 74860f3..e717e7f 100644 --- a/src/consts/map.rs +++ b/src/consts/map.rs @@ -10,7 +10,7 @@ use serde_repr::{ Serialize_repr, Deserialize_repr }; use num_enum::{ IntoPrimitive, TryFromPrimitive }; /// League of Legends maps. -#[cfg_attr(feature = "nightly", non_exhaustive)] +#[non_exhaustive] #[derive(Debug, Copy, Clone)] #[derive(Eq, PartialEq, Hash, PartialOrd, Ord)] #[derive(Serialize_repr, Deserialize_repr)] diff --git a/src/consts/queue.rs b/src/consts/queue.rs index 40bd32b..1679d6c 100644 --- a/src/consts/queue.rs +++ b/src/consts/queue.rs @@ -10,7 +10,7 @@ use serde_repr::{ Serialize_repr, Deserialize_repr }; use num_enum::{ IntoPrimitive, TryFromPrimitive }; /// League of Legends matchmaking queue. -#[cfg_attr(feature = "nightly", non_exhaustive)] +#[non_exhaustive] #[derive(Debug, Copy, Clone)] #[derive(Eq, PartialEq)] #[derive(Serialize_repr, Deserialize_repr)] diff --git a/src/consts/season.rs b/src/consts/season.rs index 79f5b11..4a935c4 100644 --- a/src/consts/season.rs +++ b/src/consts/season.rs @@ -10,7 +10,7 @@ use serde_repr::{ Serialize_repr, Deserialize_repr }; use num_enum::{ IntoPrimitive, TryFromPrimitive }; /// League of Legends matchmaking seasons. -#[cfg_attr(feature = "nightly", non_exhaustive)] +#[non_exhaustive] #[derive(Debug, Copy, Clone)] #[derive(Eq, PartialEq, Hash, PartialOrd, Ord)] #[derive(Serialize_repr, Deserialize_repr)] diff --git a/src/endpoints.rs b/src/endpoints.rs index 51cfa24..3b192df 100644 --- a/src/endpoints.rs +++ b/src/endpoints.rs @@ -16,7 +16,7 @@ use crate::models::*; use std::future::Future; use std::vec::Vec; -use url::form_urlencoded::Serializer; +use reqwest::Method; use crate::Result; use crate::consts::Region; @@ -273,6 +273,7 @@ impl RiotApi { /// `account-v1` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct AccountV1<'a> { base: &'a RiotApi, } @@ -288,8 +289,9 @@ impl<'a> AccountV1<'a> { pub fn get_by_puuid(&self, region: Region, puuid: &str) -> impl Future> + 'a { - let path_string = format!("/riot/account/v1/accounts/by-puuid/{}", puuid); - self.base.get::("account-v1.getByPuuid", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/riot/account/v1/accounts/by-puuid/{}", puuid)); + self.base.execute::("account-v1.getByPuuid", region.into(), request) } /// Get account by riot id @@ -304,8 +306,9 @@ impl<'a> AccountV1<'a> { pub fn get_by_riot_id(&self, region: Region, game_name: &str, tag_line: &str) -> impl Future>> + 'a { - let path_string = format!("/riot/account/v1/accounts/by-riot-id/{}/{}", game_name, tag_line); - self.base.get_optional::("account-v1.getByRiotId", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/riot/account/v1/accounts/by-riot-id/{}/{}", game_name, tag_line)); + self.base.execute_optional::("account-v1.getByRiotId", region.into(), request) } /// Get active shard for a player @@ -320,8 +323,9 @@ impl<'a> AccountV1<'a> { pub fn get_active_shard(&self, region: Region, game: &str, puuid: &str) -> impl Future>> + 'a { - let path_string = format!("/riot/account/v1/active-shards/by-game/{}/by-puuid/{}", game, puuid); - self.base.get_optional::("account-v1.getActiveShard", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/riot/account/v1/active-shards/by-game/{}/by-puuid/{}", game, puuid)); + self.base.execute_optional::("account-v1.getActiveShard", region.into(), request) } } @@ -331,6 +335,7 @@ impl<'a> AccountV1<'a> { /// `champion-mastery-v4` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct ChampionMasteryV4<'a> { base: &'a RiotApi, } @@ -346,8 +351,9 @@ impl<'a> ChampionMasteryV4<'a> { pub fn get_all_champion_masteries(&self, region: Region, encrypted_summoner_id: &str) -> impl Future>> + 'a { - let path_string = format!("/lol/champion-mastery/v4/champion-masteries/by-summoner/{}", encrypted_summoner_id); - self.base.get::>("champion-mastery-v4.getAllChampionMasteries", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/champion-mastery/v4/champion-masteries/by-summoner/{}", encrypted_summoner_id)); + self.base.execute::>("champion-mastery-v4.getAllChampionMasteries", region.into(), request) } /// Get a champion mastery by player ID and champion ID. @@ -362,8 +368,9 @@ impl<'a> ChampionMasteryV4<'a> { pub fn get_champion_mastery(&self, region: Region, encrypted_summoner_id: &str, champion_id: crate::consts::Champion) -> impl Future>> + 'a { - let path_string = format!("/lol/champion-mastery/v4/champion-masteries/by-summoner/{}/by-champion/{}", encrypted_summoner_id, champion_id); - self.base.get_optional::("champion-mastery-v4.getChampionMastery", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/champion-mastery/v4/champion-masteries/by-summoner/{}/by-champion/{}", encrypted_summoner_id, champion_id)); + self.base.execute_optional::("champion-mastery-v4.getChampionMastery", region.into(), request) } /// Get a player's total champion mastery score, which is the sum of individual champion mastery levels. @@ -377,8 +384,9 @@ impl<'a> ChampionMasteryV4<'a> { pub fn get_champion_mastery_score(&self, region: Region, encrypted_summoner_id: &str) -> impl Future> + 'a { - let path_string = format!("/lol/champion-mastery/v4/scores/by-summoner/{}", encrypted_summoner_id); - self.base.get::("champion-mastery-v4.getChampionMasteryScore", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/champion-mastery/v4/scores/by-summoner/{}", encrypted_summoner_id)); + self.base.execute::("champion-mastery-v4.getChampionMasteryScore", region.into(), request) } } @@ -388,6 +396,7 @@ impl<'a> ChampionMasteryV4<'a> { /// `champion-v3` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct ChampionV3<'a> { base: &'a RiotApi, } @@ -402,8 +411,9 @@ impl<'a> ChampionV3<'a> { pub fn get_champion_info(&self, region: Region) -> impl Future> + 'a { - let path_string = "/lol/platform/v3/champion-rotations".to_owned(); - self.base.get::("champion-v3.getChampionInfo", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), "/lol/platform/v3/champion-rotations"); + self.base.execute::("champion-v3.getChampionInfo", region.into(), request) } } @@ -413,6 +423,7 @@ impl<'a> ChampionV3<'a> { /// `clash-v1` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct ClashV1<'a> { base: &'a RiotApi, } @@ -430,8 +441,9 @@ impl<'a> ClashV1<'a> { pub fn get_players_by_summoner(&self, region: Region, summoner_id: &str) -> impl Future>> + 'a { - let path_string = format!("/lol/clash/v1/players/by-summoner/{}", summoner_id); - self.base.get::>("clash-v1.getPlayersBySummoner", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/clash/v1/players/by-summoner/{}", summoner_id)); + self.base.execute::>("clash-v1.getPlayersBySummoner", region.into(), request) } /// Get team by ID. @@ -445,8 +457,9 @@ impl<'a> ClashV1<'a> { pub fn get_team_by_id(&self, region: Region, team_id: &str) -> impl Future>> + 'a { - let path_string = format!("/lol/clash/v1/teams/{}", team_id); - self.base.get_optional::("clash-v1.getTeamById", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/clash/v1/teams/{}", team_id)); + self.base.execute_optional::("clash-v1.getTeamById", region.into(), request) } /// Get all active or upcoming tournaments. @@ -459,8 +472,9 @@ impl<'a> ClashV1<'a> { pub fn get_tournaments(&self, region: Region) -> impl Future>> + 'a { - let path_string = "/lol/clash/v1/tournaments".to_owned(); - self.base.get::>("clash-v1.getTournaments", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), "/lol/clash/v1/tournaments"); + self.base.execute::>("clash-v1.getTournaments", region.into(), request) } /// Get tournament by team ID. @@ -474,8 +488,9 @@ impl<'a> ClashV1<'a> { pub fn get_tournament_by_team(&self, region: Region, team_id: &str) -> impl Future>> + 'a { - let path_string = format!("/lol/clash/v1/tournaments/by-team/{}", team_id); - self.base.get_optional::("clash-v1.getTournamentByTeam", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/clash/v1/tournaments/by-team/{}", team_id)); + self.base.execute_optional::("clash-v1.getTournamentByTeam", region.into(), request) } /// Get tournament by ID. @@ -489,8 +504,9 @@ impl<'a> ClashV1<'a> { pub fn get_tournament_by_id(&self, region: Region, tournament_id: i32) -> impl Future>> + 'a { - let path_string = format!("/lol/clash/v1/tournaments/{}", tournament_id); - self.base.get_optional::("clash-v1.getTournamentById", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/clash/v1/tournaments/{}", tournament_id)); + self.base.execute_optional::("clash-v1.getTournamentById", region.into(), request) } } @@ -500,6 +516,7 @@ impl<'a> ClashV1<'a> { /// `league-exp-v4` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct LeagueExpV4<'a> { base: &'a RiotApi, } @@ -518,11 +535,10 @@ impl<'a> LeagueExpV4<'a> { pub fn get_league_entries(&self, region: Region, queue: crate::consts::QueueType, tier: crate::consts::Tier, division: crate::consts::Division, page: Option) -> impl Future>> + 'a { - let mut query_params = Serializer::new(String::new()); - if let Some(page) = page { query_params.append_pair("page", &*page.to_string()); }; - let query_string = query_params.finish(); - let path_string = format!("/lol/league-exp/v4/entries/{}/{}/{}", queue, tier, division); - self.base.get::>("league-exp-v4.getLeagueEntries", region.into(), path_string, Some(query_string)) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/league-exp/v4/entries/{}/{}/{}", queue, tier, division)); + if let Some(page) = page { request = request.query(&[ ("page", page) ]); }; + self.base.execute::>("league-exp-v4.getLeagueEntries", region.into(), request) } } @@ -532,6 +548,7 @@ impl<'a> LeagueExpV4<'a> { /// `league-v4` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct LeagueV4<'a> { base: &'a RiotApi, } @@ -547,8 +564,9 @@ impl<'a> LeagueV4<'a> { pub fn get_challenger_league(&self, region: Region, queue: crate::consts::QueueType) -> impl Future> + 'a { - let path_string = format!("/lol/league/v4/challengerleagues/by-queue/{}", queue); - self.base.get::("league-v4.getChallengerLeague", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/league/v4/challengerleagues/by-queue/{}", queue)); + self.base.execute::("league-v4.getChallengerLeague", region.into(), request) } /// Get league entries in all queues for a given summoner ID. @@ -562,8 +580,9 @@ impl<'a> LeagueV4<'a> { pub fn get_league_entries_for_summoner(&self, region: Region, encrypted_summoner_id: &str) -> impl Future>> + 'a { - let path_string = format!("/lol/league/v4/entries/by-summoner/{}", encrypted_summoner_id); - self.base.get::>("league-v4.getLeagueEntriesForSummoner", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/league/v4/entries/by-summoner/{}", encrypted_summoner_id)); + self.base.execute::>("league-v4.getLeagueEntriesForSummoner", region.into(), request) } /// Get all the league entries. @@ -580,11 +599,10 @@ impl<'a> LeagueV4<'a> { pub fn get_league_entries(&self, region: Region, queue: crate::consts::QueueType, tier: crate::consts::Tier, division: crate::consts::Division, page: Option) -> impl Future>> + 'a { - let mut query_params = Serializer::new(String::new()); - if let Some(page) = page { query_params.append_pair("page", &*page.to_string()); }; - let query_string = query_params.finish(); - let path_string = format!("/lol/league/v4/entries/{}/{}/{}", queue, tier, division); - self.base.get::>("league-v4.getLeagueEntries", region.into(), path_string, Some(query_string)) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/league/v4/entries/{}/{}/{}", queue, tier, division)); + if let Some(page) = page { request = request.query(&[ ("page", page) ]); }; + self.base.execute::>("league-v4.getLeagueEntries", region.into(), request) } /// Get the grandmaster league of a specific queue. @@ -598,8 +616,9 @@ impl<'a> LeagueV4<'a> { pub fn get_grandmaster_league(&self, region: Region, queue: crate::consts::QueueType) -> impl Future> + 'a { - let path_string = format!("/lol/league/v4/grandmasterleagues/by-queue/{}", queue); - self.base.get::("league-v4.getGrandmasterLeague", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/league/v4/grandmasterleagues/by-queue/{}", queue)); + self.base.execute::("league-v4.getGrandmasterLeague", region.into(), request) } /// Get league with given ID, including inactive entries. @@ -613,8 +632,9 @@ impl<'a> LeagueV4<'a> { pub fn get_league_by_id(&self, region: Region, league_id: &str) -> impl Future>> + 'a { - let path_string = format!("/lol/league/v4/leagues/{}", league_id); - self.base.get_optional::("league-v4.getLeagueById", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/league/v4/leagues/{}", league_id)); + self.base.execute_optional::("league-v4.getLeagueById", region.into(), request) } /// Get the master league for given queue. @@ -628,8 +648,9 @@ impl<'a> LeagueV4<'a> { pub fn get_master_league(&self, region: Region, queue: crate::consts::QueueType) -> impl Future> + 'a { - let path_string = format!("/lol/league/v4/masterleagues/by-queue/{}", queue); - self.base.get::("league-v4.getMasterLeague", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/league/v4/masterleagues/by-queue/{}", queue)); + self.base.execute::("league-v4.getMasterLeague", region.into(), request) } } @@ -639,6 +660,7 @@ impl<'a> LeagueV4<'a> { /// `lol-status-v3` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct LolStatusV3<'a> { base: &'a RiotApi, } @@ -655,8 +677,9 @@ impl<'a> LolStatusV3<'a> { pub fn get_shard_data(&self, region: Region) -> impl Future> + 'a { - let path_string = "/lol/status/v3/shard-data".to_owned(); - self.base.get::("lol-status-v3.getShardData", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), "/lol/status/v3/shard-data"); + self.base.execute::("lol-status-v3.getShardData", region.into(), request) } } @@ -666,6 +689,7 @@ impl<'a> LolStatusV3<'a> { /// `lol-status-v4` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct LolStatusV4<'a> { base: &'a RiotApi, } @@ -680,8 +704,9 @@ impl<'a> LolStatusV4<'a> { pub fn get_platform_data(&self, region: Region) -> impl Future> + 'a { - let path_string = "/lol/status/v4/platform-data".to_owned(); - self.base.get::("lol-status-v4.getPlatformData", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), "/lol/status/v4/platform-data"); + self.base.execute::("lol-status-v4.getPlatformData", region.into(), request) } } @@ -691,6 +716,7 @@ impl<'a> LolStatusV4<'a> { /// `lor-deck-v1` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct LorDeckV1<'a> { base: &'a RiotApi, } @@ -702,6 +728,7 @@ impl<'a> LorDeckV1<'a> { /// `lor-inventory-v1` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct LorInventoryV1<'a> { base: &'a RiotApi, } @@ -713,6 +740,7 @@ impl<'a> LorInventoryV1<'a> { /// `lor-match-v1` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct LorMatchV1<'a> { base: &'a RiotApi, } @@ -728,8 +756,9 @@ impl<'a> LorMatchV1<'a> { pub fn get_match_ids_by_puuid(&self, region: Region, puuid: &str) -> impl Future>> + 'a { - let path_string = format!("/lor/match/v1/matches/by-puuid/{}/ids", puuid); - self.base.get::>("lor-match-v1.getMatchIdsByPUUID", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lor/match/v1/matches/by-puuid/{}/ids", puuid)); + self.base.execute::>("lor-match-v1.getMatchIdsByPUUID", region.into(), request) } /// Get match by id @@ -743,8 +772,9 @@ impl<'a> LorMatchV1<'a> { pub fn get_match(&self, region: Region, match_id: &str) -> impl Future> + 'a { - let path_string = format!("/lor/match/v1/matches/{}", match_id); - self.base.get::("lor-match-v1.getMatch", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lor/match/v1/matches/{}", match_id)); + self.base.execute::("lor-match-v1.getMatch", region.into(), request) } } @@ -754,6 +784,7 @@ impl<'a> LorMatchV1<'a> { /// `lor-ranked-v1` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct LorRankedV1<'a> { base: &'a RiotApi, } @@ -768,8 +799,9 @@ impl<'a> LorRankedV1<'a> { pub fn get_leaderboards(&self, region: Region) -> impl Future> + 'a { - let path_string = "/lor/ranked/v1/leaderboards".to_owned(); - self.base.get::("lor-ranked-v1.getLeaderboards", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), "/lor/ranked/v1/leaderboards"); + self.base.execute::("lor-ranked-v1.getLeaderboards", region.into(), request) } } @@ -779,6 +811,7 @@ impl<'a> LorRankedV1<'a> { /// `lor-status-v1` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct LorStatusV1<'a> { base: &'a RiotApi, } @@ -793,8 +826,9 @@ impl<'a> LorStatusV1<'a> { pub fn get_platform_data(&self, region: Region) -> impl Future> + 'a { - let path_string = "/lor/status/v1/platform-data".to_owned(); - self.base.get::("lor-status-v1.getPlatformData", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), "/lor/status/v1/platform-data"); + self.base.execute::("lor-status-v1.getPlatformData", region.into(), request) } } @@ -804,6 +838,7 @@ impl<'a> LorStatusV1<'a> { /// `match-v4` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct MatchV4<'a> { base: &'a RiotApi, } @@ -819,8 +854,9 @@ impl<'a> MatchV4<'a> { pub fn get_match_ids_by_tournament_code(&self, region: Region, tournament_code: &str) -> impl Future>> + 'a { - let path_string = format!("/lol/match/v4/matches/by-tournament-code/{}/ids", tournament_code); - self.base.get::>("match-v4.getMatchIdsByTournamentCode", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/match/v4/matches/by-tournament-code/{}/ids", tournament_code)); + self.base.execute::>("match-v4.getMatchIdsByTournamentCode", region.into(), request) } /// Get match by match ID. @@ -834,8 +870,9 @@ impl<'a> MatchV4<'a> { pub fn get_match(&self, region: Region, match_id: i64) -> impl Future>> + 'a { - let path_string = format!("/lol/match/v4/matches/{}", match_id); - self.base.get_optional::("match-v4.getMatch", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/match/v4/matches/{}", match_id)); + self.base.execute_optional::("match-v4.getMatch", region.into(), request) } /// Get match by match ID and tournament code. @@ -850,8 +887,9 @@ impl<'a> MatchV4<'a> { pub fn get_match_by_tournament_code(&self, region: Region, match_id: i64, tournament_code: &str) -> impl Future> + 'a { - let path_string = format!("/lol/match/v4/matches/{}/by-tournament-code/{}", match_id, tournament_code); - self.base.get::("match-v4.getMatchByTournamentCode", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/match/v4/matches/{}/by-tournament-code/{}", match_id, tournament_code)); + self.base.execute::("match-v4.getMatchByTournamentCode", region.into(), request) } /// Get matchlist for games played on given account ID and platform ID and filtered using given filter parameters, if any. @@ -878,17 +916,16 @@ impl<'a> MatchV4<'a> { pub fn get_matchlist(&self, region: Region, encrypted_account_id: &str, begin_time: Option, begin_index: Option, champion: Option<&[crate::consts::Champion]>, end_time: Option, end_index: Option, queue: Option<&[crate::consts::Queue]>, season: Option<&[crate::consts::Season]>) -> impl Future>> + 'a { - let mut query_params = Serializer::new(String::new()); - if let Some(begin_time) = begin_time { query_params.append_pair("beginTime", &*begin_time.to_string()); }; - if let Some(begin_index) = begin_index { query_params.append_pair("beginIndex", &*begin_index.to_string()); }; - if let Some(champion) = champion { query_params.extend_pairs(champion.iter().map(|w| ("champion", Into::::into(*w).to_string()))); }; - if let Some(end_time) = end_time { query_params.append_pair("endTime", &*end_time.to_string()); }; - if let Some(end_index) = end_index { query_params.append_pair("endIndex", &*end_index.to_string()); }; - if let Some(queue) = queue { query_params.extend_pairs(queue.iter().map(|w| ("queue", Into::::into(*w).to_string()))); }; - if let Some(season) = season { query_params.extend_pairs(season.iter().map(|w| ("season", Into::::into(*w).to_string()))); }; - let query_string = query_params.finish(); - let path_string = format!("/lol/match/v4/matchlists/by-account/{}", encrypted_account_id); - self.base.get_optional::("match-v4.getMatchlist", region.into(), path_string, Some(query_string)) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/match/v4/matchlists/by-account/{}", encrypted_account_id)); + if let Some(begin_time) = begin_time { request = request.query(&[ ("beginTime", begin_time) ]); }; + if let Some(begin_index) = begin_index { request = request.query(&[ ("beginIndex", begin_index) ]); }; + if let Some(champion) = champion { request = request.query(&*champion.iter().map(|w| ( "champion", w )).collect::>()); }; + if let Some(end_time) = end_time { request = request.query(&[ ("endTime", end_time) ]); }; + if let Some(end_index) = end_index { request = request.query(&[ ("endIndex", end_index) ]); }; + if let Some(queue) = queue { request = request.query(&*queue.iter().map(|w| ( "queue", w )).collect::>()); }; + if let Some(season) = season { request = request.query(&*season.iter().map(|w| ( "season", w )).collect::>()); }; + self.base.execute_optional::("match-v4.getMatchlist", region.into(), request) } /// Get match timeline by match ID. @@ -904,8 +941,9 @@ impl<'a> MatchV4<'a> { pub fn get_match_timeline(&self, region: Region, match_id: i64) -> impl Future>> + 'a { - let path_string = format!("/lol/match/v4/timelines/by-match/{}", match_id); - self.base.get_optional::("match-v4.getMatchTimeline", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/match/v4/timelines/by-match/{}", match_id)); + self.base.execute_optional::("match-v4.getMatchTimeline", region.into(), request) } } @@ -915,6 +953,7 @@ impl<'a> MatchV4<'a> { /// `match-v5` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct MatchV5<'a> { base: &'a RiotApi, } @@ -932,12 +971,11 @@ impl<'a> MatchV5<'a> { pub fn get_match_ids_by_puuid(&self, region: Region, puuid: &str, count: Option, start: Option) -> impl Future>> + 'a { - let mut query_params = Serializer::new(String::new()); - if let Some(count) = count { query_params.append_pair("count", &*count.to_string()); }; - if let Some(start) = start { query_params.append_pair("start", &*start.to_string()); }; - let query_string = query_params.finish(); - let path_string = format!("/lol/match/v5/matches/by-puuid/{}/ids", puuid); - self.base.get::>("match-v5.getMatchIdsByPUUID", region.into(), path_string, Some(query_string)) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/match/v5/matches/by-puuid/{}/ids", puuid)); + if let Some(count) = count { request = request.query(&[ ("count", count) ]); }; + if let Some(start) = start { request = request.query(&[ ("start", start) ]); }; + self.base.execute::>("match-v5.getMatchIdsByPUUID", region.into(), request) } /// Get a match by match id @@ -951,8 +989,9 @@ impl<'a> MatchV5<'a> { pub fn get_match(&self, region: Region, match_id: &str) -> impl Future> + 'a { - let path_string = format!("/lol/match/v5/matches/{}", match_id); - self.base.get::("match-v5.getMatch", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/match/v5/matches/{}", match_id)); + self.base.execute::("match-v5.getMatch", region.into(), request) } /// Get a match timeline by match id @@ -966,8 +1005,9 @@ impl<'a> MatchV5<'a> { pub fn get_timeline(&self, region: Region, match_id: &str) -> impl Future> + 'a { - let path_string = format!("/lol/match/v5/matches/{}/timeline", match_id); - self.base.get::("match-v5.getTimeline", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/match/v5/matches/{}/timeline", match_id)); + self.base.execute::("match-v5.getTimeline", region.into(), request) } } @@ -977,6 +1017,7 @@ impl<'a> MatchV5<'a> { /// `spectator-v4` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct SpectatorV4<'a> { base: &'a RiotApi, } @@ -992,8 +1033,9 @@ impl<'a> SpectatorV4<'a> { pub fn get_current_game_info_by_summoner(&self, region: Region, encrypted_summoner_id: &str) -> impl Future>> + 'a { - let path_string = format!("/lol/spectator/v4/active-games/by-summoner/{}", encrypted_summoner_id); - self.base.get_optional::("spectator-v4.getCurrentGameInfoBySummoner", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/spectator/v4/active-games/by-summoner/{}", encrypted_summoner_id)); + self.base.execute_optional::("spectator-v4.getCurrentGameInfoBySummoner", region.into(), request) } /// Get list of featured games. @@ -1006,8 +1048,9 @@ impl<'a> SpectatorV4<'a> { pub fn get_featured_games(&self, region: Region) -> impl Future> + 'a { - let path_string = "/lol/spectator/v4/featured-games".to_owned(); - self.base.get::("spectator-v4.getFeaturedGames", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), "/lol/spectator/v4/featured-games"); + self.base.execute::("spectator-v4.getFeaturedGames", region.into(), request) } } @@ -1017,6 +1060,7 @@ impl<'a> SpectatorV4<'a> { /// `summoner-v4` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct SummonerV4<'a> { base: &'a RiotApi, } @@ -1032,8 +1076,9 @@ impl<'a> SummonerV4<'a> { pub fn get_by_account_id(&self, region: Region, encrypted_account_id: &str) -> impl Future> + 'a { - let path_string = format!("/lol/summoner/v4/summoners/by-account/{}", encrypted_account_id); - self.base.get::("summoner-v4.getByAccountId", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/summoner/v4/summoners/by-account/{}", encrypted_account_id)); + self.base.execute::("summoner-v4.getByAccountId", region.into(), request) } /// Get a summoner by summoner name. @@ -1047,8 +1092,9 @@ impl<'a> SummonerV4<'a> { pub fn get_by_summoner_name(&self, region: Region, summoner_name: &str) -> impl Future>> + 'a { - let path_string = format!("/lol/summoner/v4/summoners/by-name/{}", summoner_name); - self.base.get_optional::("summoner-v4.getBySummonerName", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/summoner/v4/summoners/by-name/{}", summoner_name)); + self.base.execute_optional::("summoner-v4.getBySummonerName", region.into(), request) } /// Get a summoner by PUUID. @@ -1062,8 +1108,9 @@ impl<'a> SummonerV4<'a> { pub fn get_by_puuid(&self, region: Region, encrypted_puuid: &str) -> impl Future> + 'a { - let path_string = format!("/lol/summoner/v4/summoners/by-puuid/{}", encrypted_puuid); - self.base.get::("summoner-v4.getByPUUID", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/summoner/v4/summoners/by-puuid/{}", encrypted_puuid)); + self.base.execute::("summoner-v4.getByPUUID", region.into(), request) } /// Get a summoner by summoner ID. @@ -1077,8 +1124,9 @@ impl<'a> SummonerV4<'a> { pub fn get_by_summoner_id(&self, region: Region, encrypted_summoner_id: &str) -> impl Future> + 'a { - let path_string = format!("/lol/summoner/v4/summoners/{}", encrypted_summoner_id); - self.base.get::("summoner-v4.getBySummonerId", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/summoner/v4/summoners/{}", encrypted_summoner_id)); + self.base.execute::("summoner-v4.getBySummonerId", region.into(), request) } } @@ -1088,6 +1136,7 @@ impl<'a> SummonerV4<'a> { /// `tft-league-v1` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct TftLeagueV1<'a> { base: &'a RiotApi, } @@ -1102,8 +1151,9 @@ impl<'a> TftLeagueV1<'a> { pub fn get_challenger_league(&self, region: Region) -> impl Future> + 'a { - let path_string = "/tft/league/v1/challenger".to_owned(); - self.base.get::("tft-league-v1.getChallengerLeague", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), "/tft/league/v1/challenger"); + self.base.execute::("tft-league-v1.getChallengerLeague", region.into(), request) } /// Get league entries for a given summoner ID. @@ -1117,8 +1167,9 @@ impl<'a> TftLeagueV1<'a> { pub fn get_league_entries_for_summoner(&self, region: Region, summoner_id: &str) -> impl Future>> + 'a { - let path_string = format!("/tft/league/v1/entries/by-summoner/{}", summoner_id); - self.base.get::>("tft-league-v1.getLeagueEntriesForSummoner", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/tft/league/v1/entries/by-summoner/{}", summoner_id)); + self.base.execute::>("tft-league-v1.getLeagueEntriesForSummoner", region.into(), request) } /// Get all the league entries. @@ -1134,11 +1185,10 @@ impl<'a> TftLeagueV1<'a> { pub fn get_league_entries(&self, region: Region, tier: &str, division: &str, page: Option) -> impl Future>> + 'a { - let mut query_params = Serializer::new(String::new()); - if let Some(page) = page { query_params.append_pair("page", &*page.to_string()); }; - let query_string = query_params.finish(); - let path_string = format!("/tft/league/v1/entries/{}/{}", tier, division); - self.base.get::>("tft-league-v1.getLeagueEntries", region.into(), path_string, Some(query_string)) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/tft/league/v1/entries/{}/{}", tier, division)); + if let Some(page) = page { request = request.query(&[ ("page", page) ]); }; + self.base.execute::>("tft-league-v1.getLeagueEntries", region.into(), request) } /// Get the grandmaster league. @@ -1151,8 +1201,9 @@ impl<'a> TftLeagueV1<'a> { pub fn get_grandmaster_league(&self, region: Region) -> impl Future> + 'a { - let path_string = "/tft/league/v1/grandmaster".to_owned(); - self.base.get::("tft-league-v1.getGrandmasterLeague", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), "/tft/league/v1/grandmaster"); + self.base.execute::("tft-league-v1.getGrandmasterLeague", region.into(), request) } /// Get league with given ID, including inactive entries. @@ -1166,8 +1217,9 @@ impl<'a> TftLeagueV1<'a> { pub fn get_league_by_id(&self, region: Region, league_id: &str) -> impl Future>> + 'a { - let path_string = format!("/tft/league/v1/leagues/{}", league_id); - self.base.get_optional::("tft-league-v1.getLeagueById", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/tft/league/v1/leagues/{}", league_id)); + self.base.execute_optional::("tft-league-v1.getLeagueById", region.into(), request) } /// Get the master league. @@ -1180,8 +1232,9 @@ impl<'a> TftLeagueV1<'a> { pub fn get_master_league(&self, region: Region) -> impl Future> + 'a { - let path_string = "/tft/league/v1/master".to_owned(); - self.base.get::("tft-league-v1.getMasterLeague", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), "/tft/league/v1/master"); + self.base.execute::("tft-league-v1.getMasterLeague", region.into(), request) } /// Get the top rated ladder for given queue @@ -1195,8 +1248,9 @@ impl<'a> TftLeagueV1<'a> { pub fn get_top_rated_ladder(&self, region: Region, queue: crate::consts::QueueType) -> impl Future>> + 'a { - let path_string = format!("/tft/league/v1/rated-ladders/{}/top", queue); - self.base.get::>("tft-league-v1.getTopRatedLadder", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/tft/league/v1/rated-ladders/{}/top", queue)); + self.base.execute::>("tft-league-v1.getTopRatedLadder", region.into(), request) } } @@ -1206,6 +1260,7 @@ impl<'a> TftLeagueV1<'a> { /// `tft-match-v1` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct TftMatchV1<'a> { base: &'a RiotApi, } @@ -1222,11 +1277,10 @@ impl<'a> TftMatchV1<'a> { pub fn get_match_ids_by_puuid(&self, region: Region, puuid: &str, count: Option) -> impl Future>> + 'a { - let mut query_params = Serializer::new(String::new()); - if let Some(count) = count { query_params.append_pair("count", &*count.to_string()); }; - let query_string = query_params.finish(); - let path_string = format!("/tft/match/v1/matches/by-puuid/{}/ids", puuid); - self.base.get::>("tft-match-v1.getMatchIdsByPUUID", region.into(), path_string, Some(query_string)) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/tft/match/v1/matches/by-puuid/{}/ids", puuid)); + if let Some(count) = count { request = request.query(&[ ("count", count) ]); }; + self.base.execute::>("tft-match-v1.getMatchIdsByPUUID", region.into(), request) } /// Get a match by match id @@ -1240,8 +1294,9 @@ impl<'a> TftMatchV1<'a> { pub fn get_match(&self, region: Region, match_id: &str) -> impl Future>> + 'a { - let path_string = format!("/tft/match/v1/matches/{}", match_id); - self.base.get_optional::("tft-match-v1.getMatch", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/tft/match/v1/matches/{}", match_id)); + self.base.execute_optional::("tft-match-v1.getMatch", region.into(), request) } } @@ -1251,6 +1306,7 @@ impl<'a> TftMatchV1<'a> { /// `tft-summoner-v1` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct TftSummonerV1<'a> { base: &'a RiotApi, } @@ -1266,8 +1322,9 @@ impl<'a> TftSummonerV1<'a> { pub fn get_by_account_id(&self, region: Region, encrypted_account_id: &str) -> impl Future> + 'a { - let path_string = format!("/tft/summoner/v1/summoners/by-account/{}", encrypted_account_id); - self.base.get::("tft-summoner-v1.getByAccountId", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/tft/summoner/v1/summoners/by-account/{}", encrypted_account_id)); + self.base.execute::("tft-summoner-v1.getByAccountId", region.into(), request) } /// Get a summoner by summoner name. @@ -1281,8 +1338,9 @@ impl<'a> TftSummonerV1<'a> { pub fn get_by_summoner_name(&self, region: Region, summoner_name: &str) -> impl Future>> + 'a { - let path_string = format!("/tft/summoner/v1/summoners/by-name/{}", summoner_name); - self.base.get_optional::("tft-summoner-v1.getBySummonerName", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/tft/summoner/v1/summoners/by-name/{}", summoner_name)); + self.base.execute_optional::("tft-summoner-v1.getBySummonerName", region.into(), request) } /// Get a summoner by PUUID. @@ -1296,8 +1354,9 @@ impl<'a> TftSummonerV1<'a> { pub fn get_by_puuid(&self, region: Region, encrypted_puuid: &str) -> impl Future> + 'a { - let path_string = format!("/tft/summoner/v1/summoners/by-puuid/{}", encrypted_puuid); - self.base.get::("tft-summoner-v1.getByPUUID", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/tft/summoner/v1/summoners/by-puuid/{}", encrypted_puuid)); + self.base.execute::("tft-summoner-v1.getByPUUID", region.into(), request) } /// Get a summoner by summoner ID. @@ -1311,8 +1370,9 @@ impl<'a> TftSummonerV1<'a> { pub fn get_by_summoner_id(&self, region: Region, encrypted_summoner_id: &str) -> impl Future> + 'a { - let path_string = format!("/tft/summoner/v1/summoners/{}", encrypted_summoner_id); - self.base.get::("tft-summoner-v1.getBySummonerId", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/tft/summoner/v1/summoners/{}", encrypted_summoner_id)); + self.base.execute::("tft-summoner-v1.getBySummonerId", region.into(), request) } } @@ -1322,6 +1382,7 @@ impl<'a> TftSummonerV1<'a> { /// `third-party-code-v4` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct ThirdPartyCodeV4<'a> { base: &'a RiotApi, } @@ -1337,8 +1398,9 @@ impl<'a> ThirdPartyCodeV4<'a> { pub fn get_third_party_code_by_summoner_id(&self, region: Region, encrypted_summoner_id: &str) -> impl Future> + 'a { - let path_string = format!("/lol/platform/v4/third-party-code/by-summoner/{}", encrypted_summoner_id); - self.base.get::("third-party-code-v4.getThirdPartyCodeBySummonerId", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/platform/v4/third-party-code/by-summoner/{}", encrypted_summoner_id)); + self.base.execute::("third-party-code-v4.getThirdPartyCodeBySummonerId", region.into(), request) } } @@ -1348,6 +1410,7 @@ impl<'a> ThirdPartyCodeV4<'a> { /// `tournament-stub-v4` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct TournamentStubV4<'a> { base: &'a RiotApi, } @@ -1363,8 +1426,9 @@ impl<'a> TournamentStubV4<'a> { pub fn get_lobby_events_by_code(&self, region: Region, tournament_code: &str) -> impl Future> + 'a { - let path_string = format!("/lol/tournament-stub/v4/lobby-events/by-code/{}", tournament_code); - self.base.get::("tournament-stub-v4.getLobbyEventsByCode", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/tournament-stub/v4/lobby-events/by-code/{}", tournament_code)); + self.base.execute::("tournament-stub-v4.getLobbyEventsByCode", region.into(), request) } } @@ -1374,6 +1438,7 @@ impl<'a> TournamentStubV4<'a> { /// `tournament-v4` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct TournamentV4<'a> { base: &'a RiotApi, } @@ -1389,8 +1454,9 @@ impl<'a> TournamentV4<'a> { pub fn get_tournament_code(&self, region: Region, tournament_code: &str) -> impl Future> + 'a { - let path_string = format!("/lol/tournament/v4/codes/{}", tournament_code); - self.base.get::("tournament-v4.getTournamentCode", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/tournament/v4/codes/{}", tournament_code)); + self.base.execute::("tournament-v4.getTournamentCode", region.into(), request) } /// Gets a list of lobby events by tournament code. @@ -1404,8 +1470,9 @@ impl<'a> TournamentV4<'a> { pub fn get_lobby_events_by_code(&self, region: Region, tournament_code: &str) -> impl Future> + 'a { - let path_string = format!("/lol/tournament/v4/lobby-events/by-code/{}", tournament_code); - self.base.get::("tournament-v4.getLobbyEventsByCode", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/lol/tournament/v4/lobby-events/by-code/{}", tournament_code)); + self.base.execute::("tournament-v4.getLobbyEventsByCode", region.into(), request) } } @@ -1415,6 +1482,7 @@ impl<'a> TournamentV4<'a> { /// `val-content-v1` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct ValContentV1<'a> { base: &'a RiotApi, } @@ -1430,11 +1498,10 @@ impl<'a> ValContentV1<'a> { pub fn get_content(&self, region: Region, locale: Option<&str>) -> impl Future> + 'a { - let mut query_params = Serializer::new(String::new()); - if let Some(locale) = locale { query_params.append_pair("locale", locale); }; - let query_string = query_params.finish(); - let path_string = "/val/content/v1/contents".to_owned(); - self.base.get::("val-content-v1.getContent", region.into(), path_string, Some(query_string)) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), "/val/content/v1/contents"); + if let Some(locale) = locale { request = request.query(&[ ("locale", locale) ]); }; + self.base.execute::("val-content-v1.getContent", region.into(), request) } } @@ -1444,6 +1511,7 @@ impl<'a> ValContentV1<'a> { /// `val-match-v1` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct ValMatchV1<'a> { base: &'a RiotApi, } @@ -1459,8 +1527,9 @@ impl<'a> ValMatchV1<'a> { pub fn get_match(&self, region: Region, match_id: &str) -> impl Future>> + 'a { - let path_string = format!("/val/match/v1/matches/{}", match_id); - self.base.get_optional::("val-match-v1.getMatch", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/val/match/v1/matches/{}", match_id)); + self.base.execute_optional::("val-match-v1.getMatch", region.into(), request) } /// Get matchlist for games played by puuid @@ -1474,8 +1543,9 @@ impl<'a> ValMatchV1<'a> { pub fn get_matchlist(&self, region: Region, puuid: &str) -> impl Future> + 'a { - let path_string = format!("/val/match/v1/matchlists/by-puuid/{}", puuid); - self.base.get::("val-match-v1.getMatchlist", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/val/match/v1/matchlists/by-puuid/{}", puuid)); + self.base.execute::("val-match-v1.getMatchlist", region.into(), request) } /// Get recent matches @@ -1491,8 +1561,9 @@ impl<'a> ValMatchV1<'a> { pub fn get_recent(&self, region: Region, queue: &str) -> impl Future> + 'a { - let path_string = format!("/val/match/v1/recent-matches/by-queue/{}", queue); - self.base.get::("val-match-v1.getRecent", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/val/match/v1/recent-matches/by-queue/{}", queue)); + self.base.execute::("val-match-v1.getRecent", region.into(), request) } } @@ -1502,6 +1573,7 @@ impl<'a> ValMatchV1<'a> { /// `val-ranked-v1` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct ValRankedV1<'a> { base: &'a RiotApi, } @@ -1519,12 +1591,11 @@ impl<'a> ValRankedV1<'a> { pub fn get_leaderboard(&self, region: Region, act_id: &str, size: Option, start_index: Option) -> impl Future>> + 'a { - let mut query_params = Serializer::new(String::new()); - if let Some(size) = size { query_params.append_pair("size", &*size.to_string()); }; - if let Some(start_index) = start_index { query_params.append_pair("startIndex", &*start_index.to_string()); }; - let query_string = query_params.finish(); - let path_string = format!("/val/ranked/v1/leaderboards/by-act/{}", act_id); - self.base.get_optional::("val-ranked-v1.getLeaderboard", region.into(), path_string, Some(query_string)) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), &format!("/val/ranked/v1/leaderboards/by-act/{}", act_id)); + if let Some(size) = size { request = request.query(&[ ("size", size) ]); }; + if let Some(start_index) = start_index { request = request.query(&[ ("startIndex", start_index) ]); }; + self.base.execute_optional::("val-ranked-v1.getLeaderboard", region.into(), request) } } @@ -1534,6 +1605,7 @@ impl<'a> ValRankedV1<'a> { /// `val-status-v1` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct ValStatusV1<'a> { base: &'a RiotApi, } @@ -1548,8 +1620,9 @@ impl<'a> ValStatusV1<'a> { pub fn get_platform_data(&self, region: Region) -> impl Future> + 'a { - let path_string = "/val/status/v1/platform-data".to_owned(); - self.base.get::("val-status-v1.getPlatformData", region.into(), path_string, None) + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), "/val/status/v1/platform-data"); + self.base.execute::("val-status-v1.getPlatformData", region.into(), request) } } diff --git a/src/req/regional_requester.rs b/src/req/regional_requester.rs index 1820c6d..71e19ed 100644 --- a/src/req/regional_requester.rs +++ b/src/req/regional_requester.rs @@ -2,7 +2,7 @@ use std::future::Future; use std::sync::Arc; use log; -use reqwest::{Client, StatusCode, Request}; +use reqwest::{ StatusCode, RequestBuilder }; use crate::Result; use crate::ResponseInfo; @@ -34,9 +34,9 @@ impl RegionalRequester { } } - pub fn execute_raw<'a>(self: Arc, - config: &'a RiotApiConfig, client: &'a Client, - method_id: &'static str, request: Request) + pub fn execute<'a>(self: Arc, + config: &'a RiotApiConfig, + method_id: &'static str, request: RequestBuilder) -> impl Future> + 'a { async move { @@ -52,7 +52,7 @@ impl RegionalRequester { // Send request. let request_clone = request.try_clone().expect("Failed to clone request."); - let response = client.execute(request_clone).await + let response = request_clone.send().await .map_err(|e| RiotApiError::new(e, retries, None, None))?; // Maybe update rate limits (based on response headers). diff --git a/src/riot_api.rs b/src/riot_api.rs index d47b773..a85fcd5 100644 --- a/src/riot_api.rs +++ b/src/riot_api.rs @@ -2,7 +2,7 @@ use std::future::Future; use std::sync::Arc; use log; -use reqwest::{Client, Request, Method, Url}; +use reqwest::{ Client, RequestBuilder, Method, Url }; use crate::Result; use crate::ResponseInfo; @@ -63,7 +63,7 @@ impl RiotApi { /// `api_key` should be a Riot Games API key from /// [https://developer.riotgames.com/](https://developer.riotgames.com/), /// and should look like `"RGAPI-01234567-89ab-cdef-0123-456789abcdef"`. - pub fn with_key>(api_key: T) -> Self { + pub fn with_key(api_key: impl AsRef<[u8]>) -> Self { Self::with_config(RiotApiConfig::with_key(api_key)) } @@ -140,16 +140,17 @@ impl RiotApi { url.set_path(&*path); url.set_query(query.as_deref()); - let request = Request::new(Method::GET, url); + let request = self.client.get(url); self.execute_raw(method_id, region_platform, request) } - - - + pub fn request(&self, method: Method, region_platform: &str, path: &str) -> RequestBuilder { + let base_url_platform = self.config.base_url.replace("{}", region_platform); + self.client.request(method, format!("{}/{}", base_url_platform, path)) + } pub async fn execute_optional<'a, T: serde::de::DeserializeOwned + 'a>(&'a self, - method_id: &'static str, region_platform: &'static str, request: Request) + method_id: &'static str, region_platform: &'static str, request: RequestBuilder) -> Result> { let rinfo = self.execute_raw(method_id, region_platform, request).await?; @@ -163,7 +164,7 @@ impl RiotApi { } pub async fn execute<'a, T: serde::de::DeserializeOwned + 'a>(&'a self, - method_id: &'static str, region_platform: &'static str, request: Request) + method_id: &'static str, region_platform: &'static str, request: RequestBuilder) -> Result { let rinfo = self.execute_raw(method_id, region_platform, request).await?; @@ -173,11 +174,11 @@ impl RiotApi { value.map_err(|e| RiotApiError::new(e, retries, None, Some(status))) } - pub fn execute_raw(&self, method_id: &'static str, region_platform: &'static str, request: Request) + pub fn execute_raw(&self, method_id: &'static str, region_platform: &'static str, request: RequestBuilder) -> impl Future> + '_ { self.regional_requester(region_platform) - .execute_raw(&self.config, &self.client, method_id, request) + .execute(&self.config, method_id, request) } /// Get or create the RegionalRequester for the given region. diff --git a/srcgen/dotUtils.js b/srcgen/dotUtils.js index 2fa621e..040f2c2 100644 --- a/srcgen/dotUtils.js +++ b/srcgen/dotUtils.js @@ -107,47 +107,30 @@ function formatJsonProperty(name) { return `#[serde(rename = "${name}")]`; } -function formatQueryParamStringify(name, prop, useOwned = false) { - const own = useOwned ? '' : '&*'; - if (prop['x-enum']) { - switch (prop.type) { - case 'integer': - return `${own}Into::<${enumTypeLookup[prop['x-enum']]}>::into(*${name}).to_string()`; - default: throw new Error(`Enum not supported: ${JSON.stringify(prop)}.`) - } - } - switch (prop.type) { - case 'array': throw new Error(`Cannot formart array: ${JSON.stringify(prop)}.`); - case 'boolean': return `${name} ? "true" : "false"`; - case 'string': return name; - default: return `${own}${name}.to_string()`; - } -} - function formatAddQueryParam(param) { let k = `"${param.name}"`; let name = changeCase.snakeCase(param.name); let nc = param.required ? '' : `if let Some(${name}) = ${name} `; let prop = param.schema; switch (prop.type) { - case 'array': return `${nc}{ query_params.extend_pairs(${name}.iter()` - + `.map(|w| (${k}, ${formatQueryParamStringify("w", prop.items, true)}))); }`; + case 'array': return `${nc}{ request = request.query(&*${name}.iter()` + + `.map(|w| ( ${k}, w )).collect::>()); }`; case 'object': throw 'unsupported'; default: - return `${nc}{ query_params.append_pair(${k}, ${formatQueryParamStringify(name, prop)}); }`; + return `${nc}{ request = request.query(&[ (${k}, ${name}) ]); }`; } } function formatRouteArgument(route, pathParams = []) { if (!pathParams.length) - return `"${route}".to_owned()`; + return `"${route}"`; route = route.replace(/\{\S+?\}/g, '{}'); const args = pathParams .map(({name}) => name) .map(changeCase.snakeCase) .join(', '); - return `format!("${route}", ${args})`; + return `&format!("${route}", ${args})`; } module.exports = { diff --git a/srcgen/endpoints.rs.dt b/srcgen/endpoints.rs.dt index cd8b24f..b09d875 100644 --- a/srcgen/endpoints.rs.dt +++ b/srcgen/endpoints.rs.dt @@ -13,7 +13,7 @@ use crate::models::*; use std::future::Future; use std::vec::Vec; -use url::form_urlencoded::Serializer; +use reqwest::Method; use crate::Result; use crate::consts::Region; @@ -57,6 +57,7 @@ impl RiotApi { /// `{{= endpointName }}` /// /// Note: this struct is automatically generated. +#[repr(transparent)] pub struct {{= endpoint }}<'a> { base: &'a RiotApi, } @@ -90,7 +91,7 @@ impl<'a> {{= endpoint }}<'a> { let makeParamCode = ''; let allParams = get.parameters; let queryParams = []; - let routeArgument = dotUtils.formatRouteArgument(route); + let routeArgument; if (allParams && allParams.length) { let pathParams = allParams.filter(p => 'path' === p.in) @@ -115,6 +116,10 @@ impl<'a> {{= endpoint }}<'a> { routeArgument = dotUtils.formatRouteArgument(route, pathParams); } + else + { + routeArgument = dotUtils.formatRouteArgument(route); + } for (var descLine of descArr) { }} @@ -142,8 +147,8 @@ impl<'a> {{= endpoint }}<'a> { pub fn {{= method }}(&self, region: Region{{= argBuilder.join('') }}) -> impl Future> + 'a { -{{? queryParams.length }} - let mut query_params = Serializer::new(String::new()); + #[allow(unused_mut)] + let mut request = self.base.request(Method::GET, region.into(), {{= routeArgument }}); {{ for (let queryParam of queryParams) { @@ -152,10 +157,7 @@ impl<'a> {{= endpoint }}<'a> { {{ } }} - let query_string = query_params.finish(); -{{?}} - let path_string = {{= routeArgument }}; - self.base.get{{= returnOptional ? '_optional' : '' }}::<{{= parseType }}>("{{= operationId }}", region.into(), path_string, {{= queryParams.length ? 'Some(query_string)' : 'None' }}) + self.base.execute{{= returnOptional ? '_optional' : '' }}::<{{= parseType }}>("{{= operationId }}", region.into(), request) } {{