Add guild list api

This commit is contained in:
Sakuhl 2018-01-15 13:25:26 +01:00
parent 6cc5a4d140
commit 8b3427867d

View File

@ -32,6 +32,17 @@ pub fn guild(name: &str) -> Result<Option<Guild>, Error> {
} }
} }
pub fn guild_list() -> Result<Vec<String>, Error> {
let resp = reqwest::get("https://api.wynncraft.com/public_api.php?action=guildList")?.text().unwrap();
if let Ok(error) = serde_json::from_str::<APIError>(&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<Option<GuildEntry>, Error> { pub fn guild_by_prefix(prefix: &str) -> Result<Option<GuildEntry>, Error> {
let top_100 = guild_leaderboard()?; let top_100 = guild_leaderboard()?;
@ -55,6 +66,11 @@ pub struct APIError {
pub error: String pub error: String
} }
#[derive(Deserialize)]
pub struct GuildList {
pub guilds: Vec<String>
}
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct Top100Guilds { pub struct Top100Guilds {
pub data: Vec<GuildEntry> pub data: Vec<GuildEntry>