summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2023-11-12 13:55:31 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2023-11-12 13:55:31 +0100
commitf55b3d485763f7fce02caa7cf235ad826d4d0c03 (patch)
tree1733915b0541a05d87307c4e97741836256ff1e8
parenta6bbc9f5ff0171e0eb73ffe434d009f6e8bf2f11 (diff)
HAFAS: cleanup
-rw-r--r--lib/Travel/Routing/DE/HAFAS.pm112
1 files changed, 47 insertions, 65 deletions
diff --git a/lib/Travel/Routing/DE/HAFAS.pm b/lib/Travel/Routing/DE/HAFAS.pm
index 70914bb..6203223 100644
--- a/lib/Travel/Routing/DE/HAFAS.pm
+++ b/lib/Travel/Routing/DE/HAFAS.pm
@@ -216,57 +216,53 @@ sub new {
my $req;
- if (0) {
+ my $date = ( $conf{datetime} // $now )->strftime('%Y%m%d');
+ my $time = ( $conf{datetime} // $now )->strftime('%H%M%S');
+
+ my ( $from_lid, $to_lid );
+ if ( $self->{from_stop} =~ m{ ^ [0-9]+ $ }x ) {
+ $from_lid = 'A=1@L=' . $self->{from_stop} . '@';
}
else {
- my $date = ( $conf{datetime} // $now )->strftime('%Y%m%d');
- my $time = ( $conf{datetime} // $now )->strftime('%H%M%S');
-
- my ( $from_lid, $to_lid );
- if ( $self->{from_stop} =~ m{ ^ [0-9]+ $ }x ) {
- $from_lid = 'A=1@L=' . $self->{from_stop} . '@';
- }
- else {
- $from_lid = 'A=1@O=' . $self->{from_stop} . '@';
- }
- if ( $self->{to_stop} =~ m{ ^ [0-9]+ $ }x ) {
- $to_lid = 'A=1@L=' . $self->{to_stop} . '@';
- }
- else {
- $to_lid = 'A=1@O=' . $self->{to_stop} . '@';
- }
-
- $req = {
- svcReqL => [
- {
- meth => 'TripSearch',
- req => {
- depLocL => [ { lid => $from_lid } ],
- arrLocL => [ { lid => $to_lid } ],
- numF => 6,
- maxChg => undef,
- minChgTime => undef,
- outFrwd => undef,
- viaLocL => undef,
- trfReq => {
- cType => 'PK',
- tvlrProf => [ { type => 'E' } ],
- },
- outDate => $date,
- outTime => $time,
- jnyFltrL => [
- {
- type => "PROD",
- mode => "INC",
- value => $self->mot_mask
- }
- ]
+ $from_lid = 'A=1@O=' . $self->{from_stop} . '@';
+ }
+ if ( $self->{to_stop} =~ m{ ^ [0-9]+ $ }x ) {
+ $to_lid = 'A=1@L=' . $self->{to_stop} . '@';
+ }
+ else {
+ $to_lid = 'A=1@O=' . $self->{to_stop} . '@';
+ }
+
+ $req = {
+ svcReqL => [
+ {
+ meth => 'TripSearch',
+ req => {
+ depLocL => [ { lid => $from_lid } ],
+ arrLocL => [ { lid => $to_lid } ],
+ numF => 6,
+ maxChg => undef,
+ minChgTime => undef,
+ outFrwd => undef,
+ viaLocL => undef,
+ trfReq => {
+ cType => 'PK',
+ tvlrProf => [ { type => 'E' } ],
},
+ outDate => $date,
+ outTime => $time,
+ jnyFltrL => [
+ {
+ type => "PROD",
+ mode => "INC",
+ value => $self->mot_mask
+ }
+ ]
},
- ],
- %{ $hafas_instance{$service}{request} }
- };
- }
+ },
+ ],
+ %{ $hafas_instance{$service}{request} }
+ };
if ( $conf{language} ) {
$req->{lang} = $conf{language};
@@ -338,14 +334,9 @@ sub new_p {
my ( $obj, %conf ) = @_;
my $promise = $conf{promise}->new;
- if (
- not( $conf{station}
- or $conf{journey}
- or $conf{geoSearch}
- or $conf{locationSearch} )
- )
- {
- return $promise->reject('station or journey flag must be passed');
+ if ( not( $conf{from_stop} and $conf{to_stop} ) ) {
+ confess('from_stop and to_stop must be specified');
+ return $promise->reject('from_stop and to_stop must be specified');
}
my $self = $obj->new( %conf, async => 1 );
@@ -356,15 +347,7 @@ sub new_p {
my ($content) = @_;
$self->{raw_json} = $self->{json}->decode($content);
$self->check_mgate;
- if ( $conf{journey} ) {
- $self->parse_journey;
- }
- elsif ( $conf{geoSearch} or $conf{locationSearch} ) {
- $self->parse_search;
- }
- else {
- $self->parse_board;
- }
+ $self->parse_trips;
if ( $self->errstr ) {
$promise->reject( $self->errstr, $self );
}
@@ -448,7 +431,6 @@ sub post_with_cache {
my $content = $reply->content;
if ($cache) {
- say "freeeez";
$cache->freeze( $self->{post}, \$content );
}