diff options
author | Daniel Friesel <derf@finalrewind.org> | 2022-10-03 18:43:25 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2022-10-03 18:43:25 +0200 |
commit | 071db7ee1ce1d2d022f192e80cf2f7c7aff4e176 (patch) | |
tree | a04e786f372d50e6ac90d3f702c382f22539ef45 /lib | |
parent | 571f956830a4b7e937490bef7d3643600055ddca (diff) |
allow overriding ua via constructor
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Travel/Status/DE/HAFAS.pm | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm index a1660c8..105bf0f 100644 --- a/lib/Travel/Status/DE/HAFAS.pm +++ b/lib/Travel/Status/DE/HAFAS.pm @@ -180,7 +180,7 @@ sub new { my %lwp_options = %{ $conf{lwp_options} // { timeout => 10 } }; - my $ua = LWP::UserAgent->new(%lwp_options); + my $ua = $conf{user_agent} // LWP::UserAgent->new(%lwp_options); $ua->env_proxy; @@ -188,7 +188,7 @@ sub new { confess('You need to specify a station'); } - if ( not defined $service and not defined $conf{url} ) { + if ( not defined $service ) { $service = $conf{service} = 'DB'; } @@ -196,7 +196,8 @@ sub new { confess("The service '$service' is not supported"); } - my $ref = { + my $now = DateTime->now( time_zone => 'Europe/Berlin' ); + my $self = { active_service => $service, arrivals => $conf{arrivals}, developer_mode => $conf{developer_mode}, @@ -206,23 +207,12 @@ sub new { results => [], station => $conf{station}, ua => $ua, - now => DateTime->now( time_zone => 'Europe/Berlin' ), + now => $now, }; - bless( $ref, $obj ); + bless( $self, $obj ); - if ( $hafas_instance{$service}{mgate} ) { - return $ref->new_mgate(%conf); - } - return $ref->new_legacy(%conf); -} - -sub new_mgate { - my ( $self, %conf ) = @_; - my $json = JSON->new->utf8; - my $service = $conf{service}; - - my $now = $self->{now}; + my $json = JSON->new->utf8; my $date = ( $conf{datetime} // $now )->strftime('%Y%m%d'); my $time = ( $conf{datetime} // $now )->strftime('%H%M%S'); |