pub struct WebClient {
pub config: Config,
pub puzzle_cache: Box<dyn PuzzleCache>,
pub session_cache: Box<dyn SessionCache>,
/* private fields */
}Expand description
HTTP-based implementation of the Client trait that talks with the Advent of Code website.
§Initialization Patterns
-
new()- Creates a client with default configuration. Requires a valid user config, a config in the local directory, or theAOC_SESSION_IDandAOC_PASSPHRASEenvironment variables to be set. -
with_options(ClientOptions)- Creates a client with custom configuration options (directories, passphrase, etc.). This is the standard path for most use cases. -
with_custom_impl(ClientConfig, Box<dyn AdventOfCodeProtocol>)- For testing usage. Allows callers to inject a mock HTTP implementation. Caches are still created automatically from the config.
§Dependencies
- Session ID: Required for authentication. Must be a valid Advent of Code session cookie.
- Network Access: Required for fetching new puzzles and submitting answers.
- Passphrase: Used to encrypt cached puzzle inputs on disk (as requested by AoC maintainer).
- Cache Directories: Created automatically if missing.
Fields§
§config: ConfigThe client configuration (session ID, cache directories, passphrase, etc)
puzzle_cache: Box<dyn PuzzleCache>Stores encrypted puzzle inputs and answer data.
session_cache: Box<dyn SessionCache>Stores submission timeout state.
Implementations§
Source§impl WebClient
impl WebClient
Sourcepub fn new() -> Result<Self, ClientError>
pub fn new() -> Result<Self, ClientError>
Creates a client with default configuration from environment variables.
Sourcepub fn with_config(config: Config) -> Self
pub fn with_config(config: Config) -> Self
Creates a client with custom configuration options.
Sourcepub fn with_custom_impl(
config: Config,
advent_protocol: Box<dyn ServiceConnector>,
) -> Self
pub fn with_custom_impl( config: Config, advent_protocol: Box<dyn ServiceConnector>, ) -> Self
Creates a client with a custom HTTP protocol implementation.
Useful for testing or using an alternative HTTP backend. Caches are automatically created from the provided config.
Trait Implementations§
Source§impl Client for WebClient
impl Client for WebClient
Source§fn years(&self) -> Vec<Year>
fn years(&self) -> Vec<Year>
Source§fn days(&self, year: Year) -> Option<Vec<Day>>
fn days(&self, year: Year) -> Option<Vec<Day>>
None is returned when year
is the current year, and the current month is not December.