From 71219638450b87f5a739ccb2b59a210e6e905f9b Mon Sep 17 00:00:00 2001 From: Kade Robertson Date: Thu, 19 Jan 2023 17:16:45 -0500 Subject: [PATCH] feat: support challenges --- src/client.rs | 6 +++- src/models/challenges.rs | 74 ++++++++++++++++++++++++++++++++++++++++ src/models/mod.rs | 2 ++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 src/models/challenges.rs diff --git a/src/client.rs b/src/client.rs index 2643013..7944183 100644 --- a/src/client.rs +++ b/src/client.rs @@ -5,7 +5,7 @@ use url::Url; #[cfg(test)] use mockito; -use crate::models::{champions::Champions, items::Items, translations::Translations}; +use crate::models::{Challenges, Champions, Items, Translations}; #[derive(Error, Debug)] pub enum DDragonClientError { @@ -68,6 +68,10 @@ impl DDragonClient { .map_err(DDragonClientError::Parse) } + pub fn challenges(&self) -> Result { + self.get_data::("./challenges.json") + } + pub fn champions(&self) -> Result { self.get_data::("./champion.json") } diff --git a/src/models/challenges.rs b/src/models/challenges.rs new file mode 100644 index 0000000..df68304 --- /dev/null +++ b/src/models/challenges.rs @@ -0,0 +1,74 @@ +use serde::{Deserialize, Serialize}; + +pub type Challenges = Vec; + +#[derive(Serialize, Deserialize)] +pub struct Challenge { + pub id: i64, + pub name: String, + pub description: String, + #[serde(rename = "shortDescription")] + pub short_description: String, + #[serde(rename = "hasLeaderboard")] + pub has_leaderboard: bool, + #[serde(rename = "levelToIconPath")] + pub level_to_icon_path: LevelToIconPath, + pub thresholds: Thresholds, +} + +#[derive(Serialize, Deserialize)] +pub struct LevelToIconPath { + #[serde(rename = "IRON")] + pub iron: Option, + #[serde(rename = "BRONZE")] + pub bronze: Option, + #[serde(rename = "SILVER")] + pub silver: Option, + #[serde(rename = "GOLD")] + pub gold: Option, + #[serde(rename = "PLATINUM")] + pub platinum: Option, + #[serde(rename = "DIAMOND")] + pub diamond: Option, + #[serde(rename = "MASTER")] + pub master: Option, + #[serde(rename = "GRANDMASTER")] + pub grandmaster: Option, + #[serde(rename = "CHALLENGER")] + pub challenger: Option, +} + +#[derive(Serialize, Deserialize)] +pub struct Thresholds { + #[serde(rename = "IRON")] + pub iron: Option, + #[serde(rename = "BRONZE")] + pub bronze: Option, + #[serde(rename = "SILVER")] + pub silver: Option, + #[serde(rename = "GOLD")] + pub gold: Option, + #[serde(rename = "PLATINUM")] + pub platinum: Option, + #[serde(rename = "DIAMOND")] + pub diamond: Option, + #[serde(rename = "MASTER")] + pub master: Option, + #[serde(rename = "GRANDMASTER")] + pub grandmaster: Option, + #[serde(rename = "CHALLENGER")] + pub challenger: Option, +} + +#[derive(Serialize, Deserialize)] +pub struct RankReward { + pub value: i64, + pub rewards: Option>, +} + +#[derive(Serialize, Deserialize)] +pub struct RewardDetails { + pub category: String, + pub quantity: i64, + pub title: String, +} diff --git a/src/models/mod.rs b/src/models/mod.rs index 19bac9a..71ab7d5 100644 --- a/src/models/mod.rs +++ b/src/models/mod.rs @@ -1,8 +1,10 @@ +pub mod challenges; pub mod champions; pub mod items; pub mod shared; pub mod translations; +pub use challenges::Challenges; pub use champions::Champions; pub use items::Items; pub use translations::Translations;