Subject: | Added CRS filters as per webservice [ listed as a TODO in module source :-) ] |
The Live Departure SOAP calls all have a filter parameter filterCRS to
specify a station + a filterType parameter to specify 'from' or 'to'.
Attached patch adds the filter params to the soap call if they're
specified - as with the webservice, filtertype defaults to 'to' if a
filter CRS is supplied but no filtertype is chosen.
Subject: | add_filters.patch |
*** /usr/local/share/perl/5.10.0/Net/NationalRail/LiveDepartureBoards.pm 2009-01-08 20:21:28.000000000 +0000
--- /tmp/buffer-content-10236jW5 2010-01-05 19:40:19.000000000 +0000
***************
*** 71,93 ****
}
sub _station_board_request {
! my $method = shift;
! my $self = shift;
! my %arg = @_;
!
! my $result = _soap_request(
! $method,
! URI_PREFIX . 'types',
! SOAP::Data->name(numRows => $arg{'rows'}),
! SOAP::Data->name(crs => $arg{'crs'}),
! # TODO: add filters.
! );
!
! if ($result->fault) {
! die join ', ', $result->faultcode, $result->faultstring;
! } else {
! return $result->result();
! }
}
sub _soap_request {
--- 71,103 ----
}
sub _station_board_request {
! my $method = shift;
! my $self = shift;
! my %arg = @_;
!
! my @opt_args;
! if(exists($arg{filtercrs})) {
! push(@opt_args, SOAP::Data->name(filterCrs => $arg{filtercrs}));
! if(exists($arg{filtertype})) {
! push(@opt_args,SOAP::Data->name(filterType => $arg{filtertype}));
! } else {
! push(@opt_args,SOAP::Data->name(filterType => 'to'));
! }
! }
!
! my $result = Net::NationalRail::LiveDepartureBoards::_soap_request(
! $method,
! URI_PREFIX . 'types',
! SOAP::Data->name(numRows => $arg{'rows'}),
! SOAP::Data->name(crs => $arg{'crs'}),
! @opt_args
! );
!
! if ($result->fault) {
! die join ', ', $result->faultcode, $result->faultstring;
! } else {
! return $result->result();
! }
}
sub _soap_request {
Subject: | example.pl |
use strict;
use warnings;
use Data::Dumper;
use Net::NationalRail::LiveDepartureBoards;
my $results;
eval {
my $ldb = Net::NationalRail::LiveDepartureBoards->new();
$results = $ldb->departures(
rows => 10,
crs => 'CDF',
filtercrs=> 'BRI',
filtertype => 'to'
);
};
if($@) {
die "Error calling webservice: %s",$@;
}
print Dumper($results),"\n";