daviddoran / railtime
PHP client for Irish Rail's Realtime Rail XML web service.
Requires
- php: >=5.3.0
- rmccue/requests: dev-master
Requires (Dev)
- phpunit/php-code-coverage: >=1.2.10,<1.3.0
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2024-04-23 03:22:23 UTC
README
A PHP library for Irish Rail's Realtime API.
Usage
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.
Installing
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
Tests
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
Examples
Get a list of all the Dart stations
$stations = $api->stations(\Railtime\StationTypeDart);
Get the currently running Mainline trains
$trains = $api->current_trains(\Railtime\TrainTypeMainline);
Get a list of the trains passing Howth Junction (default next 90 minutes)
//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");
Get a list of the trains passing Connolly in the next 15 minutes
//You can also use the station code "CNLLY" $passings = $api->station_passings("Dublin Connolly", 15);
Get a list of a train's movements on a particular day
$movements = $api->train_movements("E815", "25 Aug 2013");
Check how early/late a train was at each station
$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
License
This project is released under the MIT License - see the LICENSE file for details.