use radio_code_calculator::{RadioCodeCalculator, RadioCodeCalculatorError, RadioErrors};
#[tokio::main]
async fn main() {
let my_radio_code_calculator =
RadioCodeCalculator::new(Some("ABCD-ABCD-ABCD-ABCD".to_string()));
match my_radio_code_calculator.login().await {
Ok(result) => {
let license = &result["license"];
println!(
"License activation status - {}<br>",
if license["activationStatus"].as_bool().unwrap_or(false) {
"True"
} else {
"False"
}
);
println!("License owner - {}", license["userName"]);
println!(
"License type - {}<br>",
if license["type"].as_i64() == Some(0) {
"Personal"
} else {
"Company"
}
);
println!("Expiration date - {}<br>", license["expirationDate"]);
}
Err(e) => match e {
RadioCodeCalculatorError::ApiError(ref v) => {
if v["error"].as_i64() == Some(RadioErrors::INVALID_LICENSE as i64) {
println!("Invalid license key!");
} else {
println!("Something unexpected happen while trying to login to the service (error code {v:?}).");
}
}
RadioCodeCalculatorError::InvalidLicense => println!("Invalid license key!"),
RadioCodeCalculatorError::Transport(msg) => println!("Connection error: {msg}"),
},
}
}