-
Notifications
You must be signed in to change notification settings - Fork 20
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
base: main
Are you sure you want to change the base?
Conversation
aoc-client/src/lib.rs
Outdated
debug!("🦌 Fetching global leaderboard for {}", self.year); | ||
|
||
let url = format!("https://adventofcode.com/{}/leaderboard", self.year); | ||
let response = reqwest::blocking::get(url)?; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()?; |
There was a problem hiding this comment.
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));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense! Added :)
Thanks for this! I haven't finished reviewing it but I dropped some initial comments |
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: