Refactor
This commit is contained in:
parent
2a9a7d55e9
commit
97d6bb6a07
10
src/lib.rs
10
src/lib.rs
@ -22,9 +22,7 @@ pub fn guild(name: &str) -> Result<Guild, Box<Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn guild_by_prefix(prefix: &str) -> Result<Option<GuildEntry>, Box<Error>> {
|
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 = guild_leaderboard()?;
|
||||||
|
|
||||||
let top_100: Top100Guilds = serde_json::from_reader(resp)?;
|
|
||||||
|
|
||||||
for guild in top_100.data.into_iter() {
|
for guild in top_100.data.into_iter() {
|
||||||
if guild.prefix == prefix {
|
if guild.prefix == prefix {
|
||||||
@ -35,6 +33,12 @@ pub fn guild_by_prefix(prefix: &str) -> Result<Option<GuildEntry>, Box<Error>> {
|
|||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn guild_leaderboard() -> Result<Top100Guilds, Box<Error>> {
|
||||||
|
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)]
|
#[derive(Deserialize)]
|
||||||
pub struct Top100Guilds {
|
pub struct Top100Guilds {
|
||||||
pub data: Vec<GuildEntry>
|
pub data: Vec<GuildEntry>
|
||||||
|
Loading…
Reference in New Issue
Block a user