Skip to content

Instantly share code, notes, and snippets.

@lsmoura
Last active November 27, 2015 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lsmoura/732ee9c5e18756d51133 to your computer and use it in GitHub Desktop.
Save lsmoura/732ee9c5e18756d51133 to your computer and use it in GitHub Desktop.
var tiptoe = require('tiptoe'),
shared = require('shared');
function processSet(set) {
// Do something with the set
}
function getSet(setName, callback) {
// The functions inside "tiptoe()" parameters, will be executed one after another, assumming "this()" is called.
tiptoe(
function getSetCardList() {
var method = "GET";
var path = "/ws/v1.1/output.json/expansion/1/"+encodeURIComponent(setName);
var headerOptions = auth.getOauth("www.mkmapi.eu", path, method);
// once the URL is set, it will invoke its secons parameter (in this case, 'this'), as a function. In practice, the call is 'this(err, result);'
shared.getURLAsJSON("https://www.mkmapi.eu"+path, this, 0, headerOptions);
},
function processSetCardList(err, result) {
// In tiptoe(), the LAST function must have an 'err' as first parameter, and we check it for errors.
if (err)
throw(err);
var json = JSON.parse(result);
// In this case, I've just called another function with the results
if (callback)
callback(json);
}
);
}
// This starts the wheel. It will try to get the BFZ set and will call the function on the second parameter with the data, assumming no errors occurred.
getSet('BFZ', processSet);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment