Skip to content

Instantly share code, notes, and snippets.

@gcoop
Created December 2, 2010 17:01
Show Gist options
  • Save gcoop/725669 to your computer and use it in GitHub Desktop.
Save gcoop/725669 to your computer and use it in GitHub Desktop.
(function(window, document, $, undefined){
var SDK = function () {
var id,
cb,
key,
secret,
v = 1,
blacklabel_id = 2,
url = 'http://example.com/restserver.php',
canCache = (("localStorage" in window) &&
window["localStorage"] !== null);
if (typeof $ == undefined)
throw new Error("MSW JS SDK requires jQuery");
function getRegions() {
performRequest({
cmd: "Region",
fields: "id,name,continent_id"
}, function (d) {
console.log(d);
});
}
function performRequest(params, callback) {
params.key = key;
params.secret = secret;
params.v = v;
params.format = 'json';
params.blacklabel_id: blacklabel_id
$.ajax({
url: url,
data: params,
dataType: "jsonp",
json: "callback",
jsonpCallback: "validateResponse"
});
function validateResponse(d) {
if (typeof data == "undefined")
throw new Error("JSON was not returned by API.");
callback(data);
}
}
function init(config) {
if (typeof config.key == "undefined" || typeof config.secret == "undefined")
throw new Error("No key or secret specified.");
key = config.key;
secret = config.secret;
}
return {
init: init,
query: query
}
}();
window.SDK = typeof window.SDK == "undefined" ? SDK : window.SDK;
})(this, this.document, this.jQuery);
SDK.init({
key: "mdkey",
secret: "mdsecret"
});
SDK.getRegions();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment