Skip to content

Instantly share code, notes, and snippets.

@snay2
Created June 21, 2011 23:09
Show Gist options
  • Select an option

  • Save snay2/1039193 to your computer and use it in GitHub Desktop.

Select an option

Save snay2/1039193 to your computer and use it in GitHub Desktop.
Kynetx rule for exposing stats and the Google Apps Script function that calls it
/**
* Function to pull in TomatoFlix stats through the RESTful web service
* on the webhook. Appends a new row with the date and time and each of the stats.
*
* Set up with a trigger to run once per day in the middle of the night. This can then
* be used for aggregating the stats over time.
*/
function getTomatoFlixStats() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[3];
var myRow = sheet.getLastRow() + 1;
var range = "A" + myRow + ":G" + myRow;
jsonData = Utilities.jsonParse(UrlFetchApp.fetch("http://webhooks.kynetxapps.net/h/a163x53.dev/stats").getContentText());
values = [[new Date(),
jsonData["netflix_loggedin"],
jsonData["netflix"],
jsonData["imdb"],
jsonData["redbox"],
jsonData["fandango"],
jsonData["movies_com"]]]
sheet.getRange(range).setValues(values);
}
rule stats_webhook {
select when webhook stats
pre {
stats = {"netflix_loggedin": app:netflix_loggedin,
"netflix": app:netflix,
"imdb": app:imdb,
"redbox": app:redbox,
"fandango": app:fandango,
"movies_com": app:movies_com};
}
{
webhook:json(stats);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment