Both solutions are fine but you'll probably find that using the API is easier, especially since it's well documented.