A PHP library for Irish Rail's Realtime API.
The main class exported by this package is \Railtime\API
.
First, create a new API
object:
use \Railtime\API;
$api = new API;
Then, call the various API methods:
$stations = $api->stations();
The API
class exposes the following methods:
Station[] stations([$station_type])
RunningTrain[] current_trains([$train_type])
StationPassing[] station_passings($name_or_code[, $minutes = null])
TrainMovement[] train_movements($train_id, $train_date)
Make sure to check out the Examples below.
This package is available from Packagist.
To install using Composer, add this to the "require":
section of your composer.json
file:
"daviddoran/railtime": "dev-master"
Once you've installed Composer simply run:
php composer.phar install
Or, if you installed composer globally:
composer install
The unit tests are contained in test
and the configuration in phpunit.xml
.
After installing dependencies with composer, the following should run the tests:
./vendor/bin/phpunit
$stations = $api->stations(\Railtime\StationTypeDart);
$trains = $api->current_trains(\Railtime\TrainTypeMainline);
//You can use the station's full name
$passings = $api->station_passings("Howth Junction");
//Or use the station's code
$passings = $api->station_passings("HWTHJ");
//You can also use the station code "CNLLY"
$passings = $api->station_passings("Dublin Connolly", 15);
$movements = $api->train_movements("E815", "25 Aug 2013");
$movements = $api->train_movements("E815", "18 Aug 2013");
foreach ($movements as $stop) {
if (!$stop->is_origin()) {
$mins = round($stop->arrival_diff_seconds() / 60);
echo "-- ", abs($mins), " min ", ($mins > 0 ? "late" : "early"), " --> ";
} else {
echo "-- set off --> ";
}
echo $stop->location_fullname, "\n";
}
This will output something like:
-- set off --> Greystones
-- 0 min early --> Bray
-- 0 min early --> Shankill
-- 1 min late --> Killiney
-- 1 min late --> Dalkey
-- 2 min late --> Glenageary
-- 2 min late --> Sandycove
-- ✂ -- ✂ -- snip -- ✂ -- ✂ --
-- 3 min late --> Kilbarrack
-- 3 min late --> Howth Junction
-- 2 min late --> Clongriffin
-- 2 min late --> Portmarnock
-- 2 min late --> Malahide
This project is released under the MIT License - see the LICENSE file for details.