diff options
author | Daniel Friesel <derf@finalrewind.org> | 2022-10-03 08:04:36 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2022-10-03 08:04:36 +0200 |
commit | 4a3feb4cb5f97e5ae992bca9b34042c162580238 (patch) | |
tree | 19d16663f8fc66444425f5d16810a1a4be5a8f36 /lib | |
parent | 5c2e92955a045a1245123629ca0915b0b9bfd213 (diff) |
mgate: add message support
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Travel/Status/DE/HAFAS.pm | 38 | ||||
-rw-r--r-- | lib/Travel/Status/DE/HAFAS/Message.pm | 3 |
2 files changed, 40 insertions, 1 deletions
diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm index 8d6c81b..e67c72b 100644 --- a/lib/Travel/Status/DE/HAFAS.pm +++ b/lib/Travel/Status/DE/HAFAS.pm @@ -497,6 +497,32 @@ sub similar_stops { return; } +sub add_message { + my ( $self, $json ) = @_; + + my $short = $json->{txtS}; + my $text = $json->{txtN}; + my $code = $json->{code}; + my $prio = $json->{prio}; + + for my $message ( @{ $self->{messages} } ) { + if ( $code eq $message->{code} and $text eq $message->{text} ) { + $message->{ref_count}++; + return $message; + } + } + + my $message = Travel::Status::DE::HAFAS::Message->new( + short => $short, + text => $text, + code => $code, + prio => $prio, + ref_count => 1, + ); + push( @{ $self->{messages} }, $message ); + return $message; +} + sub add_message_node { my ( $self, $node ) = @_; @@ -623,6 +649,7 @@ sub parse_mgate { my @prodL = @{ $self->{raw_json}{svcResL}[0]{res}{common}{prodL} // [] }; my @opL = @{ $self->{raw_json}{svcResL}[0]{res}{common}{opL} // [] }; my @icoL = @{ $self->{raw_json}{svcResL}[0]{res}{common}{icoL} // [] }; + my @remL = @{ $self->{raw_json}{svcResL}[0]{res}{common}{remL} // [] }; my @jnyL = @{ $self->{raw_json}{svcResL}[0]{res}{jnyL} // [] }; for my $result (@jnyL) { @@ -660,6 +687,16 @@ sub parse_mgate { } } + my @messages; + for my $msg ( @{ $result->{msgL} // [] } ) { + if ( $msg->{type} eq 'REM' and defined $msg->{remX} ) { + push( @messages, $self->add_message( $remL[ $msg->{remX} ] ) ); + } + else { + say "Unknown message type $msg->{type}"; + } + } + push( @{ $self->{results} }, Travel::Status::DE::HAFAS::Result->new( @@ -674,6 +711,7 @@ sub parse_mgate { route_end => $destination, platform => $platform, new_platform => $new_platform, + messages => \@messages, ) ); } diff --git a/lib/Travel/Status/DE/HAFAS/Message.pm b/lib/Travel/Status/DE/HAFAS/Message.pm index f691a94..bfbf0ba 100644 --- a/lib/Travel/Status/DE/HAFAS/Message.pm +++ b/lib/Travel/Status/DE/HAFAS/Message.pm @@ -8,7 +8,8 @@ use parent 'Class::Accessor'; our $VERSION = '3.01'; -Travel::Status::DE::HAFAS::Message->mk_ro_accessors(qw(header lead ref_count)); +Travel::Status::DE::HAFAS::Message->mk_ro_accessors( + qw(short text code prio ref_count)); sub new { my ( $obj, %conf ) = @_; |