Created
April 22, 2016 21:00
-
-
Save evantahler/33bcf1e08893466f4d3c0a3c8973198b to your computer and use it in GitHub Desktop.
Nerf + Phidgets + Node
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
var phidgets = require('phidgets').phidgets; | |
var pivotal = require("pivotal"); | |
// curl -d username=$USERNAME -d password=$PASSWORD -X POST https://www.pivotaltracker.com/services/v3/tokens/active | |
var apiToken = "XXXXXXXXXXXXXXXXXXX"; | |
var projectID = 12345; | |
var OwnedBy = "Evan Tahler"; | |
var checkTimerMS = 500; | |
var newer_than_version = 0; | |
var PhidgetHost = "phidgetsbc.local"; | |
var phidgetsReady = false; | |
var phidgetData = {}; | |
var init = function(next) { | |
phidgets.on("data", function(type, id, value) { | |
if (phidgetsReady) { | |
console.log("phidgets >> " + type + " #" + id + " now at @ " + value); | |
} | |
}); | |
phidgets.on("log", function(data) { | |
if (typeof data != "object") { | |
console.log("phidgets log >> " + data); | |
} | |
}); | |
phidgets.on("error", function(e) { | |
console.log("phidgets error >> " + e); | |
}); | |
phidgets.connect({ | |
host: PhidgetHost | |
}, function(p) { | |
phidgetsReady = true; | |
phidgets.setOutput(0, false); | |
phidgets.setOutput(1, false); | |
phidgetData = p; | |
pivotal.useToken(apiToken); | |
pivotal.getProjects(function(err, resp) { | |
if (err != null) { | |
console.log(err.desc); | |
process.exit(); | |
} else { | |
var found = false; | |
for (var i in resp.project) { | |
var project = resp.project[i]; | |
if (project.id == projectID) { | |
found = true; | |
break; | |
} | |
} | |
if (found == false) { | |
console.log("This user does not have access to project #" + projectID); | |
process.exit(); | |
} else { | |
checkForTrackerStatus(); | |
next(); | |
} | |
} | |
}); | |
}); | |
} | |
var checkForTrackerStatus = function() { | |
var filters = { | |
project: projectID, | |
limit: 1, | |
newer_than_version: newer_than_version | |
}; | |
pivotal.getActivities(filters, function(err, activities) { | |
if (err != null) { | |
console.log(err.desc); | |
process.exit(); | |
} else { | |
if (activities.activity != null) { | |
if (activities.activity.event_type == "story_update" && newer_than_version > 0) { | |
pivotal.getStory(projectID, activities.activity.stories.story.id, function(err, story) { | |
if (err != null) { | |
console.log(err.desc); | |
process.exit(); | |
} else { | |
if (story.owned_by == OwnedBy) { | |
if (story.current_state == "rejected") { | |
fireGun() | |
} else if (story.current_state == "accepted") { | |
happyness() | |
} | |
} | |
} | |
}); | |
}; | |
newer_than_version = activities.activity.version; | |
} | |
setTimeout(checkForTrackerStatus, checkTimerMS); | |
} | |
}); | |
} | |
var fireGun = function(next) { | |
console.log("BANG!"); | |
phidgets.setOutput(0, true); | |
setTimeout(phidgets.setOutput, 1000, 0, false); | |
if (typeof next == "function") { | |
next(); | |
} | |
100 | |
} | |
var happyness = function(next) { | |
console.log("Yay!"); | |
phidgets.setOutput(1, true); | |
setTimeout(phidgets.setOutput, 1000, 1, false); | |
if (typeof next == "function") { | |
next(); | |
} | |
} | |
init(function() { | |
console.log("READY!"); | |
111 | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment