Created
December 2, 2010 17:01
-
-
Save gcoop/725669 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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