Refactor TOSDR API calls

This commit extracts the common logic for TOSDR API calls to a separate function and should not change any behaviour.

This will make it easier to update the code when the TOSDR API changes (as everything is grouped) and should also make it easier to test if we ever decided to do so.

The end goal is to make to `main.js` file easier to read and maintain as it now has all behaviour grouped in a single file.

@AbdullahDiaa, feel free to jump in and tell me what you think. Do you like this approach, do you think it improves the code a bit or not? Looking forward hearing from you.