Skip to content

Commit b78c348

Browse files
bbelderbosclaude
andcommitted
feat: add API key support to exercise downloader
Read PYBITES_API_KEY env var and send X-API-Key header when set. Without it, only free exercises are downloaded. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7a583c0 commit b78c348

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

exercise_downloader/src/main.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
148148
// define the base_path (current directory / exercises)
149149
let base_path = env::current_dir().unwrap().join("exercises");
150150

151-
print!("Downloading the exercises from Pybites Rust (rustplatform.com)");
151+
let api_key = env::var("PYBITES_API_KEY").ok();
152+
152153
let client = reqwest::blocking::Client::new();
153-
let response = client.get("https://rustplatform.com/api/").send()?;
154+
let mut request = client.get("https://rustplatform.com/api/");
155+
if let Some(ref key) = api_key {
156+
println!("Authenticating with API key");
157+
request = request.header("X-API-Key", key);
158+
} else {
159+
println!("No API key set (PYBITES_API_KEY), downloading free exercises only");
160+
}
161+
162+
print!("Downloading the exercises from Pybites Rust (rustplatform.com)");
163+
let response = request.send()?;
154164
println!(" ✅");
155165
println!(
156166
"'exercises' will be created in the current directory ({})",

0 commit comments

Comments
 (0)