Skip to content

Commit

Permalink
feat: support full champion data (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
kade-robertson authored Jan 23, 2023
1 parent bca7c0b commit 2eaa347
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 12 deletions.
8 changes: 6 additions & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use mockito;
use crate::cache_middleware::CacheMiddleware;

use crate::models::{
Challenges, Champions, Items, Maps, MissionAssets, ProfileIcons, Runes, SpellBuffs,
SummonerSpells, Translations,
Challenges, Champions, ChampionsFull, Items, Maps, MissionAssets, ProfileIcons, Runes,
SpellBuffs, SummonerSpells, Translations,
};

#[derive(Error, Debug)]
Expand Down Expand Up @@ -106,6 +106,10 @@ impl DDragonClient {
self.get_data::<Champions>("./champion.json")
}

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

pub fn items(&self) -> Result<Items, DDragonClientError> {
self.get_data::<Items>("./item.json")
}
Expand Down
106 changes: 106 additions & 0 deletions src/models/champions_full.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Example code that deserializes and serializes the model.
// extern crate serde;
// #[macro_use]
// extern crate serde_derive;
// extern crate serde_json;
//
// use generated_module::ChampionsComplete;
//
// fn main() {
// let json = r#"{"answer": 42}"#;
// let model: ChampionsComplete = serde_json::from_str(&json).unwrap();
// }

use serde::{Deserialize, Serialize};
use std::collections::HashMap;

use super::{
champions::{Info, Tag},
shared::Image,
};

#[derive(Serialize, Deserialize)]
pub struct ChampionsFull {
pub format: String,
pub version: String,
pub data: HashMap<String, ChampionFull>,
pub keys: HashMap<String, String>,
}

#[derive(Serialize, Deserialize)]
pub struct ChampionFull {
pub id: String,
pub key: String,
pub name: String,
pub title: String,
pub image: Image,
pub skins: Vec<Skin>,
pub lore: String,
pub blurb: String,
pub allytips: Vec<String>,
pub enemytips: Vec<String>,
pub tags: Vec<Tag>,
pub partype: String,
pub info: Info,
pub stats: HashMap<String, f64>,
pub spells: Vec<Spell>,
pub passive: Passive,
}

#[derive(Serialize, Deserialize)]
pub struct Passive {
pub name: String,
pub description: String,
pub image: Image,
}

#[derive(Serialize, Deserialize)]
pub struct Skin {
pub id: String,
pub num: i64,
pub name: String,
pub chromas: bool,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Spell {
pub id: String,
pub name: String,
pub description: String,
pub tooltip: String,
pub leveltip: Option<Leveltip>,
pub maxrank: i64,
pub cooldown: Vec<f64>,
#[serde(rename = "cooldownBurn")]
pub cooldown_burn: String,
pub cost: Vec<i64>,
#[serde(rename = "costBurn")]
pub cost_burn: String,
pub effect: Vec<Option<Vec<f64>>>,
#[serde(rename = "effectBurn")]
pub effect_burn: Vec<Option<String>>,
#[serde(rename = "costType")]
pub cost_type: String,
pub maxammo: String,
pub range: Vec<i64>,
#[serde(rename = "rangeBurn")]
pub range_burn: String,
pub image: Image,
pub resource: Option<String>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Leveltip {
pub label: Vec<String>,
pub effect: Vec<String>,
}

#[derive(Serialize, Deserialize, Clone, Copy, Debug)]
pub enum Type {
#[serde(rename = "champion")]
Champion,
#[serde(rename = "passive")]
Passive,
#[serde(rename = "spell")]
Spell,
}
2 changes: 2 additions & 0 deletions src/models/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod challenges;
pub mod champions;
pub mod champions_full;
pub mod items;
pub mod maps;
pub mod mission_assets;
Expand All @@ -12,6 +13,7 @@ pub mod translations;

pub use challenges::Challenges;
pub use champions::Champions;
pub use champions_full::ChampionsFull;
pub use items::Items;
pub use maps::Maps;
pub use mission_assets::MissionAssets;
Expand Down
12 changes: 2 additions & 10 deletions src/models/summoner_spells.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,11 @@ pub struct SummonerSpell {
pub summoner_level: i64,
pub modes: Vec<String>,
#[serde(rename = "costType")]
pub cost_type: CostType,
pub cost_type: String,
pub maxammo: String,
pub range: Vec<i64>,
#[serde(rename = "rangeBurn")]
pub range_burn: String,
pub image: Image,
pub resource: CostType,
}

#[derive(Serialize, Deserialize, Clone, Copy, Debug)]
pub enum CostType {
#[serde(rename = "&nbsp;")]
Nbsp,
#[serde(rename = "No Cost")]
NoCost,
pub resource: Option<String>,
}
2 changes: 2 additions & 0 deletions tests/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ fn health_check() {
let uncached_start = Instant::now();
client.challenges().unwrap();
client.champions().unwrap();
client.champions_full().unwrap();
client.items().unwrap();
client.maps().unwrap();
client.mission_assets().unwrap();
Expand All @@ -26,6 +27,7 @@ fn health_check() {
let cached_start = Instant::now();
client.challenges().unwrap();
client.champions().unwrap();
client.champions_full().unwrap();
client.items().unwrap();
client.maps().unwrap();
client.mission_assets().unwrap();
Expand Down

0 comments on commit 2eaa347

Please sign in to comment.