diff options
author | dakkar <dakkar@thenautilus.net> | 2023-12-09 13:19:26 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2023-12-09 13:19:26 +0000 |
commit | 5c48b7da4780bcdac4757ad5c23e74e3f6744c42 (patch) | |
tree | 7b81b6523b99e85c05798667ab908ef62da39340 /lib/WebService/TFL/TubeStatus.pm | |
parent | new bus api (diff) | |
download | HomePanel-5c48b7da4780bcdac4757ad5c23e74e3f6744c42.tar.gz HomePanel-5c48b7da4780bcdac4757ad5c23e74e3f6744c42.tar.bz2 HomePanel-5c48b7da4780bcdac4757ad5c23e74e3f6744c42.zip |
new tube api
Diffstat (limited to 'lib/WebService/TFL/TubeStatus.pm')
-rw-r--r-- | lib/WebService/TFL/TubeStatus.pm | 25 |
1 files changed, 17 insertions, 8 deletions
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; |