summaryrefslogtreecommitdiff
path: root/lib/WebService/TFL/TubeStatus.pm
diff options
context:
space:
mode:
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;