summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--index.pl57
1 files changed, 56 insertions, 1 deletions
diff --git a/index.pl b/index.pl
index 8a6f0e5..5225377 100644
--- a/index.pl
+++ b/index.pl
@@ -578,7 +578,7 @@ sub handle_request {
}
);
}
- else { # apiver == 2
+ elsif ( $apiver == 2 ) {
my ( $delay_arr, $delay_dep, $sched_arr, $sched_dep );
if ( $result->arrival ) {
$delay_arr = $result->arrival->subtract_datetime(
@@ -631,6 +631,61 @@ sub handle_request {
}
);
}
+ else { # apiver == 3
+ my ( $delay_arr, $delay_dep, $sched_arr, $sched_dep );
+ if ( $result->arrival ) {
+ $delay_arr = $result->arrival->subtract_datetime(
+ $result->sched_arrival )->in_units('minutes');
+ }
+ if ( $result->departure ) {
+ $delay_dep = $result->departure->subtract_datetime(
+ $result->sched_departure )->in_units('minutes');
+ }
+ if ( $result->sched_arrival ) {
+ $sched_arr = $result->sched_arrival->strftime('%H:%M');
+ }
+ if ( $result->sched_departure ) {
+ $sched_dep = $result->sched_departure->strftime('%H:%M');
+ }
+ push(
+ @departures,
+ {
+ delayArrival => $delay_arr,
+ delayDeparture => $delay_dep,
+ destination => $result->destination,
+ isCancelled => $result->can('is_cancelled')
+ ? $result->is_cancelled
+ : undef,
+ messages => {
+ delay => [
+ map {
+ {
+ timestamp => $_->[0],
+ text => $_->[1]
+ }
+ } $result->delay_messages
+ ],
+ qos => [
+ map {
+ {
+ timestamp => $_->[0],
+ text => $_->[1]
+ }
+ } $result->qos_messages
+ ],
+ },
+ platform => $result->platform,
+ route => \@json_route,
+ scheduledPlatform => $result->sched_platform,
+ scheduledArrival => $sched_arr,
+ scheduledDeparture => $sched_dep,
+ train => $result->train,
+ trainClasses => [ $result->classes ],
+ trainNumber => $result->train_no,
+ via => [ $result->route_interesting(3) ],
+ }
+ );
+ }
}
elsif ( $backend eq 'iris' ) {
push(