Skip to content

Commit

Permalink
feat: support challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
kade-robertson committed Jan 19, 2023
1 parent 1788015 commit 7121963
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -68,6 +68,10 @@ impl DDragonClient {
.map_err(DDragonClientError::Parse)
}

pub fn challenges(&self) -> Result<Challenges, DDragonClientError> {
self.get_data::<Challenges>("./challenges.json")
}

pub fn champions(&self) -> Result<Champions, DDragonClientError> {
self.get_data::<Champions>("./champion.json")
}
Expand Down
74 changes: 74 additions & 0 deletions src/models/challenges.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use serde::{Deserialize, Serialize};

pub type Challenges = Vec<Challenge>;

#[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<String>,
#[serde(rename = "BRONZE")]
pub bronze: Option<String>,
#[serde(rename = "SILVER")]
pub silver: Option<String>,
#[serde(rename = "GOLD")]
pub gold: Option<String>,
#[serde(rename = "PLATINUM")]
pub platinum: Option<String>,
#[serde(rename = "DIAMOND")]
pub diamond: Option<String>,
#[serde(rename = "MASTER")]
pub master: Option<String>,
#[serde(rename = "GRANDMASTER")]
pub grandmaster: Option<String>,
#[serde(rename = "CHALLENGER")]
pub challenger: Option<String>,
}

#[derive(Serialize, Deserialize)]
pub struct Thresholds {
#[serde(rename = "IRON")]
pub iron: Option<RankReward>,
#[serde(rename = "BRONZE")]
pub bronze: Option<RankReward>,
#[serde(rename = "SILVER")]
pub silver: Option<RankReward>,
#[serde(rename = "GOLD")]
pub gold: Option<RankReward>,
#[serde(rename = "PLATINUM")]
pub platinum: Option<RankReward>,
#[serde(rename = "DIAMOND")]
pub diamond: Option<RankReward>,
#[serde(rename = "MASTER")]
pub master: Option<RankReward>,
#[serde(rename = "GRANDMASTER")]
pub grandmaster: Option<RankReward>,
#[serde(rename = "CHALLENGER")]
pub challenger: Option<RankReward>,
}

#[derive(Serialize, Deserialize)]
pub struct RankReward {
pub value: i64,
pub rewards: Option<Vec<RewardDetails>>,
}

#[derive(Serialize, Deserialize)]
pub struct RewardDetails {
pub category: String,
pub quantity: i64,
pub title: String,
}
2 changes: 2 additions & 0 deletions src/models/mod.rs
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 7121963

Please sign in to comment.