(function() { window.UoSLive = {}; var busStopRequests = {}; var busStopCache = {}; UoSLive.getBusStopURL = function(busStop) { var base = "http://bus.southampton.ac.uk/bus-stop/"; var url = base + busStop + ".json"; return url; }; UoSLive.subscribeToBusStop = function(busStop, callback) { if (busStop in busStopCache) { var result = busStopCache[busStop]; if (result.timeFetched > (Date.now() - 60000)) { callback(result); } } var url = UoSLive.getBusStopURL(busStop); var req = new Pollymer.Request(); busStopRequests[busStop] = req; req.recurring = true; req.on('finished', function(code, result, headers) { result.timeFetched = Date.now(); busStopCache[busStop] = result; callback(result); }); req.on('error', function(reason) { }); req.maxTries = -1; req.maxDelay = 60000; req.minDelay = 60000; req.start('GET', url); }; UoSLive.unsubscribeToBusStop = function(busStop) { var req = busStopRequests[busStop]; req.abort(); } })();