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

move geosearch into dbris helper; enable proxies

parent a083884d
Loading
Loading
Loading
Loading
+4 −8
Original line number Diff line number Diff line
@@ -594,13 +594,9 @@ sub geolocation {
	if ($dbris_service) {
		$self->render_later;

		Travel::Status::DE::DBRIS->new_p(
			promise    => 'Mojo::Promise',
			user_agent => Mojo::UserAgent->new,
			geoSearch  => {
		$self->dbris->geosearch_p(
			latitude  => $lat,
			longitude => $lon
			}
		)->then(
			sub {
				my ($dbris) = @_;
@@ -2486,7 +2482,7 @@ sub edit_journey {
					uid  => $uid,
					db   => $db,
					id   => $journey->{id},
					$key => $self->param($key)
					$key => $self->param($key),
				);
				if ($error) {
					last;
+25 −0
Original line number Diff line number Diff line
@@ -29,6 +29,31 @@ sub new {
	return bless( \%opt, $class );
}

sub geosearch_p {
	my ( $self, %opt ) = @_;
	my $agent = $self->{user_agent};
	my $proxy;
	if ( my @proxies = @{ $self->{service_config}{'bahn.de'}{proxies} // [] } )
	{
		$proxy = $proxies[ int( rand( scalar @proxies ) ) ];
	}
	elsif ( my $p = $self->{service_config}{'bahn.de'}{proxy} ) {
		$proxy = $p;
	}

	if ($proxy) {
		$agent = Mojo::UserAgent->new;
		$agent->proxy->http($proxy);
		$agent->proxy->https($proxy);
	}

	return Travel::Status::DE::DBRIS->new_p(
		promise    => 'Mojo::Promise',
		user_agent => $agent,
		geoSearch  => \%opt,
	);
}

sub get_station_id_p {
	my ( $self, $station_name ) = @_;