Skip to content

Instantly share code, notes, and snippets.

@joshkehn
Created February 20, 2012 02:16
Show Gist options
  • Save joshkehn/1867282 to your computer and use it in GitHub Desktop.
Save joshkehn/1867282 to your computer and use it in GitHub Desktop.
function APIClient (config) {
this.config = config || { host : 'singly.com' };
this.config.baseUrl = 'https://api.' + this.config.host + '/';
this.getApiKey();
}
APIClient.prototype.setApiKey = function setApiKey (key) {
this.config.key = key;
sessionStorage.setItem("singly_apiKey." + this.config.host, key);
};
APIClient.prototype.getApiKey = function getApiKey () {
return sessionStorage.getItem("singly_apiKey." + this.config.host);
}
APIClient.prototype.getJSON = function (path, params, callback, retry) {
if (path.indexOf("/") !== 0) {
path = "/" + path;
}
$.getJSON(this.config.baseUrl + this.config.key + path, params, callback);
};
window.APIClient = APIClient;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment