function sendBusStopInfo(stopNum,senderID) {
        return request({
                rejectUnauthorized: false,
                uri: 'https://data.dublinked.ie/cgi-bin/rtpi/realtimebusinformation',
                qs: { stopid: stopNum },
                method: 'GET',
                
        }, function(error, response, body) {
                if(!error && response.statusCode === 200) {
                        var jbody = JSON.parse(body);       
                        console.log("Bus Stop request succesful");
                        if(jbody.errorcode != 0) {
                                console.log(jbody.errorcode);
                                console.log(jbody.errormessage);
                                sendTextMessage(senderID,  jbody.errormessage + " Please enter a valid bus stop number. Please note some buses cease operation at 00:00 and begin at 05:00. Type help for more info  ");
                        }
                        else {
                                var busRoutes = new Array(jbody.results.length);
                                console.log("Bus stop information retrieved successfully");
                                for(var i = 0; i < jbody.results.length; i++) {
                                        if(busRoutes.indexOf(jbody.results[i].route) === -1) {          //If the bus route does not exist already in the bus array
                                                if(jbody.results[i].duetime > 1) {
                                                        sendTextMessage(senderID, "A " + jbody.results[i].route + " bus will arrive in " + jbody.results[i].duetime + " minutes!");
                                                }
                                                else if(jbody.results[i].duetime === 'Due') {
                                                        sendTextMessage(senderID, "A " + jbody.results[i].route + " bus is arriving now!");
                                                }
                                                else {
                                                        sendTextMessage(senderID, "A " + jbody.results[i].route + " bus will arrive in " + jbody.results[i].duetime + " minute!");
                                                }
                                                busRoutes[i] = jbody.results[i].route;                          //Add the bus route to the bus array so we wont print that route again
                                        }
                                }
                        }                               
                }
                else {
                        console.error("Unable to reach RTPI system");
                        console.error(response);
                        console.error(error);
                }
        });
}
/*
        This function will send the stop number received from the user as a GET request to the Dublin Bus RTPI.
        If unsuccesful response and errors are logged.
        If the RTPI is successfully reached, parse the response as json. If the response has an error code, log the error and send an error message back to the user.
        If there is no error, an array with length equal to the number of buses in the response is created.
        A for loop will send a message back with the next bus of each bus route due to arrive at the user's bus stop.
        This is because in some cases multiple buses of the same route may be due to arrive within a short timeframe and it would spam the user with far too many bus times at once.
*/
This function will send the stop number received from the user as a GET request to the Dublin Bus RTPI.
If unsuccesful response and errors are logged.
If the RTPI is successfully reached, parse the response as json. If the response has an error code, log the error and send an error message back to the user.
If there is no error, an array with length equal to the number of buses in the response is created.
A for loop will send a message back with the next bus of each bus route due to arrive at the user's bus stop.
This is because in some cases multiple buses of the same route may be due to arrive within a short timeframe and it would spam the user with far too many bus times at once.
This function will send the stop number received from the user as a GET request to the Dublin Bus RTPI . If unsuccesful response and errors are logged . If the RTPI is successfully reached parse the response as json . If the response has an error code log the error and send an error message back to the user . If there is no error an array with length equal to the number of buses in the response is created . A for loop will send a message back with the next bus of each bus route due to arrive at the user ' s bus stop . This is because in some cases multiple buses of the same route may be due to arrive within a short timeframe and it would spam the user with far too many bus times at once .
function sendBusStopInfo(stopNum,senderID) {
        return request({
                rejectUnauthorized: false,
                uri: 'https://data.dublinked.ie/cgi-bin/rtpi/realtimebusinformation',
                qs: { stopid: stopNum },
                method: 'GET',
        }, function(error, response, body) {
                if(!error && response.statusCode === 200) {
                        var jbody = JSON.parse(body);       
                        console.log("Bus Stop request succesful");
                        if(jbody.errorcode != 0) {
                                console.log(jbody.errorcode);
                                console.log(jbody.errormessage);
                                sendTextMessage(senderID,  jbody.errormessage + " Please enter a valid bus stop number. Please note some buses cease operation at 00:00 and begin at 05:00. Type help for more info  ");
                        }
                        else {
                                var busRoutes = new Array(jbody.results.length);
                                console.log("Bus stop information retrieved successfully");
                                for(var i = 0; i < jbody.results.length; i++) {
                                        if(busRoutes.indexOf(jbody.results[i].route) === -1) {          
                                                if(jbody.results[i].duetime > 1) {
                                                        sendTextMessage(senderID, "A " + jbody.results[i].route + " bus will arrive in " + jbody.results[i].duetime + " minutes!");
                                                }
                                                else if(jbody.results[i].duetime === 'Due') {
                                                        sendTextMessage(senderID, "A " + jbody.results[i].route + " bus is arriving now!");
                                                }
                                                else {
                                                        sendTextMessage(senderID, "A " + jbody.results[i].route + " bus will arrive in " + jbody.results[i].duetime + " minute!");
                                                }
                                                busRoutes[i] = jbody.results[i].route;                          
                                        }
                                }
                        }                               
                }
                else {
                        console.error("Unable to reach RTPI system");
                        console.error(response);
                        console.error(error);
                }
        });
}
function sendBusStopInfo ( stopNum , senderID ) { return request ( { rejectUnauthorized : false , uri : 'https://data.dublinked.ie/cgi-bin/rtpi/realtimebusinformation' , qs : { stopid : stopNum } , method : 'GET' , } , function ( error , response , body ) { if ( ! error && response . statusCode === 200 ) { var jbody = JSON . parse ( body ) ; console . log ( "Bus Stop request succesful" ) ; if ( jbody . errorcode != 0 ) { console . log ( jbody . errorcode ) ; console . log ( jbody . errormessage ) ; sendTextMessage ( senderID , jbody . errormessage + " Please enter a valid bus stop number. Please note some buses cease operation at 00:00 and begin at 05:00. Type help for more info  " ) ; } else { var busRoutes = new Array ( jbody . results . length ) ; console . log ( "Bus stop information retrieved successfully" ) ; for ( var i = 0 ; i < jbody . results . length ; i ++ ) { if ( busRoutes . indexOf ( jbody . results [ i ] . route ) === - 1 ) { if ( jbody . results [ i ] . duetime > 1 ) { sendTextMessage ( senderID , "A " + jbody . results [ i ] . route + " bus will arrive in " + jbody . results [ i ] . duetime + " minutes!" ) ; } else if ( jbody . results [ i ] . duetime === 'Due' ) { sendTextMessage ( senderID , "A " + jbody . results [ i ] . route + " bus is arriving now!" ) ; } else { sendTextMessage ( senderID , "A " + jbody . results [ i ] . route + " bus will arrive in " + jbody . results [ i ] . duetime + " minute!" ) ; } busRoutes [ i ] = jbody . results [ i ] . route ; } } } } else { console . error ( "Unable to reach RTPI system" ) ; console . error ( response ) ; console . error ( error ) ; } } ) ; }
This function will send the stop number received from the user as a GET request to the Dublin Bus RTPI.
This function will send the stop number received from the user as a GET request to the Dublin Bus RTPI .
//If the bus route does not exist already in the bus array //Add the bus route to the bus array so we wont print that route again