From 97d6bb6a0741edb4f925e4487e6c6d52f90136d0 Mon Sep 17 00:00:00 2001 From: Sakuhl <2012collector@gmail.com> Date: Tue, 2 Jan 2018 00:40:38 +0100 Subject: [PATCH] Refactor --- src/lib.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index dd11c51..331c419 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,9 +22,7 @@ pub fn guild(name: &str) -> Result> { } 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)?; + let top_100 = guild_leaderboard()?; for guild in top_100.data.into_iter() { if guild.prefix == prefix { @@ -35,6 +33,12 @@ pub fn guild_by_prefix(prefix: &str) -> Result, Box> { Ok(None) } +pub fn guild_leaderboard() -> Result> { + let resp = reqwest::get("https://api.wynncraft.com/public_api.php?action=statsLeaderboard&type=guild&timeframe=alltime")?; + + Ok(serde_json::from_reader(resp)?) +} + #[derive(Deserialize)] pub struct Top100Guilds { pub data: Vec