#advent-of-code #http #api #aoc #api-bindings

aoc_leaderboard

Strongly-typed wrapper for Advent of Code leaderboard data

1 unstable release

0.1.0 Dec 28, 2024

#662 in Asynchronous

Download history 85/week @ 2024-12-24 2/week @ 2024-12-31

87 downloads per month

MIT license

21KB
166 lines

aoc_leaderboard

CI codecov Security audit crates.io downloads docs.rs Contributor Covenant

Strongly-typed wrapper for an Advent of Code leaderboard and a convenient way to fetch its data.

Installing

Add aoc_leaderboard to your dependencies:

[dependencies]
aoc_leaderboard = "1.0.0"

or by running:

cargo add aoc_leaderboard

Example

use std::env;

use aoc_leaderboard::aoc::Leaderboard;
use dotenvy::dotenv;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Maybe your AoC token lives in a `.env` file?
    let _ = dotenv();

    // Fetch AoC session token and leaderboard ID from the environment.
    let aoc_token = env::var("AOC_TOKEN")?;
    let leaderboard_id = env::var("AOC_LEADERBOARD_ID")?.parse()?;

    // Load the leaderboard from the AoC website.
    // Careful not to call this more than once every **15 minutes**.
    let year = 2024;
    let leaderboard = Leaderboard::get(year, leaderboard_id, aoc_token).await?;

    // Do something useful.
    println!("Leaderboard for year {year} has {} members.", leaderboard.members.len());

    Ok(())
}

The above example is available here. For complete API usage, see the docs.

Minimum Rust version

aoc_leaderboard currently builds on Rust 1.70 or newer.

Dependencies

~1–12MB
~138K SLoC