Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
youRhere-part3-targetprocess.js
var rest = require("restler"); //https://github.com/danwrong/restler
//var moment = require("moment"); //http://momentjs.com
var self = this;
var methods = {
globalOptions : {},
init : function(options) {
self.globalOptions = options;
self.globalOptions.format = self.globalOptions.format || "json";
console.log("init");
},
getEntitiesForActiveIteration : function(callback, options) {
//todo: extend globalOptions with options to create localOptions variable
options = options || {};
var getOptions = {
username: options.username || self.globalOptions.username,
password: options.password || self.globalOptions.password,
parser: rest.parsers.json
};
var url = [];
url.push(options.url || self.globalOptions.url);
url.push("Assignables?format=");
url.push(options.format || self.globalOptions.format);
url.push("&where=");
url.push(encodeURIComponent("(EntityType.Name in ('UserStory','Bug'))"));
url.push(encodeURIComponent(" and (Iteration.EndDate eq '"));
//url.push(moment().format("YYYY-MM-DD")); //todo: use moment.js to make this work for any day (finished in current iteration)
url.push("2012-06-13");
url.push(encodeURIComponent("')"));
url.push(encodeURIComponent(" and (EntityState.Name in ('To Verify','Done','Fixed','Closed'))&take=1&include=[Id,Name,EntityType]")); //todo: make this end states configurable
url = url.join("");
console.log("url is: " + url);
rest.get(url, getOptions).on("complete", function(result) {
if (result instanceof Error) {
console.log("ERROR: " + result.message);
} else {
callback(result);
}
});
}
};
api = function(methodName, callback, options) {
console.log("Calling " + methodName);
if (methods[methodName]) {
return methods[methodName].apply(this, Array.prototype.splice.call(arguments, 1));
} else if (typeof methodName === "object" || !methodName) {
return methods.init.apply(this, arguments);
} else {
throw new Error("Method " + method + " does not exist in tp.api");
}
}
exports.api = api;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment