Unverified Commit 6a0dead7 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

add stopfinder support

parent b8a15268
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -325,6 +325,13 @@ sub show_coord {
	}
}

sub show_stopfinder {
	my $max_len = max map { length( $_->full_name ) } $efa->results;
	for my $stop ( $efa->results ) {
		printf( "%-${max_len}s  %s\n", $stop->full_name, $stop->id );
	}
}

sub show_stopseq {
	my $trip = $efa->result;

+27 −1
Original line number Diff line number Diff line
@@ -192,7 +192,7 @@ sub new {
		$self->{post} = {
			locationServerActive => 1,
			type_sf              => 'any',
			name                 => $opt{stopfinder}{name},
			name_sf              => $opt{stopfinder}{name},
			anyObjFilter_sf      => 2,
			coordOutputFormat    => 'WGS84[DD.DDDDD]',
			outputFormat         => 'JSON',
@@ -536,6 +536,9 @@ sub results {
	if ( $self->{post}{coord} ) {
		return $self->results_coord;
	}
	elsif ( $self->{post}{name_sf} ) {
		return $self->results_stopfinder;
	}
	else {
		return $self->results_dm;
	}
@@ -564,6 +567,29 @@ sub results_coord {
	return @results;
}

sub results_stopfinder {
	my ($self) = @_;
	my $json = $self->{response};

	my @results;
	for my $stop ( @{ $json->{stopFinder}{points} // [] } ) {
		push(
			@results,
			Travel::Status::DE::EFA::Stop->new(
				place     => $stop->{ref}{place},
				full_name => $stop->{name},
				name      => $stop->{object},
				id        => $stop->{stateless},
				stop_id   => $stop->{ref}{gid},
			)
		);
	}

	$self->{results} = \@results;

	return @results;
}

sub results_dm {
	my ($self) = @_;
	my $json = $self->{response};