From 5c48b7da4780bcdac4757ad5c23e74e3f6744c42 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sat, 9 Dec 2023 13:19:26 +0000 Subject: new tube api --- lib/WebService/TFL/TubeStatus.pm | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'lib/WebService/TFL/TubeStatus.pm') diff --git a/lib/WebService/TFL/TubeStatus.pm b/lib/WebService/TFL/TubeStatus.pm index b0ba260..4166a79 100644 --- a/lib/WebService/TFL/TubeStatus.pm +++ b/lib/WebService/TFL/TubeStatus.pm @@ -2,8 +2,6 @@ package WebService::TFL::TubeStatus; use Moo; use Type::Utils 'duck_type'; use Types::URI 'Uri'; -use XML::LibXML; -use XML::LibXML::XPathContext; use WebService::TFL::TubeStatus::Response; use namespace::autoclean; @@ -22,18 +20,29 @@ has uri => ( isa => Uri, is => 'ro', coerce => Uri->coercion, - default => 'http://cloud.tfl.gov.uk/TrackerNet/LineStatus', + default => 'https://api.tfl.gov.uk/Line/Mode/tube/Status', +); + +has parser => ( + is => 'lazy', + builder => sub { JSON->new->utf8 }, ); 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); + my $http_response = $self->user_agent->get($self->uri); + if ($http_response->is_success) { + my $json = $http_response->content; + + return WebService::TFL::TubeStatus::Response->new_from_response( + $self->parser->decode($json) + ); + } + else { + die $http_response->status_line; + } } 1; -- cgit v1.2.3