summaryrefslogtreecommitdiff
path: root/lib/Travelynx
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2022-09-24 15:01:24 +0200
committerDaniel Friesel <derf@finalrewind.org>2022-09-24 15:01:24 +0200
commit208b818d7c5c503149ecc0b662c02b0b4af63a41 (patch)
tree3329dc8ac2c302f289f1578c6ffc7c11e2f3de39 /lib/Travelynx
parentd8cbd9cd6cd19f164b865d54584f05c1490c77f7 (diff)
HAFAS->get_json_p: accept cache and encoding parameters
Diffstat (limited to 'lib/Travelynx')
-rw-r--r--lib/Travelynx/Helper/HAFAS.pm9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/Travelynx/Helper/HAFAS.pm b/lib/Travelynx/Helper/HAFAS.pm
index 383b3bd..c8e0ef4 100644
--- a/lib/Travelynx/Helper/HAFAS.pm
+++ b/lib/Travelynx/Helper/HAFAS.pm
@@ -119,11 +119,16 @@ sub get_polyline_p {
}
sub get_json_p {
- my ( $self, $url ) = @_;
+ my ( $self, $url, %opt ) = @_;
my $cache = $self->{main_cache};
my $promise = Mojo::Promise->new;
+ if ( $opt{realtime} ) {
+ $cache = $self->{realtime_cache};
+ }
+ $opt{encoding} //= 'ISO-8859-15';
+
if ( my $content = $cache->thaw($url) ) {
return $promise->resolve($content);
}
@@ -140,7 +145,7 @@ sub get_json_p {
return;
}
- my $body = decode( 'ISO-8859-15', $tx->res->body );
+ my $body = decode( $opt{encoding}, $tx->res->body );
$body =~ s{^TSLs[.]sls = }{};
$body =~ s{;$}{};