summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Travel/Status/DE/URA.pm35
-rw-r--r--t/20-aseag.t21
-rw-r--r--t/21-get-stop-by-name.t11
-rw-r--r--t/22-results-via.t22
-rw-r--r--t/in/instant_V1 (renamed from t/in/aseag_20131223T132300)0
5 files changed, 37 insertions, 52 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;
diff --git a/t/20-aseag.t b/t/20-aseag.t
index 2d96037..84bb6e2 100644
--- a/t/20-aseag.t
+++ b/t/20-aseag.t
@@ -5,17 +5,17 @@ use 5.010;
use utf8;
use Encode qw(decode);
-use File::Slurp qw(slurp);
use List::Util qw(first);
-use Test::More tests => 14;
+use Test::More tests => 13;
BEGIN {
- use_ok('Travel::Status::DE::ASEAG');
+ use_ok('Travel::Status::DE::URA');
}
-require_ok('Travel::Status::DE::ASEAG');
+require_ok('Travel::Status::DE::URA');
-my $rawstr = slurp('t/in/aseag_20131223T132300');
-my $s = Travel::Status::DE::ASEAG->new_from_raw(
+my $s = Travel::Status::DE::URA->new(
+ ura_base => 'file:t/in',
+ ura_version => 1,
datetime => DateTime->new(
year => 2014,
month => 1,
@@ -24,12 +24,10 @@ my $s = Travel::Status::DE::ASEAG->new_from_raw(
minute => 1,
time_zone => 'Europe/Berlin'
),
- raw_str => $rawstr,
hide_past => 0
);
-isa_ok( 'Travel::Status::DE::ASEAG', 'Travel::Status::DE::URA' );
-isa_ok( $s, 'Travel::Status::DE::ASEAG' );
+isa_ok( $s, 'Travel::Status::DE::URA' );
can_ok( $s, qw(errstr results) );
@@ -67,7 +65,9 @@ is( ( first { $_->stop ne 'Aachen Bushof' } @results ),
undef, '"Aachen Bushof" only matches "Aachen Bushof"' );
# exact matching: also works in constructor
-$s = Travel::Status::DE::ASEAG->new_from_raw(
+$s = Travel::Status::DE::URA->new(
+ ura_base => 'file:t/in',
+ ura_version => 1,
datetime => DateTime->new(
year => 2014,
month => 1,
@@ -76,7 +76,6 @@ $s = Travel::Status::DE::ASEAG->new_from_raw(
minute => 1,
time_zone => 'Europe/Berlin'
),
- raw_str => $rawstr,
hide_past => 0,
stop => 'Aachen Bushof',
);
diff --git a/t/21-get-stop-by-name.t b/t/21-get-stop-by-name.t
index 43952ac..48cd3a7 100644
--- a/t/21-get-stop-by-name.t
+++ b/t/21-get-stop-by-name.t
@@ -5,18 +5,17 @@ use 5.010;
use utf8;
use Encode qw(decode);
-use File::Slurp qw(slurp);
use List::Util qw(first);
use Test::More tests => 5;
BEGIN {
- use_ok('Travel::Status::DE::ASEAG');
+ use_ok('Travel::Status::DE::URA');
}
-require_ok('Travel::Status::DE::ASEAG');
+require_ok('Travel::Status::DE::URA');
-my $rawstr = slurp('t/in/aseag_20131223T132300');
-my $s = Travel::Status::DE::ASEAG->new_from_raw(
- raw_str => $rawstr,
+my $s = Travel::Status::DE::URA->new(
+ ura_base => 'file:t/in',
+ ura_version => 1,
hide_past => 0
);
diff --git a/t/22-results-via.t b/t/22-results-via.t
index 7bda954..ac8d7eb 100644
--- a/t/22-results-via.t
+++ b/t/22-results-via.t
@@ -4,22 +4,21 @@ use warnings;
use 5.010;
use utf8;
-use Encode qw(decode);
-use File::Slurp qw(slurp);
use List::Util qw(first);
use Test::More tests => 23;
BEGIN {
- use_ok('Travel::Status::DE::ASEAG');
+ use_ok('Travel::Status::DE::URA');
}
-require_ok('Travel::Status::DE::ASEAG');
+require_ok('Travel::Status::DE::URA');
-my $rawstr = slurp('t/in/aseag_20131223T132300');
my ($s, @results);
# via filter in ->results, implicit route_after
-$s = Travel::Status::DE::ASEAG->new_from_raw(
+$s = Travel::Status::DE::URA->new(
+ ura_base => 'file:t/in',
+ ura_version => 1,
datetime => DateTime->new(
year => 2013,
month => 12,
@@ -28,7 +27,6 @@ $s = Travel::Status::DE::ASEAG->new_from_raw(
minute => 0,
time_zone => 'Europe/Berlin'
),
- raw_str => $rawstr,
hide_past => 0,
stop => 'Aachen Bushof',
);
@@ -63,8 +61,9 @@ is(
# via filter in ->results, explicit route_after
-$s = Travel::Status::DE::ASEAG->new_from_raw(
- raw_str => $rawstr,
+$s = Travel::Status::DE::URA->new(
+ ura_base => 'file:t/in',
+ ura_version => 1,
hide_past => 0,
stop => 'Aachen Bushof',
);
@@ -102,8 +101,9 @@ is(
# via filter in ->results, explicit route_before
-$s = Travel::Status::DE::ASEAG->new_from_raw(
- raw_str => $rawstr,
+$s = Travel::Status::DE::URA->new(
+ ura_base => 'file:t/in',
+ ura_version => 1,
hide_past => 0,
stop => 'Aachen Bushof',
);
diff --git a/t/in/aseag_20131223T132300 b/t/in/instant_V1
index 7b99f4b..7b99f4b 100644
--- a/t/in/aseag_20131223T132300
+++ b/t/in/instant_V1