VERSION
version 0.001
NAME
WWW::IRail::API::Liveboard - HTTP::Request builder and HTTP::Response parser for the IRail API Liveboard data
SYNOPSIS
make_request ( station => 'oostende' ); # departures by default
make_request ( to => 'oostende' ); # arrivals coming into oostende
DESCRIPTION
This module builds a HTTP::Request and has a parser for the HTTP::Response. It's up to you to transmit it over the wire. If don't want to do that yourself, don't use this module directly and use WWW::IRail::API instead.
METHODS
make_request( key = 'val'> | { key = 'val' }> )
Only the station
argument is required, but if you either use to
or from
it will be seen as the station name with the direction set accordingly. Memento: trains leaving from => 'oostende' and trains arriving into => 'oostende'. If the direction could not be deduced it defaults to 'departures'
make_request ( from => 'oostende' );
make_request ( station => 'oostende', direction => 'departures' );
make_request ( { station => 'oostende', dir => 'arr' } );
the API direction parameter is extracted from your input using m/(arr|dep)/i
so you can choose between less typing or better readability.
parse_response( $http_response, dataType )
rses the HTTP::Response you got back from the server, which if all went well contains XML. That XML is then transformed into other data formats
xml
XML
YAML
JSON
perl (default)
example of output when dataType = 'xml'
<liveboard station="MOLLEM" timestamp="1291044188">
<departures>
<departure platform="1" station="DENDERMONDE" time="1291043100" vehicle="BE.NMBS.CR1564" />
<departure platform="1" station="DENDERMONDE" time="1291044480" vehicle="BE.NMBS.CR5316" />
<departure platform="2" station="GERAARDSBERGEN" time="1291046100" vehicle="BE.NMBS.CR1588" />
<departure platform="1" station="DENDERMONDE" time="1291046700" vehicle="BE.NMBS.CR1565" />
</departures>
</liveboard>
example of output when dataType = 'XML'
<liveboard timestamp="1291044222" version="1.0">
<departures name="departure" number="4">
<departure id="0" delay="1200" vehicle="BE.NMBS.CR1564">
<platform normal="1">1</platform>
<station id="BE.NMBS.137" locationX="4.101431" locationY="51.022775">DENDERMONDE</station>
<time formatted="2010-11-29T15:05:00Z">1291043100</time>
</departure>
<departure id="1" delay="1140" vehicle="BE.NMBS.CR5316">
<platform normal="1">1</platform>
<station id="BE.NMBS.137" locationX="4.101431" locationY="51.022775">DENDERMONDE</station>
<time formatted="2010-11-29T15:28:00Z">1291044480</time>
</departure>
<departure id="2" delay="0" vehicle="BE.NMBS.CR1588">
<platform normal="1">2</platform>
<station id="BE.NMBS.210" locationX="3.871956" locationY="50.771025">GERAARDSBERGEN</station>
<time formatted="2010-11-29T15:55:00Z">1291046100</time>
</departure>
<departure id="3" delay="0" vehicle="BE.NMBS.CR1565">
<platform normal="1">1</platform>
<station id="BE.NMBS.137" locationX="4.101431" locationY="51.022775">DENDERMONDE</station>
<time formatted="2010-11-29T16:05:00Z">1291046700</time>
</departure>
</departures>
<station id="BE.NMBS.376" locationX="4.21675" locationY="50.932808">MOLLEM</station>
</liveboard>
example of output when dataType = 'YAML'
---
departures:
- platform: 1
station: DENDERMONDE
time: 1291043100
vehicle: BE.NMBS.CR1564
- platform: 1
station: DENDERMONDE
time: 1291044480
vehicle: BE.NMBS.CR5316
- platform: 2
station: GERAARDSBERGEN
time: 1291046100
vehicle: BE.NMBS.CR1588
- platform: 1
station: DENDERMONDE
time: 1291046700
vehicle: BE.NMBS.CR1565
station: MOLLEM
timestamp: 1291044267
example of output when dataType = 'JSON'
{
"departures" : [
{
"station" : "DENDERMONDE",
"time" : "1291043100",
"vehicle" : "BE.NMBS.CR1564",
"platform" : "1"
},
{
"station" : "DENDERMONDE",
"time" : "1291044480",
"vehicle" : "BE.NMBS.CR5316",
"platform" : "1"
},
{
"station" : "GERAARDSBERGEN",
"time" : "1291046100",
"vehicle" : "BE.NMBS.CR1588",
"platform" : "2"
},
{
"station" : "DENDERMONDE",
"time" : "1291046700",
"vehicle" : "BE.NMBS.CR1565",
"platform" : "1"
}
],
"station" : "MOLLEM",
"timestamp" : "1291044295"
}
example of output when dataType = 'perl'
{
'departures' => [
{
'station' => 'DENDERMONDE',
'time' => '1291043100',
'vehicle' => 'BE.NMBS.CR1564',
'platform' => '1'
},
{
'station' => 'DENDERMONDE',
'time' => '1291044480',
'vehicle' => 'BE.NMBS.CR5316',
'platform' => '1'
},
{
'station' => 'GERAARDSBERGEN',
'time' => '1291046100',
'vehicle' => 'BE.NMBS.CR1588',
'platform' => '2'
},
{
'station' => 'DENDERMONDE',
'time' => '1291046700',
'vehicle' => 'BE.NMBS.CR1565',
'platform' => '1'
}
],
'station' => 'MOLLEM',
'timestamp' => '1291044344'
};
METHODS
INSTALLATION
See perlmodinstall for information and options on installing Perl modules.
BUGS AND LIMITATIONS
No bugs have been reported.
Please report any bugs or feature requests through the web interface at http://rt.cpan.org.
AUTHOR
Tim Esselens <tim.esselens@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2010 by Tim Esselens.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.