aoc_leaderboard 1.0.0

Strongly-typed wrapper for Advent of Code leaderboard data
docs.rs failed to build aoc_leaderboard-1.0.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: aoc_leaderboard-0.2.0

aoc_leaderboard

CI codecov Security audit crates.io MSRV 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]
# Enable http feature to be able to fetch leaderboard data
aoc_leaderboard = { version = "1.0.0", features = ["http"] }

or by running:

cargo add aoc_leaderboard --features http

Example

use std::env;

use aoc_leaderboard::aoc::{Leaderboard, LeaderboardCredentials};
use dotenvy::dotenv;

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

    // Fetch leaderboard ID and AoC credentials from the environment.
    let leaderboard_id = env::var("AOC_LEADERBOARD_ID")?.parse()?;
    let credentials = aoc_credentials()?;

    // 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, &credentials).await?;

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

    Ok(())
}

fn aoc_credentials() -> anyhow::Result<LeaderboardCredentials> {
    Ok(env::var("AOC_VIEW_KEY")
        .map(LeaderboardCredentials::ViewKey)
        .or_else(|_| env::var("AOC_SESSION").map(LeaderboardCredentials::SessionCookie))?)
}

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

Minimum Rust version

aoc_leaderboard currently builds on Rust 1.88 or newer.

Contributing / Local development

For information about contributing to this project, see CONTRIBUTING. For information regarding local development, see DEVELOPMENT.