Express app for Narratives coffeemaker
This file contains 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 stateCount = 0; | |
var timer; | |
var resetTimer; | |
var brewing = false; | |
app.post('/brew_hook', function(req, res) { | |
stateCount++; | |
clearTimeout(resetTimer); | |
resetTimer = setTimeout(function() { | |
stateCount = 0; | |
brewing = false; | |
}, 60000); | |
if (stateCount > 1) { | |
if (brewing === false) { | |
brewing = true; | |
io.emit('brew_update', JSON.stringify({ "brewing": brewing })); | |
request(hubotDomain + '/brewingcoffee'); // Ping hubot webhook that the coffee is ready | |
} | |
clearTimeout(timer); | |
timer = setTimeout(function() { | |
stateCount = 0; | |
brewing = false; | |
var CoffeeObject = Parse.Object.extend("Coffee"); | |
var coffeeObject = new CoffeeObject(); | |
coffeeObject.save({cups: 7}); | |
io.emit('brew_update', JSON.stringify({ "brewing": brewing })); | |
request(hubotDomain + '/donecoffee'); // Ping hubot webhook that the coffee is ready | |
}, 240000); | |
} | |
res.sendStatus(200); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment