From 52b55d2a5c982c4a56db7dfde4326eb195798c63 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 14 Sep 2015 15:55:14 +0200 Subject: HAFAS/hafas-m: Add StopFinder support --- lib/Travel/Status/DE/HAFAS.pm | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'lib/Travel/Status') diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm index 61e3469..2a7bb11 100644 --- a/lib/Travel/Status/DE/HAFAS.pm +++ b/lib/Travel/Status/DE/HAFAS.pm @@ -11,6 +11,7 @@ use Carp qw(confess); use LWP::UserAgent; use POSIX qw(strftime); use Travel::Status::DE::HAFAS::Result; +use Travel::Status::DE::HAFAS::StopFinder; use XML::LibXML; our $VERSION = '1.05'; @@ -18,12 +19,14 @@ our $VERSION = '1.05'; my %hafas_instance = ( BVG => { url => 'http://bvg.hafas.de/bin/stboard.exe', + stopfinder => 'http://bvg.hafas.de/bin/ajax-getstop.exe', name => 'Berliner Verkehrsgesellschaft', productbits => [qw[s u tram bus ferry ice regio ondemand]], }, DB => { - url => 'http://reiseauskunft.bahn.de/bin/bhftafel.exe', - name => 'Deutsche Bahn', + url => 'http://reiseauskunft.bahn.de/bin/bhftafel.exe', + stopfinder => 'http://reiseauskunft.bahn.de/bin/ajax-getstop.exe', + name => 'Deutsche Bahn', productbits => [qw[ice ic_ec d regio s bus ferry u tram ondemand x x x x]], }, @@ -102,6 +105,7 @@ sub new { developer_mode => $conf{developer_mode}, exclusive_mots => $conf{exclusive_mots}, excluded_mots => $conf{excluded_mots}, + station => $conf{station}, post => { input => $conf{station}, date => $date, @@ -210,17 +214,43 @@ sub check_input_error { = $err->getAttribute('text') . ' (code ' . $err->getAttribute('code') . ')'; + $self->{errcode} = $err->getAttribute('code'); } return; } +sub errcode { + my ($self) = @_; + + return $self->{errcode}; +} + sub errstr { my ($self) = @_; return $self->{errstr}; } +sub similar_stops { + my ($self) = @_; + + my $service = $self->{active_service}; + + if ( $service and exists $hafas_instance{$service}{stopfinder} ) { + my $sf = Travel::Status::DE::HAFAS::StopFinder->new( + url => $hafas_instance{$service}{stopfinder}, + input => $self->{station}, + ); + if ( my $err = $sf->errstr ) { + $self->{errstr} = $err; + return; + } + return $sf->results; + } + return; +} + sub results { my ($self) = @_; my $mode = $self->{post}->{boardType}; -- cgit v1.2.3