Skip to content

Instantly share code, notes, and snippets.

@notslang
Created November 22, 2013 07:17
Show Gist options
  • Save notslang/7596103 to your computer and use it in GitHub Desktop.
Save notslang/7596103 to your computer and use it in GitHub Desktop.
http = require 'http'
url = 'http://xapi.snapapp.com/xapi/v2/promotions/528557c027ce261e6f000018/entries'
http.get(url, (res) ->
body = ''
res.on('data', (chunk) ->
body += chunk
)
res.on('end', () ->
response = JSON.parse(body)
entries = []
for entry in response['entries']
entries.push [entry['votes'], entry['entry']['video']['title']]
entries.sort((a, b) ->
if (a[0] > b[0])
return 1;
if (a[0] < b[0])
return -1;
return 0;
)
for entry in entries
console.log entry[0] + "\t" + entry[1]
)
).on('error', (e) ->
console.log("Got error: ", e)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment