Created
June 11, 2012 09:31
-
-
Save jmhobbs/2909305 to your computer and use it in GitHub Desktop.
Toy Using GoSquared API
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
<!doctype html> | |
<html> | |
<head> | |
<title>GoSquared!</title> | |
</head> | |
<body> | |
<script src="jquery.min.js"></script> | |
<script> | |
jQuery(document).ready(function($) { | |
var API_KEY = 'demo', | |
INTERVAL = 60 * 5; | |
function refresh () { | |
$('div.site').each(function ( i, $site ) { | |
$.getJSON( | |
'http://api.gosquared.com/concurrents.json?callback=?', | |
{ api_key: API_KEY, site_token: $site.data('token') }, | |
function ( data ) { $site.find('div').text(data.concurrents); } | |
); | |
}); | |
} | |
$.getJSON( | |
'http://api.gosquared.com/list_sites.json?callback=?', | |
{ api_key:API_KEY }, | |
function ( data ) { | |
$.each( data, function ( i, site ) { | |
$('body').append( | |
$('<div/>').addClass('site') | |
.text(site.name) | |
.data('token', site.token) | |
.append($('<div/>')) | |
); | |
setInterval( refresh, INTERVAL ); | |
} ); | |
} | |
); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment