Add rate limiting example

This commit is contained in:
Koen Bolhuis 2021-01-30 03:08:42 +01:00
parent 508f697a51
commit 44319feb79
1 changed files with 27 additions and 0 deletions

27
examples/rate_limiting.rs Normal file
View File

@ -0,0 +1,27 @@
use listenbrainz::raw::Client;
fn main() {
let token = std::env::args().nth(1).expect("No token provided");
let client = Client::new();
loop {
match client.validate_token(&token) {
Ok(response) => {
println!("{:?}", response.rate_limit);
if let Some(remaining) = response.rate_limit.map(|r| r.remaining) {
if remaining == 0 {
break;
}
} else {
break;
}
}
Err(err) => {
eprintln!("{}", err);
break;
}
}
}
}