diff options
author | Gianni Ceccarelli <gianni.ceccarelli@net-a-porter.com> | 2013-05-30 08:00:41 +0100 |
---|---|---|
committer | Gianni Ceccarelli <gianni.ceccarelli@net-a-porter.com> | 2013-05-30 08:00:41 +0100 |
commit | c099b757579129a454739f6e13fc4c5fea4e062e (patch) | |
tree | a9481943b4a6305e931eceb5746467c6546f549e /lib/WebService/TFL/TubeStatus.pm | |
parent | return json response (diff) | |
download | HomePanel-c099b757579129a454739f6e13fc4c5fea4e062e.tar.gz HomePanel-c099b757579129a454739f6e13fc4c5fea4e062e.tar.bz2 HomePanel-c099b757579129a454739f6e13fc4c5fea4e062e.zip |
tube status
Diffstat (limited to 'lib/WebService/TFL/TubeStatus.pm')
-rw-r--r-- | lib/WebService/TFL/TubeStatus.pm | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/WebService/TFL/TubeStatus.pm b/lib/WebService/TFL/TubeStatus.pm new file mode 100644 index 0000000..79230ce --- /dev/null +++ b/lib/WebService/TFL/TubeStatus.pm @@ -0,0 +1,40 @@ +package WebService::TFL::TubeStatus; +use Moose; +use Moose::Util::TypeConstraints; +use MooseX::Types::URI 'Uri'; +use XML::LibXML; +use XML::LibXML::XPathContext; +use WebService::TFL::TubeStatus::Response; +use namespace::autoclean; + +has user_agent => ( + isa => duck_type(['get']), + is => 'ro', + lazy_build => 1, +); +sub _build_user_agent { + require LWP::UserAgent; + my $ua = LWP::UserAgent->new(); + $ua->env_proxy; + return $ua; +} + +has uri => ( + isa => Uri, + is => 'ro', + coerce => 1, + default => 'http://cloud.tfl.gov.uk/TrackerNet/LineStatus', +); + +sub request { + my ($self) = @_; + + my $doc = XML::LibXML->load_xml(location => $self->uri) + or die "Couldn't fetch tube status"; + my $xpath=XML::LibXML::XPathContext->new($doc); + $xpath->registerNs('ws','http://webservices.lul.co.uk/'); + + return WebService::TFL::TubeStatus::Response->new_from_xml($doc,$xpath); +} + +1; |