Skip to content

Commit

Permalink
Changed API backend to a load-balanced and redundant system.
Browse files Browse the repository at this point in the history
  • Loading branch information
thecosmicfrog committed Oct 2, 2015
1 parent 15e387b commit 9f337c4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
.DS_Store
.excludes
manifest.json
uDART.qmlproject.user
Expand Down
17 changes: 14 additions & 3 deletions js/gettimes.js
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion uDART.qml
Expand Up @@ -7,7 +7,7 @@ MainView {
id: mainView

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

//automaticOrientation: true

Expand Down

0 comments on commit 9f337c4

Please sign in to comment.