diff options
author | Daniel Friesel <derf@finalrewind.org> | 2014-01-22 23:25:32 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2014-01-22 23:25:48 +0100 |
commit | 375fc4b815d6cf69c5d268dd1156df29045d1da1 (patch) | |
tree | b54b0e4589102ee54da25215138874584002df47 /lib/Travel/Status/DE | |
parent | 8d952e1b3a40d59d95e827aee419b3bf79194cb9 (diff) |
URA: Remove new_from_raw test constructor, accept file: URLs
change tests accordingly
Diffstat (limited to 'lib/Travel/Status/DE')
-rw-r--r-- | lib/Travel/Status/DE/URA.pm | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/lib/Travel/Status/DE/URA.pm b/lib/Travel/Status/DE/URA.pm index 5e25074..99a56fe 100644 --- a/lib/Travel/Status/DE/URA.pm +++ b/lib/Travel/Status/DE/URA.pm @@ -19,13 +19,14 @@ sub new { my ( $class, %opt ) = @_; my $ua = LWP::UserAgent->new(%opt); + my $response; if ( not( $opt{ura_base} and $opt{ura_version} ) ) { confess('ura_base and ura_version are mandatory'); } my $self = { - datetime => $opt{datetime} + datetime => $opt{datetime} // DateTime->now( time_zone => 'Europe/Berlin' ), ura_base => $opt{ura_base}, ura_version => $opt{ura_version}, @@ -47,7 +48,12 @@ sub new { $ua->env_proxy; - my $response = $ua->post( $self->{ura_instant_url}, $self->{post} ); + if ( substr( $self->{ura_instant_url}, 0, 5 ) ne 'file:' ) { + $response = $ua->post( $self->{ura_instant_url}, $self->{post} ); + } + else { + $response = $ua->get( $self->{ura_instant_url} ); + } if ( $response->is_error ) { $self->{errstr} = $response->status_line; @@ -55,28 +61,9 @@ sub new { } $self->{raw_str} = $response->decoded_content; - - $self->parse_raw_data; - - return $self; -} - -sub new_from_raw { - my ( $class, %opt ) = @_; - - my $self = { - datetime => $opt{datetime} - // DateTime->now( time_zone => 'Europe/Berlin' ), - ura_base => $opt{ura_base}, - ura_version => $opt{ura_version}, - full_routes => $opt{full_routes} // 0, - hide_past => $opt{hide_past} // 1, - stop => $opt{stop}, - via => $opt{via}, - raw_str => $opt{raw_str} - }; - - bless( $self, $class ); + if ( substr( $self->{ura_instant_url}, 0, 5 ) eq 'file:' ) { + $self->{raw_str} = encode( 'UTF-8', $self->{raw_str} ); + } $self->parse_raw_data; |