Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Global leaderboard #17

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

WillLillis
Copy link
Contributor

As suggested in CONTRIBUTING.md, this feature adds the ability to display the Global Leaderboard for a given year.

I've tested this on all years and it appears to be functioning correctly, but I'm happy to refactor/ fix things if they're not up to standard :)

Screenshot of (the start of) 2022:
image

debug!("🦌 Fetching global leaderboard for {}", self.year);

let url = format!("https://adventofcode.com/{}/leaderboard", self.year);
let response = reqwest::blocking::get(url)?;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to use reqwest directly instead of calling http_client? This way you're missing some common error handling there and also not passing the user agent header.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just used reqwest directly because I saw the session cookie wasn't required for grabbing the global leaderboard. Happy to switch it over for the error handling :)


let url = format!("https://adventofcode.com/{}/leaderboard", self.year);
let response = reqwest::blocking::get(url)?;
let contents = response.error_for_status()?.text()?;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a good idea to handle NOT FOUND which can only happen if the year is invalid (like it's done in get_calendar_html):

        if response.status() == StatusCode::NOT_FOUND {
            // A 404 reponse means the leaderboard for
            // the requested year is not yet available
            return Err(AocError::InvalidEventYear(self.year));
        }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! Added :)

@scarvalhojr
Copy link
Owner

Thanks for this! I haven't finished reviewing it but I dropped some initial comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants