Last active
August 29, 2015 14:02
-
-
Save eurica/e4027372b301f0b4e17d 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
// Some basic interactivity | |
wind.on('click', 'down', function() { | |
textfield.text("Paused, up to resume") | |
count = -1 | |
clearInterval(interval); | |
}); | |
wind.on('click', 'up', function() { | |
textfield.text("Contacting PagerDuty") | |
PDupdate() | |
clearInterval(interval); | |
interval = window.setInterval(PDupdate,polling_interval) | |
}); |
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 user_id = "P304FC8"; | |
var subdomain = "webdemo"; | |
var token = "sVVWs84QqzkXqbvVsetM"; | |
// 2000ms = 2 seconds: about as high as you can get without rate limiting kicking in | |
var polling_interval = 2000; |
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
updateScreen = function (data) { | |
new_count = data.total || 0 | |
console.log("Found " + new_count + " incidents from " + count); | |
if(new_count != count) { | |
str = "" | |
if(new_count>count && new_count > 0) { | |
Vibe.vibrate('short'); | |
str = "Oh dear" | |
} else if(new_count<count){ | |
Vibe.vibrate('long'); | |
str = "Yay!" | |
} | |
count = new_count | |
textfield.text(count + " incidents\n" + str) | |
} | |
} |
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
PDupdate = function(e) { | |
ajax( | |
{ | |
url: 'http://'+subdomain+'.pagerduty.com/api/v1/incidents/count?'+ | |
'status=triggered,acknowledged&assigned_to_user='+user_id, | |
type: 'json', | |
headers: { | |
Authorization: 'Token token='+token, | |
contentType: 'application/json; charset=utf-8' | |
} | |
}, | |
updateScreen, // <-- on success run this function | |
function (error) { | |
console.log("Error:"); | |
console.log(error); // <-- super high fidelity error logging | |
} | |
); | |
} |
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
// Load a basic screen | |
wind = new UI.Window(); | |
textfield = new UI.Text({ | |
position: new Vector2(0, 50), | |
size: new Vector2(144, 30), | |
font: 'gothic-24-bold', | |
text: "Contacting PagerDuty", | |
textAlign: 'center' | |
}); | |
wind.add(textfield); | |
wind.show(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment