summaryrefslogtreecommitdiff
path: root/lib/Travel/Status
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Travel/Status')
-rw-r--r--lib/Travel/Status/DE/HAFAS.pm38
-rw-r--r--lib/Travel/Status/DE/HAFAS/Message.pm3
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 ) = @_;