HAFAS->get_json_p: accept cache and encoding parameters

This commit is contained in:
Daniel Friesel 2022-09-24 15:01:24 +02:00
parent d8cbd9cd6c
commit 208b818d7c
No known key found for this signature in database
GPG key ID: 100D5BFB5166E005

View file

@ -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{;$}{};