Permalink
Browse files

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

  • Loading branch information...
thecosmicfrog committed Oct 2, 2015
1 parent 15e387b commit 9f337c4c74ef5933236a0b455840b37e7fb86e78
Showing with 16 additions and 4 deletions.
  1. +1 −0 .gitignore
  2. +14 −3 js/gettimes.js
  3. +1 −1 uDART.qml
@@ -1,3 +1,4 @@
.DS_Store
.excludes
manifest.json
uDART.qmlproject.user
@@ -8,9 +8,20 @@ WorkerScript.onMessage = function(sentMessage) {
var stationInfo = [];
var trains = [];

// 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/irish-rail-api.php?station=" + station, 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/irish-rail-api.php?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 + station, true);
xmlHttp.send(null);

xmlHttp.onreadystatechange = function() {
@@ -7,7 +7,7 @@ MainView {
id: mainView

applicationName: "org.thecosmicfrog.udart"
property string version: "0.17"
property string version: "0.18"

//automaticOrientation: true

0 comments on commit 9f337c4

Please sign in to comment.