Created
June 21, 2011 23:09
-
-
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
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
| /** | |
| * 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); | |
| } |
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
| 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