forked from mirror/Riven
1
0
Fork 0

Add match_v5::Participant champion(&self) method to handle bad champion IDs

Riot: https://github.com/RiotGames/developer-relations/issues/553
https://github.com/MingweiSamuel/Riven/issues/36
users/mingwei/unknown-variant-messy
Mingwei Samuel 2021-12-29 10:04:54 -08:00
parent de1e5cdbca
commit 2f4d1dc65c
5 changed files with 29 additions and 0 deletions

View File

@ -190,6 +190,7 @@ pub use error::*;
pub mod meta; pub mod meta;
pub mod models; pub mod models;
mod models_impls;
mod req; mod req;

View File

@ -820,6 +820,9 @@ pub mod match_v5 {
pub champ_level: i32, pub champ_level: i32,
/// Prior to patch 11.4, on Feb 18th, 2021, this field returned invalid championIds. We recommend determining the champion based on the championName field for matches played prior to patch 11.4. /// Prior to patch 11.4, on Feb 18th, 2021, this field returned invalid championIds. We recommend determining the champion based on the championName field for matches played prior to patch 11.4.
#[serde(rename = "championId")] #[serde(rename = "championId")]
///
/// Instead use [`Self::champion()`] which checks this field then parses [`Self::champion_name`].
#[deprecated(since = "2.5.0", note = "Use `Participant.champion()` instead. Riot sometimes returns corrupted data for this field: https://github.com/RiotGames/developer-relations/issues/553")]
#[serde(serialize_with = "crate::consts::Champion::serialize_result")] #[serde(serialize_with = "crate::consts::Champion::serialize_result")]
#[serde(deserialize_with = "crate::consts::Champion::deserialize_result")] #[serde(deserialize_with = "crate::consts::Champion::deserialize_result")]
pub champion_id: Result<crate::consts::Champion, std::num::TryFromIntError>, pub champion_id: Result<crate::consts::Champion, std::num::TryFromIntError>,

21
riven/src/models_impls.rs Normal file
View File

@ -0,0 +1,21 @@
use crate::models::match_v5::Participant;
use crate::consts::Champion;
impl Participant {
/// This method takes the [`Self::champion_id`] field if it is valid
/// (`Ok`), otherwise it attempts to parse [`Self::champion_name`] and
/// returns the `Result`.
///
/// This is needed because some of Riot's [`Self::champion_id`] data is
/// corrupted, as they describe in the docs:
///
/// > Prior to patch 11.4, on Feb 18th, 2021, this field returned invalid
/// > championIds. We recommend determining the champion based on the
/// > championName field for matches played prior to patch 11.4.
///
/// This issue is reported here: <https://github.com/RiotGames/developer-relations/issues/553>.
pub fn champion(&self) -> Result<Champion, <Champion as std::str::FromStr>::Err> {
#[allow(deprecated)]
self.champion_id.or_else(|_| self.champion_name.parse())
}
}

View File

@ -26,6 +26,7 @@ pub use error::*;
pub mod meta; pub mod meta;
pub mod models; pub mod models;
mod models_impls;
mod req; mod req;

View File

@ -59,6 +59,9 @@ pub mod {{= dotUtils.changeCase.snakeCase(endpoint) }} {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
{{?}} {{?}}
{{? 'championId' === propKey && (prop.description || '').includes('this field returned invalid championIds') }} {{? 'championId' === propKey && (prop.description || '').includes('this field returned invalid championIds') }}
///
/// Instead use [`Self::champion()`] which checks this field then parses [`Self::champion_name`].
#[deprecated(since = "2.5.0", note = "Use `Participant.champion()` instead. Riot sometimes returns corrupted data for this field: https://github.com/RiotGames/developer-relations/issues/553")]
#[serde(serialize_with = "crate::consts::Champion::serialize_result")] #[serde(serialize_with = "crate::consts::Champion::serialize_result")]
#[serde(deserialize_with = "crate::consts::Champion::deserialize_result")] #[serde(deserialize_with = "crate::consts::Champion::deserialize_result")]
pub {{= name }}: Result<crate::consts::Champion, std::num::TryFromIntError>, pub {{= name }}: Result<crate::consts::Champion, std::num::TryFromIntError>,