earthmc 2.0.6

Async client for interacting with the EarthMC API
Documentation
use std::sync::Arc;

use earthmc::{
    client::ClientBuilder, model::query::SimpleQueryBuilder,
    retry_strategy::NeverRetry,
};
use parking_lot::Mutex;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = ClientBuilder::default()
        .retry_strategy(Arc::new(Mutex::new(NeverRetry)))
        .build();

    let query = SimpleQueryBuilder::default()
        .insert("London")
        .insert_many(["Berlin", "Paris", "Rome"])
        .insert("this town doesn't exist") // towns that don't exist are simply omitted
        .build()?;

    let towns = client.towns(query).await?;

    for town in &towns {
        println!(
            "{}'s town, {}, has {} gold, {} residents, and {} town blocks.",
            town.mayor.name,
            town.name,
            town.stats.balance,
            town.stats.num_residents,
            town.stats.num_town_blocks
        );
    }

    Ok(())
}