summaryrefslogtreecommitdiff
path: root/lib/WebService/TFL/TubeStatus/Response
diff options
context:
space:
mode:
Diffstat (limited to 'lib/WebService/TFL/TubeStatus/Response')
-rw-r--r--lib/WebService/TFL/TubeStatus/Response/Line.pm25
-rw-r--r--lib/WebService/TFL/TubeStatus/Response/LineStatus.pm25
2 files changed, 21 insertions, 29 deletions
diff --git a/lib/WebService/TFL/TubeStatus/Response/Line.pm b/lib/WebService/TFL/TubeStatus/Response/Line.pm
index 9779443..f962418 100644
--- a/lib/WebService/TFL/TubeStatus/Response/Line.pm
+++ b/lib/WebService/TFL/TubeStatus/Response/Line.pm
@@ -1,13 +1,12 @@
package WebService::TFL::TubeStatus::Response::Line;
use Moo;
use Types::Standard -all;
-use WebService::TFL::TubeStatus::Types -all;
use WebService::TFL::TubeStatus::Response::LineStatus;
-use namespace::autoclean;
+use namespace::clean;
has id => (
is => 'ro',
- isa => Num,
+ isa => Str,
required => 1,
);
@@ -19,20 +18,20 @@ has name => (
has status => (
is => 'ro',
- isa => LineStatusT,
+ isa => InstanceOf['WebService::TFL::TubeStatus::Response::LineStatus'],
required => 1,
);
-sub new_from_xml {
- my ($class,$line,$status,$xpath) = @_;
-
- my %init_arg;
-
- $init_arg{id} = $line->findvalue(q{@ID});
- $init_arg{name} = $line->findvalue(q{@Name});
- $init_arg{status} = WebService::TFL::TubeStatus::Response::LineStatus->new_from_xml($status,$xpath);
+sub new_from_response {
+ my ($class,$response_data) = @_;
- return $class->new(\%init_arg);
+ return $class->new({
+ id => $response_data->{id},
+ name => $response_data->{name},
+ status => WebService::TFL::TubeStatus::Response::LineStatus->new_from_response(
+ $response_data->{lineStatuses}[0],
+ ),
+ });
}
1;
diff --git a/lib/WebService/TFL/TubeStatus/Response/LineStatus.pm b/lib/WebService/TFL/TubeStatus/Response/LineStatus.pm
index 6caa7d6..69ddf20 100644
--- a/lib/WebService/TFL/TubeStatus/Response/LineStatus.pm
+++ b/lib/WebService/TFL/TubeStatus/Response/LineStatus.pm
@@ -1,33 +1,26 @@
package WebService::TFL::TubeStatus::Response::LineStatus;
use Moo;
use Types::Standard -all;
-use namespace::autoclean;
+use namespace::clean;
-has is_active => (
+has [qw(statusSeverity statusSeverityDescription)] => (
is => 'ro',
- isa => Bool,
+ isa => Str,
required => 1,
);
-has [qw(code class description details)] => (
+has reason => (
is => 'ro',
isa => Str,
- required => 1,
);
-sub new_from_xml {
- my ($class,$ls,$xpath) = @_;
-
- my %init_arg;
+sub new_from_response {
+ my ($class,$response_data) = @_;
- my ($status) = $xpath->findnodes(q{ws:Status},$ls);
- $init_arg{code} = $status->findvalue(q{@ID});
- $init_arg{is_active} = $status->findvalue(q{@IsActive}) eq 'true';
- $init_arg{class} = $status->findvalue(q{@CssClass});
- $init_arg{description} = $status->findvalue(q{@Description});
- $init_arg{details} = $ls->findvalue(q{@StatusDetails});
+ $response_data->{reason} =~ s{\A .+? : \s*}{}x
+ if $response_data->{reason};
- return $class->new(\%init_arg);
+ return $class->new($response_data);
}
1;