Merged some common code into its own function.

A lot of response handling code from API.Get() and API.Post() has been
merged into the API.handleResponse method in accordance with the DRY
principle.
More specific default user agent.