diff --git a/.gitignore b/.gitignore index 57e20d7..e2f7a46 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.DS_Store .excludes manifest.json uLuas.qmlproject.user diff --git a/js/gettimes.js b/js/gettimes.js index d95cd72..5103060 100644 --- a/js/gettimes.js +++ b/js/gettimes.js @@ -68,9 +68,20 @@ WorkerScript.onMessage = function(sentMessage) { "Brides Glen": "BRI" }; - // Query a hosted Luas API script. Returns JSON object with service message and times for the given stop. - // API can be found here: https://github.com/ncremins/luas-api - xmlHttp.open("GET", "https://api.thecosmicfrog.org/cgi-bin/luas-api.php?action=times&station=BLA/luas-api-v2/luas-api.php?action=times&station=" + stopCodes[stopName], true); + /* + * Randomly choose an API endpoint to query. This provides load balancing and redundancy + * in case of server failures. + * All API endpoints are of the form: "apiN.thecosmicfrog.org", where N is determined by + * the formula below. + * The constant NUM_API_ENDPOINTS governs how many endpoints there currently are. + */ + var API_URL_PREFIX = "https://api"; + var API_URL_POSTFIX = ".thecosmicfrog.org/cgi-bin/luas-api.php?action=times&station="; + var NUM_API_ENDPOINTS = 2; + var apiEndpointToQuery = Math.floor((Math.random() * NUM_API_ENDPOINTS + 1)).toString(); + var apiUrl = API_URL_PREFIX + apiEndpointToQuery + API_URL_POSTFIX; + + xmlHttp.open("GET", apiUrl + stopCodes[stopName], true); xmlHttp.send(null); xmlHttp.onreadystatechange = function() { diff --git a/uLuas.qml b/uLuas.qml index 28da0a6..e736bac 100644 --- a/uLuas.qml +++ b/uLuas.qml @@ -7,7 +7,7 @@ MainView { id: mainView applicationName: "org.thecosmicfrog.uluas" - property string version: "0.26" + property string version: "0.27" //automaticOrientation: true