summaryrefslogtreecommitdiff
path: root/lib/WebService/TFL/Bus.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/WebService/TFL/Bus.pm')
-rw-r--r--lib/WebService/TFL/Bus.pm23
1 files changed, 15 insertions, 8 deletions
diff --git a/lib/WebService/TFL/Bus.pm b/lib/WebService/TFL/Bus.pm
index 3559755..31bd9c3 100644
--- a/lib/WebService/TFL/Bus.pm
+++ b/lib/WebService/TFL/Bus.pm
@@ -1,9 +1,9 @@
package WebService::TFL::Bus;
use Moo;
-use namespace::autoclean;
use Types::URI 'Uri';
use Type::Utils 'duck_type';
use WebService::TFL::Bus::Response;
+use namespace::clean;
has user_agent => (
isa => duck_type(['get']),
@@ -21,21 +21,28 @@ has uri => (
isa => Uri,
is => 'ro',
coerce => Uri->coercion,
- default => 'http://countdown.api.tfl.gov.uk/interfaces/ura/instant_V1',
+ default => 'https://api.tfl.gov.uk/StopPoint/__/Arrivals',
+);
+
+has parser => (
+ is => 'lazy',
+ builder => sub { JSON->new->utf8 },
);
sub request {
- my ($self,$request) = @_;
+ my ($self,$stop_id) = @_;
- my $http_response = $self->user_agent->get(
- $request->request_uri($self->uri)
+ my $uri = $self->uri->clone;
+ $uri->path_segments(
+ map { $_ eq '__' ? $stop_id : $_ } $uri->path_segments
);
+
+ my $http_response = $self->user_agent->get($uri);
if ($http_response->is_success) {
my $json = $http_response->content;
- return WebService::TFL::Bus::Response->new_from_json(
- $request->ReturnList,
- $json
+ return WebService::TFL::Bus::Response->new_from_response(
+ $self->parser->decode($json)
);
}
else {