From 0f400ab43a2345aa450b105988aa1f9e8ff75103 Mon Sep 17 00:00:00 2001 From: Mingwei Samuel Date: Sun, 9 May 2021 09:46:10 -0700 Subject: [PATCH] Regen, update tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - New `tft-league-v1.getTopRatedLadder` endpoint. #24 - Updated optionals on `tft-league-v1.LeagueEntryDTO`. #25 - New `RANKED_TFT_TURBO` `QueueType`. #25 - Test for `tft-league-v1.getLeagueEntriesForSummoner` added. #25 - Fixed whitespace on `잘 못` doc test (werid). --- README.md | 2 +- src/consts/queue_type.rs | 3 +- src/endpoints.rs | 108 +++++++++++++++++++++++++++++++++++---- src/meta.rs | 8 ++- src/models.rs | 91 +++++++++++++++++++++++++++++---- test.bash | 2 +- tests/tests_jp.rs | 10 ++++ 7 files changed, 199 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 5c1629c..d1c3435 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ rt.block_on(async { // Get summoner data. let summoner = riot_api.summoner_v4() - .get_by_summoner_name(Region::NA, "잘못").await + .get_by_summoner_name(Region::NA, "잘 못").await .expect("Get summoner failed.") .expect("There is no summoner with that name."); diff --git a/src/consts/queue_type.rs b/src/consts/queue_type.rs index 2fe4e1f..5a02d6c 100644 --- a/src/consts/queue_type.rs +++ b/src/consts/queue_type.rs @@ -13,8 +13,9 @@ pub enum QueueType { // League of Legends, Twisted Treeline (3v3), Flex Queue. RANKED_FLEX_TT, // Ranked Teamfight Tactics. - #[deprecated(note = "Teamfight Tactics ranks should be acquired using `TftLeagueV1::get_league_entries`.")] RANKED_TFT, + // Ranked Teamfight Tactics, Turbo gamemode. + RANKED_TFT_TURBO, } serde_string!(QueueType); diff --git a/src/endpoints.rs b/src/endpoints.rs index e2b94dc..0807853 100644 --- a/src/endpoints.rs +++ b/src/endpoints.rs @@ -7,7 +7,7 @@ /////////////////////////////////////////////// // http://www.mingweisamuel.com/riotapi-schema/tool/ -// Version 7bea623175b27bdc53a046c4e0d09b0f0d638aa7 +// Version d958cb912f35a3eb9091337de469633e228a7aa2 //! Automatically generated endpoint handles. @@ -131,6 +131,15 @@ impl RiotApi { pub fn match_v4(&self) -> MatchV4 { MatchV4 { base: self } } + /// Returns a handle for accessing [MatchV5](crate::endpoints::MatchV5) endpoints. + /// # Riot Developer API Reference + /// `match-v5` + /// + /// Note: this method is automatically generated. + #[inline] + pub fn match_v5(&self) -> MatchV5 { + MatchV5 { base: self } + } /// Returns a handle for accessing [SpectatorV4](crate::endpoints::SpectatorV4) endpoints. /// # Riot Developer API Reference /// `spectator-v4` @@ -284,8 +293,8 @@ impl<'a> AccountV1<'a> { /// Get active shard for a player /// # Parameters /// * `region` - Region to query. - /// * `puuid` /// * `game` + /// * `puuid` /// # Riot Developer API Reference /// `account-v1.getActiveShard` /// @@ -483,7 +492,7 @@ impl<'a> LeagueExpV4<'a> { /// * `queue` - Note that the queue value must be a valid ranked queue. /// * `tier` /// * `division` - /// * `page` (optional) - Starts with page 1. + /// * `page` (optional) - Defaults to 1. Starts with page 1. /// # Riot Developer API Reference /// `league-exp-v4.getLeagueEntries` /// @@ -545,7 +554,7 @@ impl<'a> LeagueV4<'a> { /// * `division` /// * `tier` /// * `queue` - Note that the queue value must be a valid ranked queue. - /// * `page` (optional) - Starts with page 1. + /// * `page` (optional) - Defaults to 1. Starts with page 1. /// # Riot Developer API Reference /// `league-v4.getLeagueEntries` /// @@ -861,6 +870,68 @@ impl<'a> MatchV4<'a> { } +/// MatchV5 endpoints handle, accessed by calling [`match_v5()`](crate::RiotApi::match_v5) on a [`RiotApi`](crate::RiotApi) instance. +/// # Riot Developer API Reference +/// `match-v5` +/// +/// Note: this struct is automatically generated. +pub struct MatchV5<'a> { + base: &'a RiotApi, +} +impl<'a> MatchV5<'a> { + /// Get a list of match ids by puuid + /// # Parameters + /// * `region` - Region to query. + /// * `puuid` + /// * `start` (optional) - Defaults to 0. Start index. + /// * `count` (optional) - Defaults to 20. Valid values: 0 to 100. Match id count. + /// # Riot Developer API Reference + /// `match-v5.getMatchIdsByPUUID` + /// + /// Note: this method is automatically generated. + 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)) + } + + /// Get a match by match id + /// # Parameters + /// * `region` - Region to query. + /// * `matchId` + /// # Riot Developer API Reference + /// `match-v5.getMatch` + /// + /// Note: this method is automatically generated. + 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) + } + + /// Get a match timeline by match id + /// # Parameters + /// * `region` - Region to query. + /// * `matchId` + /// # Riot Developer API Reference + /// `match-v5.getTimeline` + /// + /// Note: this method is automatically generated. + 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) + } + +} + /// SpectatorV4 endpoints handle, accessed by calling [`spectator_v4()`](crate::RiotApi::spectator_v4) on a [`RiotApi`](crate::RiotApi) instance. /// # Riot Developer API Reference /// `spectator-v4` @@ -998,15 +1069,15 @@ impl<'a> TftLeagueV1<'a> { /// Get league entries for a given summoner ID. /// # Parameters /// * `region` - Region to query. - /// * `encryptedSummonerId` + /// * `summonerId` /// # Riot Developer API Reference /// `tft-league-v1.getLeagueEntriesForSummoner` /// /// Note: this method is automatically generated. - pub fn get_league_entries_for_summoner(&self, region: Region, encrypted_summoner_id: &str) + 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/{}", encrypted_summoner_id); + let path_string = format!("/tft/league/v1/entries/by-summoner/{}", summoner_id); self.base.get::>("tft-league-v1.getLeagueEntriesForSummoner", region.into(), path_string, None) } @@ -1015,7 +1086,7 @@ impl<'a> TftLeagueV1<'a> { /// * `region` - Region to query. /// * `tier` /// * `division` - /// * `page` (optional) - Starts with page 1. + /// * `page` (optional) - Defaults to 1. Starts with page 1. /// # Riot Developer API Reference /// `tft-league-v1.getLeagueEntries` /// @@ -1073,6 +1144,21 @@ impl<'a> TftLeagueV1<'a> { self.base.get::("tft-league-v1.getMasterLeague", region.into(), path_string, None) } + /// Get the top rated ladder for given queue + /// # Parameters + /// * `region` - Region to query. + /// * `queue` + /// # Riot Developer API Reference + /// `tft-league-v1.getTopRatedLadder` + /// + /// Note: this method is automatically generated. + pub fn get_top_rated_ladder(&self, region: Region, queue: &str) + -> 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) + } + } /// TftMatchV1 endpoints handle, accessed by calling [`tft_match_v1()`](crate::RiotApi::tft_match_v1) on a [`RiotApi`](crate::RiotApi) instance. @@ -1088,7 +1174,7 @@ impl<'a> TftMatchV1<'a> { /// # Parameters /// * `region` - Region to query. /// * `puuid` - /// * `count` (optional) + /// * `count` (optional) - Defaults to 20. /// # Riot Developer API Reference /// `tft-match-v1.getMatchIdsByPUUID` /// @@ -1384,8 +1470,8 @@ impl<'a> ValRankedV1<'a> { /// # Parameters /// * `region` - Region to query. /// * `actId` - Act ids can be found using the val-content API. - /// * `size` (optional) - /// * `startIndex` (optional) + /// * `size` (optional) - Defaults to 200. Valid values: 1 to 200. + /// * `startIndex` (optional) - Defaults to 0. /// # Riot Developer API Reference /// `val-ranked-v1.getLeaderboard` /// diff --git a/src/meta.rs b/src/meta.rs index 90c5639..71663c9 100644 --- a/src/meta.rs +++ b/src/meta.rs @@ -7,7 +7,7 @@ /////////////////////////////////////////////// // http://www.mingweisamuel.com/riotapi-schema/tool/ -// Version 7bea623175b27bdc53a046c4e0d09b0f0d638aa7 +// Version d958cb912f35a3eb9091337de469633e228a7aa2 //! Metadata about the Riot API and Riven. //! @@ -50,6 +50,9 @@ lazy_static! { map.insert("/lol/match/v4/matches/{matchId}/by-tournament-code/{tournamentCode}", "match-v4.getMatchByTournamentCode"); map.insert("/lol/match/v4/matchlists/by-account/{encryptedAccountId}", "match-v4.getMatchlist"); map.insert("/lol/match/v4/timelines/by-match/{matchId}", "match-v4.getMatchTimeline"); + map.insert("/lol/match/v5/matches/by-puuid/{puuid}/ids", "match-v5.getMatchIdsByPUUID"); + map.insert("/lol/match/v5/matches/{matchId}", "match-v5.getMatch"); + map.insert("/lol/match/v5/matches/{matchId}/timeline", "match-v5.getTimeline"); map.insert("/lol/spectator/v4/active-games/by-summoner/{encryptedSummonerId}", "spectator-v4.getCurrentGameInfoBySummoner"); map.insert("/lol/spectator/v4/featured-games", "spectator-v4.getFeaturedGames"); map.insert("/lol/summoner/v4/summoners/by-account/{encryptedAccountId}", "summoner-v4.getByAccountId"); @@ -57,11 +60,12 @@ lazy_static! { map.insert("/lol/summoner/v4/summoners/by-puuid/{encryptedPUUID}", "summoner-v4.getByPUUID"); map.insert("/lol/summoner/v4/summoners/{encryptedSummonerId}", "summoner-v4.getBySummonerId"); map.insert("/tft/league/v1/challenger", "tft-league-v1.getChallengerLeague"); - map.insert("/tft/league/v1/entries/by-summoner/{encryptedSummonerId}", "tft-league-v1.getLeagueEntriesForSummoner"); + map.insert("/tft/league/v1/entries/by-summoner/{summonerId}", "tft-league-v1.getLeagueEntriesForSummoner"); map.insert("/tft/league/v1/entries/{tier}/{division}", "tft-league-v1.getLeagueEntries"); map.insert("/tft/league/v1/grandmaster", "tft-league-v1.getGrandmasterLeague"); map.insert("/tft/league/v1/leagues/{leagueId}", "tft-league-v1.getLeagueById"); map.insert("/tft/league/v1/master", "tft-league-v1.getMasterLeague"); + map.insert("/tft/league/v1/rated-ladders/{queue}/top", "tft-league-v1.getTopRatedLadder"); map.insert("/tft/match/v1/matches/by-puuid/{puuid}/ids", "tft-match-v1.getMatchIdsByPUUID"); map.insert("/tft/match/v1/matches/{matchId}", "tft-match-v1.getMatch"); map.insert("/tft/summoner/v1/summoners/by-account/{encryptedAccountId}", "tft-summoner-v1.getByAccountId"); diff --git a/src/models.rs b/src/models.rs index 39ec026..1b3ecf8 100644 --- a/src/models.rs +++ b/src/models.rs @@ -7,7 +7,7 @@ /////////////////////////////////////////////// // http://www.mingweisamuel.com/riotapi-schema/tool/ -// Version 7bea623175b27bdc53a046c4e0d09b0f0d638aa7 +// Version d958cb912f35a3eb9091337de469633e228a7aa2 //! Data transfer structs. //! @@ -202,6 +202,7 @@ pub mod league_exp_v4 { pub queue_type: crate::consts::QueueType, #[serde(rename = "tier")] pub tier: crate::consts::Tier, + /// The player's division within a tier. #[serde(rename = "rank")] pub rank: crate::consts::Division, #[serde(rename = "leaguePoints")] @@ -316,6 +317,7 @@ pub mod league_v4 { pub queue_type: crate::consts::QueueType, #[serde(rename = "tier")] pub tier: crate::consts::Tier, + /// The player's division within a tier. #[serde(rename = "rank")] pub rank: crate::consts::Division, #[serde(rename = "leaguePoints")] @@ -1309,6 +1311,31 @@ pub mod match_v4 { } } +/// Data structs used by [`MatchV5`](crate::endpoints::MatchV5). +/// +/// Note: this module is automatically generated. +#[allow(dead_code)] +pub mod match_v5 { + /// Match data object. + /// # Description + /// UNKNOWN TYPE. + /// + /// Note: This struct is automatically generated + #[derive(Debug)] + #[derive(serde::Serialize, serde::Deserialize)] + pub struct Match { + } + /// MatchTimeline data object. + /// # Description + /// UNKNOWN TYPE. + /// + /// Note: This struct is automatically generated + #[derive(Debug)] + #[derive(serde::Serialize, serde::Deserialize)] + pub struct MatchTimeline { + } +} + /// Data structs used by [`SpectatorV4`](crate::endpoints::SpectatorV4). /// /// Note: this module is automatically generated. @@ -1617,8 +1644,9 @@ pub mod tft_league_v1 { #[derive(Debug)] #[derive(serde::Serialize, serde::Deserialize)] pub struct LeagueEntry { + /// Not included for the RANKED_TFT_TURBO queueType. #[serde(rename = "leagueId")] - pub league_id: String, + pub league_id: Option, /// Player's encrypted summonerId. #[serde(rename = "summonerId")] pub summoner_id: String, @@ -1626,29 +1654,63 @@ pub mod tft_league_v1 { pub summoner_name: String, #[serde(rename = "queueType")] pub queue_type: crate::consts::QueueType, + /// Only included for the RANKED_TFT_TURBO queueType.
+ /// (Legal values: ORANGE, PURPLE, BLUE, GREEN, GRAY) + #[serde(rename = "ratedTier")] + pub rated_tier: Option, + /// Only included for the RANKED_TFT_TURBO queueType. + #[serde(rename = "ratedRating")] + pub rated_rating: Option, + /// Not included for the RANKED_TFT_TURBO queueType. #[serde(rename = "tier")] - pub tier: crate::consts::Tier, + pub tier: Option, + /// A player's division within a tier. Not included for the RANKED_TFT_TURBO queueType. #[serde(rename = "rank")] - pub rank: crate::consts::Division, + pub rank: Option, + /// Not included for the RANKED_TFT_TURBO queueType. #[serde(rename = "leaguePoints")] - pub league_points: i32, + pub league_points: Option, /// First placement. #[serde(rename = "wins")] pub wins: i32, /// Second through eighth placement. #[serde(rename = "losses")] pub losses: i32, + /// Not included for the RANKED_TFT_TURBO queueType. #[serde(rename = "hotStreak")] - pub hot_streak: bool, + pub hot_streak: Option, + /// Not included for the RANKED_TFT_TURBO queueType. #[serde(rename = "veteran")] - pub veteran: bool, + pub veteran: Option, + /// Not included for the RANKED_TFT_TURBO queueType. #[serde(rename = "freshBlood")] - pub fresh_blood: bool, + pub fresh_blood: Option, + /// Not included for the RANKED_TFT_TURBO queueType. #[serde(rename = "inactive")] - pub inactive: bool, + pub inactive: Option, + /// Not included for the RANKED_TFT_TURBO queueType. #[serde(rename = "miniSeries")] pub mini_series: Option, } + /// TopRatedLadderEntry data object. + #[derive(Debug)] + #[derive(serde::Serialize, serde::Deserialize)] + pub struct TopRatedLadderEntry { + #[serde(rename = "summonerId")] + pub summoner_id: String, + #[serde(rename = "summonerName")] + pub summoner_name: String, + /// (Legal values: ORANGE, PURPLE, BLUE, GREEN, GRAY) + #[serde(rename = "ratedTier")] + pub rated_tier: String, + #[serde(rename = "ratedRating")] + pub rated_rating: i32, + /// First placement. + #[serde(rename = "wins")] + pub wins: i32, + #[serde(rename = "previousUpdateLadderPosition")] + pub previous_update_ladder_position: i32, + } } /// Data structs used by [`TftMatchV1`](crate::endpoints::TftMatchV1). @@ -2184,6 +2246,8 @@ pub mod val_match_v1 { pub match_info: MatchInfo, #[serde(rename = "players")] pub players: std::vec::Vec, + #[serde(rename = "coaches")] + pub coaches: std::vec::Vec, #[serde(rename = "teams")] pub teams: std::vec::Vec, #[serde(rename = "roundResults")] @@ -2273,6 +2337,15 @@ pub mod val_match_v1 { #[serde(rename = "ultimateCasts")] pub ultimate_casts: i32, } + /// Coach data object. + #[derive(Debug)] + #[derive(serde::Serialize, serde::Deserialize)] + pub struct Coach { + #[serde(rename = "puuid")] + pub puuid: String, + #[serde(rename = "teamId")] + pub team_id: String, + } /// Team data object. #[derive(Debug)] #[derive(serde::Serialize, serde::Deserialize)] diff --git a/test.bash b/test.bash index 56a14f2..9a20766 100755 --- a/test.bash +++ b/test.bash @@ -1,2 +1,2 @@ #!/bin/bash -RGAPI_KEY="$(cat apikey.txt)" RUST_BACKTRACE=1 cargo test --features nightly -- --nocapture +RGAPI_KEY="$(cat apikey.txt)" RUST_BACKTRACE=1 RUST_LOG=riven=debug cargo test --features nightly -- --nocapture diff --git a/tests/tests_jp.rs b/tests/tests_jp.rs index 7addcb0..16f5b26 100644 --- a/tests/tests_jp.rs +++ b/tests/tests_jp.rs @@ -46,5 +46,15 @@ async_tests!{ rassert_eq!(Some(reqwest::StatusCode::FORBIDDEN), r.unwrap_err().status_code()); Ok(()) }, + + // https://github.com/MingweiSamuel/Riven/issues/25 + tft_league_getbysummoner: async { + let sp = RIOT_API.summoner_v4().get_by_summoner_name(Region::JP, "Caihonbbt"); + let sr = sp.await.map_err(|e| e.to_string())?.ok_or("Failed to get \"Caihonbbt\"".to_owned())?; + let lp = RIOT_API.tft_league_v1().get_league_entries_for_summoner(Region::JP, &sr.id); + let lr = lp.await.map_err(|e| e.to_string())?; + rassert!(0 < lr.len()); + Ok(()) + }, } }