summaryrefslogtreecommitdiff
path: root/lib/WebService/TFL/TubeStatus.pm
diff options
context:
space:
mode:
authorGianni Ceccarelli <gianni.ceccarelli@net-a-porter.com>2013-05-30 08:00:41 +0100
committerGianni Ceccarelli <gianni.ceccarelli@net-a-porter.com>2013-05-30 08:00:41 +0100
commitc099b757579129a454739f6e13fc4c5fea4e062e (patch)
treea9481943b4a6305e931eceb5746467c6546f549e /lib/WebService/TFL/TubeStatus.pm
parentreturn json response (diff)
downloadHomePanel-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.pm40
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;