summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2016-06-19 22:18:21 +0200
committerDaniel Friesel <derf@finalrewind.org>2016-06-19 22:18:21 +0200
commitad1651ebca7fc9600e284a35dd12685b53381d4c (patch)
tree41ff5faf25b61b4ab5a3c605f1fe817961a0fb83
parentab3318c5fe1d6e0b767cebc090c8dbaa9dd9a14c (diff)
Add marudor API v3 (adds trainClasses and trainNumber elements)
-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(