diff --git a/src/lib.rs b/src/lib.rs index 47833e8..33b3567 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,6 +21,38 @@ pub fn guild(name: &str) -> Result> { Ok(serde_json::from_reader(resp)?) } +pub fn guild_by_prefix(prefix: &str) -> Result, Box> { + let resp = reqwest::get("https://api.wynncraft.com/public_api.php?action=statsLeaderboard&type=guild&timeframe=alltime")?; + + let top_100: Top100Guilds = serde_json::from_reader(resp)?; + + for guild in &top_100.data { + if guild.prefix == prefix { + return Ok(Some(guild)); + } + } + + Ok(None) +} + +#[derive(Deserialize)] +pub struct Top100Guilds { + pub data: Vec +} + +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct GuildEntry { + pub name: String, + pub prefix: String, + pub xp: u64, + pub level: u64, + pub created: String, + pub territories: u64, + pub members_count: u64, + pub num: u64 +} + #[derive(Deserialize)] #[serde(rename_all = "camelCase")] pub struct Guild {