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

aoc_leaderboard

Strongly-typed wrapper for Advent of Code leaderboard data

2 unstable releases

0.2.0 Jan 19, 2025
0.1.0 Dec 28, 2024

#617 in Asynchronous

Download history 57/week @ 2024-12-22 29/week @ 2024-12-29 1/week @ 2025-01-05 116/week @ 2025-01-19 3/week @ 2025-01-26 8/week @ 2025-02-02

127 downloads per month
Used in aoc_leaderbot_lib

MIT license

23KB
255 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

~0.9–12MB
~140K SLoC