radio-code-calculator 1.0.1

Radio Code Calculator is an online service along with Web API and SDK for generating car radio unlock codes for popular vehicle brands.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
# Radio Code Calculator Online & SDK for Rust

[![crates.io](https://img.shields.io/crates/v/radio-code-calculator.svg)](https://crates.io/crates/radio-code-calculator)
[![docs.rs](https://img.shields.io/docsrs/radio-code-calculator)](https://docs.rs/radio-code-calculator)
[![License](https://img.shields.io/crates/l/radio-code-calculator)](https://crates.io/crates/radio-code-calculator)

**[Radio Code Calculator](https://www.pelock.com/products/radio-code-calculator)** is an online service along with [Web API & SDK](https://www.pelock.com/products/radio-code-calculator/sdk) for generating car radio unlock codes for popular vehicle brands.

Following a breakdown or a disconnection of the car battery, most of the vehicle radio & navigation units will ask for an unlocking code. It's standard anti-theft protection.

Our car Radio Code Calculator allows you to generate **100% valid** radio codes to unlock car radios & navigation without the need to use the expensive service of authorized dealers.

![Radio Code Calculator](https://www.pelock.com/img/en/products/radio-code-calculator/car-radio-code-calculator-online-web-api-sdk.jpg)

The service is available through a simple online interface and `Web API`, with multiple `SDK` development libraries for popular programming languages.

Thanks to our solution, you can create, for instance, mobile or web applications that allow for easy generation of radio codes.

## Supported car models and radios

Our service is being continuously developed and new algorithms are gradually added for new car models and their radios.

If a new algorithm is added, you will get automatic and free access to it as part of your current license.

Individual calculators are available on our site as a paid service for end customers. You can verify them and see lists of supported radios on the relevant subpages:

* [Renault & Dacia]https://www.pelock.com/products/renault-and-dacia-car-radio-code-calculator-generator
* [Toyota ERC]https://www.pelock.com/products/toyota-erc-calculator-radio-unlock-code-generator
* [Jeep Cherokee]https://www.pelock.com/products/jeep-cherokee-radio-unlock-code-calculator-generator
* [Ford M Serial]https://www.pelock.com/products/ford-radio-code-m-serial-calculator-generator
* [Ford V Serial]https://www.pelock.com/products/ford-radio-code-v-serial-calculator-generator
* [Ford TravelPilot EX, FX & NX]https://www.pelock.com/products/ford-travelpilot-ex-fx-nx-radio-code-generator-calculator
* [Chrysler Panasonic TM9]https://www.pelock.com/products/chrysler-panasonic-tm9-car-radio-code-calculator-generator
* [Chrysler Dodge Ram VP2]https://www.pelock.com/products/chrysler-dodge-ram-uconnect-harman-kardon-radio-code
* [Fiat Stilo & Bravo Visteon]https://www.pelock.com/products/fiat-stilo-bravo-visteon-radio-code-calculator-generator
* [Fiat DAIICHI MOPAR]https://www.pelock.com/products/fiat-daiichi-radio-code-calculator-generator
* [Fiat Continental 250 & 500 VP1/VP2]https://www.pelock.com/products/fiat-250-500-vp1-vp2-radio-code-calculator-generator
* [Nissan Glove Box Immobiliser PIN]https://www.pelock.com/products/nissan-glove-box-pin-code-calculator
* [Eclipse ESN Unlock Code Calculator]https://www.pelock.com/products/eclipse-esn-unlock-code-calculator
* [Jaguar Alpine]https://www.pelock.com/products/jaguar-alpine-car-radio-unlock-code-calculator

## Use of radio code calculator

Where and who can use the radio code generation service and make money from code generation?

### ![Android]https://www.pelock.com/img/en/icons/android-32.png App developers
The main audience for our software is clearly developers and programmers, either of mobile or desktop applications.

### ![Shopping cart]https://www.pelock.com/img/en/icons/cart-32.png Online stores
If you run an online e-commerce store, you can sell radio codes through it using our software solutions.

### ![Car]https://www.pelock.com/img/en/icons/car-32.png Auto repair shops
We also encourage car repair shops whose customers often use car radio unlocking services.

### ![Person]https://www.pelock.com/img/en/icons/user-32.png Private individuals
Private individuals will also profit from our solution by generating codes and selling them on car forums or auction sites such as eBay, Craigslist.

### No limits!

You can generate codes **without limitation** with your purchased one-year license.

Set your own price for generating a single code and start earning by using **tried and tested** algorithms from a programming language you know.

If you are not a programmer - don't worry. Just use our [online calculator](https://www.pelock.com/products/radio-code-calculator/online).

## Installation

The preferred way to add the Web API client is with [Cargo](https://doc.rust-lang.org/cargo/):

```text
cargo add radio-code-calculator
```

Or add to your `Cargo.toml`:

```toml
[dependencies]
radio-code-calculator = "1.0.0"
```

Examples in this repository use [Tokio](https://tokio.rs/) as the async runtime (`#[tokio::main]`). Add Tokio to your binary crate:

```toml
[dependencies]
radio-code-calculator = "1.0.0"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
```

Run an example:

```text
cargo run --example RadioCodeCalculatorSimple
```

### Integration tests

Live API tests in `tests/test_radio_code_calculator.rs` require an active Web API license. Set `RADIO_CODE_CALCULATOR_API_KEY` and run ignored tests:

```text
set RADIO_CODE_CALCULATOR_API_KEY=your-key-here
cargo test -- --ignored
```

The default `cargo test` run executes only checks that do not depend on a valid license (for example, invalid key handling).

## Packages for other programming languages

The installation packages have been uploaded to repositories for several popular programming languages and their source codes have been published on GitHub:

| Repository   | Language | Installation | Package | GitHub |
| ------------ | ---------| ------------ | ------- | ------ |
| ![Packagist repository for PHP and Composer]https://www.pelock.com/img/logos/repo-packagist-composer.png | PHP | Add the following line to `require` section of your `composer.json` file `"pelock/radio-code-calculator": "*"` | [Packagist]https://packagist.org/packages/pelock/radio-code-calculator | [Sources]https://github.com/PELock/Radio-Code-Calculator-PHP
| ![PyPI repository for Python]https://www.pelock.com/img/logos/repo-pypi.png | Python | Run `pip install radio-code-calculator` | [PyPi]https://pypi.org/project/radio-code-calculator/ | [Sources]https://github.com/PELock/Radio-Code-Calculator-Python
| ![NPM repository for JavaScript and TypeScript]https://www.pelock.com/img/logos/repo-npm.png | JavaScript, TypeScript | Run `npm i radio-code-calculator` or add the following to `dependencies` section of your `package.json` file `"dependencies": { "radio-code-calculator": "latest" },` | [NPM]https://www.npmjs.com/package/radio-code-calculator | [Sources]https://github.com/PELock/Radio-Code-Calculator-JavaScript
| ![Rust / Cargo]https://www.pelock.com/img/logos/repo-crates.png | Rust | Run `cargo add radio-code-calculator` or add `radio-code-calculator = "1.0.0"` to `[dependencies]` in `Cargo.toml` | [crates.io]https://crates.io/crates/radio-code-calculator | [Sources]https://github.com/PELock/Radio-Code-Calculator-Rust

## Usage examples

### Radio code generation

This example demonstrates code generation for a selected radio model. All input parameter validation is done on the server side and if the radio serial number has an invalid length or pattern - the service will return an error.

```rust
/******************************************************************************
 *
 * Radio Code Calculator API - WebApi interface usage example
 *
 * In this example, we will demonstrate how to generate a code for a specific
 * type of car radio.
 *
 * Version      : v1.0.0
 * Rust         : 2021
 * Dependencies : radio-code-calculator
 * Author       : Bartosz Wójcik (support@pelock.com)
 * Project      : https://www.pelock.com/products/radio-code-calculator
 * Homepage     : https://www.pelock.com
 *
 * @link https://www.pelock.com/products/radio-code-calculator
 * @copyright Copyright (c) 2021-2026 PELock LLC
 * @license Apache-2.0
 *
 *****************************************************************************/

//
// include Radio Code Calculator API module
//
use radio_code_calculator::{RadioCodeCalculator, RadioCodeCalculatorError, RadioErrors, RadioModels};

#[tokio::main]
async fn main() {
    //
    // create Radio Code Calculator API class instance (we are using our activation key)
    //
    let my_radio_code_calculator =
        RadioCodeCalculator::new(Some("ABCD-ABCD-ABCD-ABCD".to_string()));

    //
    // generate radio code (using Web API)
    //
    match my_radio_code_calculator
        .calc(&*RadioModels::FORD_M_SERIES, "123456", "")
        .await
    {
        Ok(result) => {
            println!("Radio code is {}", result["code"]);
        }
        Err(e) => match e {
            RadioCodeCalculatorError::ApiError(ref v) => match v["error"].as_i64().unwrap_or(-1) as i32 {
                RadioErrors::INVALID_RADIO_MODEL => {
                    println!("Invalid radio model (not supported)");
                }
                RadioErrors::INVALID_SERIAL_LENGTH => println!(
                    "Invalid serial number length (expected {} characters)",
                    v["serialMaxLen"]
                ),
                RadioErrors::INVALID_SERIAL_PATTERN => println!(
                    "Invalid serial number regular expression pattern (expected {} regex pattern)",
                    v["serialRegexPattern"]["php"]
                ),
                RadioErrors::INVALID_SERIAL_NOT_SUPPORTED => {
                    println!("This serial number is not supported");
                }
                RadioErrors::INVALID_EXTRA_LENGTH => println!(
                    "Invalid extra data length (expected {} characters)",
                    v["extraMaxLen"]
                ),
                RadioErrors::INVALID_EXTRA_PATTERN => println!(
                    "Invalid extra data regular expression pattern (expected {} regex pattern",
                    v["extraRegexPattern"]["php"]
                ),
                RadioErrors::INVALID_INPUT => println!("Invalid input data"),
                RadioErrors::INVALID_COMMAND => {
                    println!("Invalid command sent to the Web API interface");
                }
                RadioErrors::INVALID_LICENSE => println!("Invalid license key!"),
                _ => 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}");
            }
        },
    }
}
```

### Radio code generation with additional offline validation

Radio codes are generated based on input parameters such as the **radio's serial number**, among others.

Radio serial numbers are different for different radios, they have different lengths and different patterns, some may consist of just digits e.g. `1234`, while others may consist of digits and letters e.g. `AB1234XYZ`.

Validation of this data is done on the server side. However, to make things more efficient, we can use the information about available limits and patterns of particular serial numbers to, for example, set these limits in controls in our own applications without unnecessary calls to the `Web API`.

```rust
/******************************************************************************
 *
 * Radio Code Calculator API - WebApi interface usage example
 *
 * In this example, we will demonstrate how to generate a code for a specific
 * type of car radio. This example shows how to use an extended offline
 * validation.
 *
 * Version      : v1.0.0
 * Rust         : 2021
 * Dependencies : radio-code-calculator
 * Author       : Bartosz Wójcik (support@pelock.com)
 * Project      : https://www.pelock.com/products/radio-code-calculator
 * Homepage     : https://www.pelock.com
 *
 * @link https://www.pelock.com/products/radio-code-calculator
 * @copyright Copyright (c) 2021-2026 PELock LLC
 * @license Apache-2.0
 *
 *****************************************************************************/

//
// include Radio Code Calculator API module
//
use radio_code_calculator::{RadioCodeCalculator, RadioCodeCalculatorError, RadioErrors, RadioModels};

#[tokio::main]
async fn main() {
    //
    // create Radio Code Calculator API class instance (we are using our activation key)
    //
    let my_radio_code_calculator =
        RadioCodeCalculator::new(Some("ABCD-ABCD-ABCD-ABCD".to_string()));

    //
    // generate a single radio unlocking code
    //
    let serial = "123456";
    let extra = "";

    //
    // select a radio model
    //
    let radio_model = &*RadioModels::FORD_M_SERIES;

    //
    // display radio model information, you can use it to set limits in your controls e.g.
    //
    // textFieldRadioSerial.maxLength = radioModel.serial_max_len
    // textFieldRadioSerial.regEx = radioModel.serial_regex_pattern()
    //
    // (if allowed by your controls)
    //
    println!(
        "Radio model {} expects a serial number of {} length and {} regex pattern<br>",
        radio_model.name,
        radio_model.serial_max_len,
        radio_model.serial_regex_pattern()
    );

    // additional information
    if radio_model.extra_max_len > 0 {
        println!(
            "Additionally an extra field is required with {} and {:?} regex pattern<br>",
            radio_model.extra_max_len,
            radio_model.extra_regex_pattern()
        );
    }

    //
    // validate the serial number (offline) before sending the Web API request
    //
    let error = radio_model.validate(serial, Some(extra));

    if error != RadioErrors::SUCCESS {
        if error == RadioErrors::INVALID_SERIAL_LENGTH {
            println!(
                "Invalid serial number length (expected {} characters<br>",
                radio_model.serial_max_len
            );
        } else if error == RadioErrors::INVALID_SERIAL_PATTERN {
            println!(
                "Invalid serial number regular expression pattern (expected {} regex pattern)<br>",
                radio_model.serial_regex_pattern()
            );
        } else if error == RadioErrors::INVALID_SERIAL_NOT_SUPPORTED {
            println!("This serial number is not supported");
        } else if error == RadioErrors::INVALID_EXTRA_LENGTH {
            println!(
                "Invalid extra data length (expected {} characters)<br>",
                radio_model.extra_max_len
            );
        } else if error == RadioErrors::INVALID_EXTRA_PATTERN {
            println!(
                "Invalid extra data regular expression pattern (expected {:?} regex pattern)<br>",
                radio_model.extra_regex_pattern()
            );
        }
        std::process::exit(1);
    }

    //
    // generate radio code (using Web API)
    //
    match my_radio_code_calculator
        .calc(radio_model, serial, extra)
        .await
    {
        Ok(result) => println!("Radio code is {}", result["code"]),
        Err(e) => match e {
            RadioCodeCalculatorError::ApiError(ref v) => match v["error"].as_i64().unwrap_or(-1) as i32 {
                RadioErrors::INVALID_RADIO_MODEL => {
                    println!("Invalid radio model (not supported)");
                }
                RadioErrors::INVALID_SERIAL_LENGTH => println!(
                    "Invalid serial number length (expected {} characters)",
                    v["serialMaxLen"]
                ),
                RadioErrors::INVALID_SERIAL_PATTERN => println!(
                    "Invalid serial number regular expression pattern (expected {} regex pattern)",
                    v["serialRegexPattern"]["php"]
                ),
                RadioErrors::INVALID_SERIAL_NOT_SUPPORTED => {
                    println!("This serial number is not supported");
                }
                RadioErrors::INVALID_EXTRA_LENGTH => println!(
                    "Invalid extra data length (expected {} characters)",
                    v["extraMaxLen"]
                ),
                RadioErrors::INVALID_EXTRA_PATTERN => println!(
                    "Invalid extra data regular expression pattern (expected {} regex pattern)",
                    v["extraRegexPattern"]["php"]
                ),
                RadioErrors::INVALID_INPUT => println!("Invalid input data"),
                RadioErrors::INVALID_COMMAND => {
                    println!("Invalid command sent to the Web API interface");
                }
                RadioErrors::INVALID_LICENSE => println!("Invalid license key!"),
                _ => 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}"),
        },
    }
}
```

### Download list of supported radio code calculators

If you would like to download information about all supported radio models and their parameters such as serial number length and pattern - you can do so.

```rust
/******************************************************************************
 *
 * Radio Code Calculator API - WebApi interface usage example
 *
 * In this example we will list all the available calculators and, their
 * parameters like name, maximum length of the radio serial number and its
 * regex pattern.
 *
 * Version      : v1.0.0
 * Rust         : 2021
 * Dependencies : radio-code-calculator
 * Author       : Bartosz Wójcik (support@pelock.com)
 * Project      : https://www.pelock.com/products/radio-code-calculator
 * Homepage     : https://www.pelock.com
 *
 * @link https://www.pelock.com/products/radio-code-calculator
 * @copyright Copyright (c) 2021-2026 PELock LLC
 * @license Apache-2.0
 *
 *****************************************************************************/

//
// include Radio Code Calculator API module
//
use radio_code_calculator::{RadioCodeCalculator, RadioCodeCalculatorError, RadioErrors};

#[tokio::main]
async fn main() {
    //
    // create Radio Code Calculator API class instance (we are using our activation key)
    //
    let my_radio_code_calculator =
        RadioCodeCalculator::new(Some("ABCD-ABCD-ABCD-ABCD".to_string()));

    //
    // get the list of the supported radio calculators and their parameters (max. length, regex pattern)
    //
    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()
                );

                // is extra field specified?
                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}"),
        },
    }
}
```

### Downloading the parameters of the selected radio calculator

You can download the parameters of the selected calculator.

```rust
/******************************************************************************
 *
 * Radio Code Calculator API - WebApi interface usage example
 *
 * In this example, we will demonstrate how to get information about the
 * specific radio calculator and its parameters (max. length & regex pattern).
 *
 * Version      : v1.0.0
 * Rust         : 2021
 * Dependencies : radio-code-calculator
 * Author       : Bartosz Wójcik (support@pelock.com)
 * Project      : https://www.pelock.com/products/radio-code-calculator
 * Homepage     : https://www.pelock.com
 *
 * @link https://www.pelock.com/products/radio-code-calculator
 * @copyright Copyright (c) 2021-2026 PELock LLC
 * @license Apache-2.0
 *
 *****************************************************************************/

//
// include Radio Code Calculator API module
//
use radio_code_calculator::{RadioCodeCalculator, RadioCodeCalculatorError, RadioErrors};

#[tokio::main]
async fn main() {
    //
    // create Radio Code Calculator API class instance (we are using our activation key)
    //
    let my_radio_code_calculator =
        RadioCodeCalculator::new(Some("ABCD-ABCD-ABCD-ABCD".to_string()));

    //
    // query information about the radio model
    //
    match my_radio_code_calculator.info("ford-m-series").await {
        Ok(info) => {
            let radio_model = &info.radio_model;

            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()
            );

            // is extra field specified?
            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(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["error"]
                    );
                }
            }
            RadioCodeCalculatorError::InvalidLicense => println!("Invalid license key!"),
            RadioCodeCalculatorError::Transport(msg) => println!("Connection error: {msg}"),
        },
    }
}
```

### Checking activation key

By checking the activation key status, we will get information about the license owner, license type and license expiration date.

```rust
/******************************************************************************
 *
 * Radio Code Calculator API - WebApi interface usage example
 *
 * In this example we will verify our activation key status.
 *
 * Version      : v1.0.0
 * Rust         : 2021
 * Dependencies : radio-code-calculator
 * Author       : Bartosz Wójcik (support@pelock.com)
 * Project      : https://www.pelock.com/products/radio-code-calculator
 * Homepage     : https://www.pelock.com
 *
 * @link https://www.pelock.com/products/radio-code-calculator
 * @copyright Copyright (c) 2021-2026 PELock LLC
 * @license Apache-2.0
 *
 *****************************************************************************/

//
// include Radio Code Calculator API module
//
use radio_code_calculator::{RadioCodeCalculator, RadioCodeCalculatorError, RadioErrors};

#[tokio::main]
async fn main() {
    //
    // create Radio Code Calculator API class instance (we are using our activation key)
    //
    let my_radio_code_calculator =
        RadioCodeCalculator::new(Some("ABCD-ABCD-ABCD-ABCD".to_string()));

    //
    // login to the service
    //
    match my_radio_code_calculator.login().await {
        Ok(result) => {
            //
            // result[] array holds the information about the license
            //
            // result["license"]["activationStatus"] - True if license is active, False on invalid/expired keys
            // result["license"]["userName"] - user name/company name of the license owner
            // result["license"]["type"] - license type (0 - Personal License, 1 - Company License)
            // result["license"]["expirationDate"] - license expiration date (in YYYY-MM-DD format)
            //
            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}"),
        },
    }
}
```

## Got questions?

If you are interested in the Radio Code Calculator Web API or have any questions regarding radio code generator SDK packages, technical or legal issues, or if something is not clear, [please contact me](https://www.pelock.com/contact). I'll be happy to answer all of your questions.

Bartosz Wójcik

* Visit my site at — https://www.pelock.com
* X — https://x.com/PELock
* GitHub — https://github.com/PELock