diff options
Diffstat (limited to 'lib/Travelynx/Helper/DBRIS.pm')
| -rw-r--r-- | lib/Travelynx/Helper/DBRIS.pm | 105 |
1 files changed, 58 insertions, 47 deletions
diff --git a/lib/Travelynx/Helper/DBRIS.pm b/lib/Travelynx/Helper/DBRIS.pm index e8ef45b..94746cc 100644 --- a/lib/Travelynx/Helper/DBRIS.pm +++ b/lib/Travelynx/Helper/DBRIS.pm @@ -29,8 +29,8 @@ sub new { return bless( \%opt, $class ); } -sub get_station_id_p { - my ( $self, $station_name ) = @_; +sub get_agent { + my ($self) = @_; my $agent = $self->{user_agent}; my $proxy; @@ -48,16 +48,35 @@ sub get_station_id_p { $agent->proxy->https($proxy); } + return $agent; +} + +sub geosearch_p { + my ( $self, %opt ) = @_; + + return Travel::Status::DE::DBRIS->new_p( + promise => 'Mojo::Promise', + user_agent => $self->get_agent, + geoSearch => \%opt, + developer_mode => $self->{log}->is_level('debug') ? 1 : 0, + ); +} + +sub get_station_id_p { + my ( $self, $station_name ) = @_; + my $promise = Mojo::Promise->new; + Travel::Status::DE::DBRIS->new_p( locationSearch => $station_name, - cache => $self->{cache}, + cache => $self->{realtime_cache}, lwp_options => { timeout => 10, agent => $self->{header}{'User-Agent'}, }, - promise => 'Mojo::Promise', - user_agent => $agent, + promise => 'Mojo::Promise', + user_agent => $self->get_agent, + developer_mode => $self->{log}->is_level('debug') ? 1 : 0, )->then( sub { my ($dbris) = @_; @@ -84,22 +103,6 @@ sub get_station_id_p { sub get_departures_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); - } - if ( $opt{station} =~ m{ [@] L = (?<eva> \d+ ) }x ) { $opt{station} = { eva => $+{eva}, @@ -112,12 +115,14 @@ sub get_departures_p { ? $opt{timestamp}->clone : DateTime->now( time_zone => 'Europe/Berlin' ) )->subtract( minutes => $opt{lookbehind} ); + return Travel::Status::DE::DBRIS->new_p( - station => $opt{station}, - datetime => $when, - cache => $self->{cache}, - promise => 'Mojo::Promise', - user_agent => $agent->request_timeout(10), + station => $opt{station}, + datetime => $when, + cache => $self->{realtime_cache}, + promise => 'Mojo::Promise', + user_agent => $self->get_agent->request_timeout(10), + developer_mode => $self->{log}->is_level('debug') ? 1 : 0, ); } @@ -126,28 +131,13 @@ sub get_journey_p { my $promise = Mojo::Promise->new; - 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); - } - Travel::Status::DE::DBRIS->new_p( - journey => $opt{trip_id}, - with_polyline => $opt{with_polyline}, - cache => $self->{realtime_cache}, - promise => 'Mojo::Promise', - user_agent => $agent->request_timeout(10), + journey => $opt{trip_id}, + with_polyline => $opt{with_polyline}, + cache => $self->{realtime_cache}, + promise => 'Mojo::Promise', + user_agent => $self->get_agent->request_timeout(10), + developer_mode => $self->{log}->is_level('debug') ? 1 : 0, )->then( sub { my ($dbris) = @_; @@ -174,4 +164,25 @@ sub get_journey_p { return $promise; } +sub get_wagonorder_p { + my ( $self, %opt ) = @_; + + $self->{log} + ->debug("get_wagonorder_p($opt{train_type} $opt{train_no} @ $opt{eva})"); + + return Travel::Status::DE::DBRIS->new_p( + cache => $self->{main_cache}, + failure_cache => $self->{realtime_cache}, + promise => 'Mojo::Promise', + user_agent => $self->get_agent->request_timeout(10), + formation => { + departure => $opt{datetime}, + eva => $opt{eva}, + train_type => $opt{train_type}, + train_number => $opt{train_no} + }, + developer_mode => $self->{log}->is_level('debug') ? 1 : 0, + ); +} + 1; |
