From 8b3427867d7867f7333e15f5375c5555524062b9 Mon Sep 17 00:00:00 2001 From: Sakuhl <2012collector@gmail.com> Date: Mon, 15 Jan 2018 13:25:26 +0100 Subject: [PATCH] Add guild list api --- src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 57deaf6..cf65cf5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,6 +32,17 @@ pub fn guild(name: &str) -> Result, Error> { } } +pub fn guild_list() -> Result, Error> { + let resp = reqwest::get("https://api.wynncraft.com/public_api.php?action=guildList")?.text().unwrap(); + + if let Ok(error) = serde_json::from_str::(&resp) { + bail!("API error ({})", error.error); + } else { + let list: GuildList = serde_json::from_str(&resp)?; + Ok(list.guilds) + } +} + pub fn guild_by_prefix(prefix: &str) -> Result, Error> { let top_100 = guild_leaderboard()?; @@ -55,6 +66,11 @@ pub struct APIError { pub error: String } +#[derive(Deserialize)] +pub struct GuildList { + pub guilds: Vec +} + #[derive(Deserialize)] pub struct Top100Guilds { pub data: Vec