I wrote Python (https://github.com/wbond/vat_moss-python) and JS (https://github.com/wbond/vat-moss.js) libraries for this. They include docs about how to handle other aspects of VAT MOSS also.
Included are methods to determine the applicable rate based on self-declared location, billing address, phone number or IP address. The Python library includes functionality to grab exchange rates and perform VAT ID validation.