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.list().await {
Ok(list) => {
let radio_models = &list.radio_models;
println!("Supported radio models {}<br>", radio_models.len());
for radio_model in radio_models {
println!("Radio model name - {}<br>", radio_model.name);
println!(
"Max. length of the radio serial number - {}<br>",
radio_model.serial_max_len
);
println!(
"Regex pattern for the radio serial number - {}<br>",
radio_model.serial_regex_pattern()
);
if radio_model.extra_max_len > 0 {
println!(
"Max. length of the radio extra data - {}<br>",
radio_model.extra_max_len
);
println!(
"Regex pattern for the radio extra data - {:?}<br>",
radio_model.extra_regex_pattern()
);
println!("<br>");
}
}
}
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}"),
},
}
}