summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2014-12-06 20:28:41 +0100
committerDaniel Friesel <derf@finalrewind.org>2014-12-06 20:28:41 +0100
commitc828f5b327bdbcd46a85890221ba47b91df386e0 (patch)
treece26385dd5d047c34f586b2f99d8de8123c7ecf9
parent88da26860bdbfea46b29ef83becb814edb92d10a (diff)
add special api for marudor's departure monitor app
-rw-r--r--index.pl36
1 files changed, 29 insertions, 7 deletions
diff --git a/index.pl b/index.pl
index 14b4a61..0fe6eb6 100644
--- a/index.pl
+++ b/index.pl
@@ -15,7 +15,7 @@ our $VERSION = qx{git describe --dirty} || '0.05';
my $refresh_interval = 180;
sub get_results_for {
- my ( $backend, $station ) = @_;
+ my ( $backend, $station, %opt ) = @_;
my $cache = Cache::File->new(
cache_root => '/tmp/db-fake',
@@ -45,14 +45,17 @@ sub get_results_for {
my $status = Travel::Status::DE::IRIS->new(
station => $station,
- serializable => 1
+ serializable => 1,
+ %opt
);
$results = [ $status->results ];
$cache->freeze( $cache_str, $results );
}
else {
- my $status
- = Travel::Status::DE::DeutscheBahn->new( station => $station );
+ my $status = Travel::Status::DE::DeutscheBahn->new(
+ station => $station,
+ %opt
+ );
$results = [ $status->results ];
$cache->freeze( $cache_str, $results );
}
@@ -75,6 +78,7 @@ sub handle_request {
my $backend = $self->param('backend') // 'ris';
my $admode = $self->param('admode') // 'deparr';
my $callback = $self->param('callback');
+ my %opt;
my $api_version
= $backend eq 'iris'
@@ -85,7 +89,7 @@ sub handle_request {
$self->stash( title => 'db-fakedisplay' );
$self->stash( version => $VERSION );
- if ( not( $template ~~ [qw[clean json multi single]] ) ) {
+ if ( not( $template ~~ [qw[clean json marudor_v1 multi single]] ) ) {
$template = 'multi';
}
@@ -98,10 +102,14 @@ sub handle_request {
return;
}
+ if ( $template eq 'marudor_v1' and $backend eq 'iris' ) {
+ $opt{lookahead} = 120;
+ }
+
my @departures;
- my @results = get_results_for( $backend, $station );
+ my @results = get_results_for( $backend, $station, %opt );
- if ( not @results and $template eq 'json' ) {
+ if ( not @results and $template ~~ [qw[json marudor_v1]] ) {
my $json;
if ( $backend eq 'iris' ) {
my @candidates = map { { code => $_->[0], name => $_->[1] } }
@@ -348,6 +356,20 @@ sub handle_request {
);
}
}
+ if ( $template eq 'marudor_v1' ) {
+ $callback //= 'db_fakedisplay';
+ my $json = $self->render_to_string(
+ json => {
+ api_version => $api_version,
+ preformatted => \@departures,
+ version => $VERSION,
+ }
+ );
+ $self->render(
+ data => "$callback($json);",
+ format => 'json'
+ );
+ }
else {
$self->render(
$template,