summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDerf Null <derf@finalrewind.org>2023-04-10 21:42:06 +0200
committerDerf Null <derf@finalrewind.org>2023-04-10 21:42:06 +0200
commit2542ed41c818ba1cd1e000bc4b5c133972507aea (patch)
tree98132d2b257b076b7b9e83147c5da17fb41d178b /lib
parenta789b0e271dc66498896176d02afd18c13744fc1 (diff)
add locationSearch support
Diffstat (limited to 'lib')
-rw-r--r--lib/Travel/Status/DE/HAFAS.pm57
-rw-r--r--lib/Travel/Status/DE/HAFAS/Stop.pm6
2 files changed, 50 insertions, 13 deletions
diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm
index 1250857..23aba6e 100644
--- a/lib/Travel/Status/DE/HAFAS.pm
+++ b/lib/Travel/Status/DE/HAFAS.pm
@@ -193,8 +193,15 @@ sub new {
$ua->env_proxy;
}
- if ( not( $conf{station} or $conf{journey} or $conf{geoSearch} ) ) {
- confess('station / journey / geoSearch must be specified');
+ if (
+ not( $conf{station}
+ or $conf{journey}
+ or $conf{geoSearch}
+ or $conf{locationSearch} )
+ )
+ {
+ confess(
+ 'station / journey / geoSearch / locationSearch must be specified');
}
if ( not defined $service ) {
@@ -270,6 +277,27 @@ sub new {
%{ $hafas_instance{$service}{request} }
};
}
+ elsif ( $conf{locationSearch} ) {
+ $req = {
+ svcReqL => [
+ {
+ cfg => { polyEnc => 'GPA' },
+ meth => 'LocMatch',
+ req => {
+ input => {
+ loc => {
+ type => 'S',
+ name => $conf{locationSearch},
+ },
+ maxLoc => 10,
+ field => 'S',
+ },
+ }
+ }
+ ],
+ %{ $hafas_instance{$service}{request} }
+ };
+ }
else {
my $date = ( $conf{datetime} // $now )->strftime('%Y%m%d');
my $time = ( $conf{datetime} // $now )->strftime('%H%M%S');
@@ -372,8 +400,8 @@ sub new {
if ( $conf{journey} ) {
$self->parse_journey;
}
- elsif ( $conf{geoSearch} ) {
- $self->parse_geosearch;
+ elsif ( $conf{geoSearch} or $conf{locationSearch} ) {
+ $self->parse_search;
}
else {
$self->parse_board;
@@ -401,8 +429,8 @@ sub new_p {
if ( $conf{journey} ) {
$self->parse_journey;
}
- elsif ( $conf{geoSearch} ) {
- $self->parse_geosearch;
+ elsif ( $conf{geoSearch} or $conf{locationSearch} ) {
+ $self->parse_search;
}
else {
$self->parse_board;
@@ -613,7 +641,7 @@ sub add_message {
return $message;
}
-sub parse_geosearch {
+sub parse_search {
my ($self) = @_;
$self->{results} = [];
@@ -625,6 +653,10 @@ sub parse_geosearch {
my @refLocL = @{ $self->{raw_json}{svcResL}[0]{res}{common}{locL} // [] };
my @locL = @{ $self->{raw_json}{svcResL}[0]{res}{locL} // [] };
+ if ( $self->{raw_json}{svcResL}[0]{res}{match} ) {
+ @locL = @{ $self->{raw_json}{svcResL}[0]{res}{match}{locL} // [] };
+ }
+
for my $loc (@locL) {
push(
@{ $self->{results} },
@@ -886,7 +918,7 @@ Requests item(s) as specified by I<opt> and returns a new
Travel::Status::DE::HAFAS element with the results. Dies if the wrong
I<opt> were passed.
-I<opt> must contain either a B<station>, a B<geoSearch>, or a B<journey> flag:
+I<opt> must contain either a B<station>, B<geoSearch>, B<locationSearch>, or B<journey> flag:
=over
@@ -902,6 +934,11 @@ Results are available via C<< $status->results >>.
Search for stations near I<latitude>, I<longitude>.
Results are available via C<< $status->results >>.
+=item B<locationSearch> => I<query>
+
+Search for stations whose name is similar to I<query>.
+Results are available via C<< $status->results >>.
+
=item B<journey> => B<{> B<id> => I<tripid> [, B<name> => I<line> ] B<}>
Request details about the journey identified by I<tripid> and I<line>.
@@ -953,7 +990,7 @@ Default: -1 (do not limit results by time).
Passed on to C<< LWP::UserAgent->new >>. Defaults to C<< { timeout => 10 } >>,
pass an empty hashref to call the LWP::UserAgent constructor without arguments.
-=item B<results> => I<count> (geoSearch, station)
+=item B<results> => I<count> (geoSearch, locationSearch, station)
Request up to I<count> results.
Default: 30.
@@ -1001,7 +1038,7 @@ as string. If no backend error occurred, returns undef.
In case of an error in the HTTP request or HAFAS backend, returns a string
describing it. If no error occurred, returns undef.
-=item $status->results (geoSearch)
+=item $status->results (geoSearch, locationSearch)
Returns a list of stations. Each list element is a
Travel::Status::DE::HAFAS::Stop(3pm) object.
diff --git a/lib/Travel/Status/DE/HAFAS/Stop.pm b/lib/Travel/Status/DE/HAFAS/Stop.pm
index 1f16550..3c56900 100644
--- a/lib/Travel/Status/DE/HAFAS/Stop.pm
+++ b/lib/Travel/Status/DE/HAFAS/Stop.pm
@@ -61,10 +61,10 @@ version 4.09
=head1 DESCRIPTION
Travel::Status::DE::HAFAS::Stop describes a HAFAS stop. It may be part of a
-journey or part of a geoSearch request.
+journey or part of a geoSearch / locationSearch request.
-geoSearch-specific accessors are annotated with "(geoSearch)" and return
-undef for non-geoSearch stops.
+geoSearch- and locationSearch-specific accessors are annotated accordingly and
+return undef for non-geoSearch / non-locationSearch stops.
=head1 METHODS