Permalink
Browse files

Changed out Citybik.es third-party API for official JCDecaux Dublinbi…

…kes API.

App is far more reliable, accurate and quicker to retrieve data as a consequence.
  • Loading branch information...
thecosmicfrog committed Feb 21, 2015
1 parent a47987c commit 3826f6d9f46e19708ba7382064fa1adcfcf0d661
Showing with 14 additions and 13 deletions.
  1. +3 −2 js/getbikes.js
  2. +2 −1 js/getstations.js
  3. +9 −10 ui/MainPage.qml
@@ -1,10 +1,11 @@
WorkerScript.onMessage = function(sentMessage) {
var stationName = sentMessage.station;
var apiKey = sentMessage.apiKey;
var xmlHttp = new XMLHttpRequest();
var msg;
var stationInfo;

xmlHttp.open("GET", "http://api.citybik.es/dublinbikes.json", true);
xmlHttp.open("GET", "https://api.jcdecaux.com/vls/v1/stations?contract=Dublin&apiKey=" + apiKey, true);
xmlHttp.send(null);

xmlHttp.onreadystatechange = function() {
@@ -16,7 +17,7 @@ WorkerScript.onMessage = function(sentMessage) {

if (typeof stationInfo != "undefined") {
for (var i = 0; i < stationInfo.length; i++) {
if (stationInfo[i].name === stationName) {
if (stationInfo[i].address === stationName) {
WorkerScript.sendMessage({'stationInfo': stationInfo[i]});
}
}
@@ -1,10 +1,11 @@
WorkerScript.onMessage = function(sentMessage) {
var apiKey = sentMessage.apiKey;
var xmlHttp = new XMLHttpRequest();
var msg;
var parsedMsg;
var stations = [];

xmlHttp.open("GET", "http://api.citybik.es/dublinbikes.json", true);
xmlHttp.open("GET", "https://api.jcdecaux.com/vls/v1/stations?contract=Dublin&apiKey=" + apiKey, true);
xmlHttp.send(null);

xmlHttp.onreadystatechange = function() {
@@ -12,7 +12,7 @@ Page {

// Always begin by loading the selected stop.
Component.onCompleted: {
queryStationsWorker.sendMessage({'station': stationsModel.get(stationSelector.selectedIndex).name})
queryStationsWorker.sendMessage({"station": stationsModel.get(stationSelector.selectedIndex).name, "apiKey": apiKeys.jc_decaux_apiKey})
}

WorkerScript {
@@ -21,13 +21,12 @@ Page {

onMessage: {
bikesAvailableLabel.font.pointSize = 28;
bikesAvailableLabel.text = "<b>" + messageObject.stationInfo.bikes + "</b><br>Bikes";
bikesAvailableLabel.text = "<b>" + messageObject.stationInfo.available_bikes + "</b><br>Bikes";

spotsAvailableLabel.font.pointSize = 28;
spotsAvailableLabel.text = "<b>" + messageObject.stationInfo.free + "</b><br>Spots";
spotsAvailableLabel.text = "<b>" + messageObject.stationInfo.available_bike_stands + "</b><br>Spots";

// Workaround - FIXME
map.center = QtPositioning.coordinate(messageObject.stationInfo.lat / 1000000, messageObject.stationInfo.lng / 1000000)
map.center = QtPositioning.coordinate(messageObject.stationInfo.position.lat, messageObject.stationInfo.position.lng)
map.zoomLevel = 16

activityIndicator.running = false
@@ -40,7 +39,7 @@ Page {

onMessage: {
for (var i = 0; i < messageObject.stations.length; i++) {
stationsModel.append({ "name": messageObject.stations[i].name, "description": "" })
stationsModel.append({ "name": messageObject.stations[i].address, "description": "" })
}

stationSelector.selectedIndex = getLastStationIndex(lastStation.contents.stationName, stationsModel)
@@ -56,7 +55,7 @@ Page {

onTriggered: {
activityIndicator.running = true
queryBikesWorker.sendMessage({'station': stationsModel.get(stationSelector.selectedIndex).name})
queryBikesWorker.sendMessage({"station": stationsModel.get(stationSelector.selectedIndex).name, "apiKey": apiKeys.jc_decaux_apiKey})
}
},
Action {
@@ -127,7 +126,7 @@ Page {

onSelectedIndexChanged: {
activityIndicator.running = true
queryBikesWorker.sendMessage({'station': stationsModel.get(stationSelector.selectedIndex).name})
queryBikesWorker.sendMessage({'station': stationsModel.get(stationSelector.selectedIndex).name, "apiKey": apiKeys.jc_decaux_apiKey})

// Save station to U1DB backend for faster access on next app start.
lastStation.contents = {stationName: stationsModel.get(stationSelector.selectedIndex).name}
@@ -219,8 +218,8 @@ Page {
required.geocoding: Plugin.AnyGeocodingFeatures

parameters: [
PluginParameter { name: "app_id"; value: apiKeys.app_id },
PluginParameter { name: "token"; value: apiKeys.token }
PluginParameter { name: "app_id"; value: apiKeys.here_app_id },
PluginParameter { name: "token"; value: apiKeys.here_token }
]
}

0 comments on commit 3826f6d

Please sign in to comment.