Permalink
Browse files

Changed API backend to a load-balanced and redundant system.

  • Loading branch information...
thecosmicfrog committed Oct 2, 2015
1 parent 271ab0b commit 15e53708f5a62cbf6d1d3456266d6eeda05e63c4
Showing with 16 additions and 4 deletions.
  1. +1 −0 .gitignore
  2. +14 −3 js/gettimes.js
  3. +1 −1 uLuas.qml
@@ -1,3 +1,4 @@
.DS_Store
.excludes
manifest.json
uLuas.qmlproject.user
@@ -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() {
@@ -7,7 +7,7 @@ MainView {
id: mainView

applicationName: "org.thecosmicfrog.uluas"
property string version: "0.26"
property string version: "0.27"

//automaticOrientation: true

0 comments on commit 15e5370

Please sign in to comment.