Support guild lookup by prefix
This commit is contained in:
parent
b73034104c
commit
ba0d6c7709
32
src/lib.rs
32
src/lib.rs
@ -21,6 +21,38 @@ pub fn guild(name: &str) -> Result<Guild, Box<Error>> {
|
|||||||
Ok(serde_json::from_reader(resp)?)
|
Ok(serde_json::from_reader(resp)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn guild_by_prefix(prefix: &str) -> Result<Option<GuildEntry>, Box<Error>> {
|
||||||
|
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<GuildEntry>
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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)]
|
#[derive(Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Guild {
|
pub struct Guild {
|
||||||
|
Loading…
Reference in New Issue
Block a user