WWW-PIDS
view release on metacpan or search on metacpan
lib/WWW/PIDS.pm view on Meta::CPAN
my $valid = __validate_parameters( $method, %parameters );
die $valid unless ( $valid eq "1" );
my @body = __construct_body( $method, %parameters );
my $r = SOAP::Lite->endpoint( $ENDPOINT )
->default_ns( $NS )
->proxy( $PROXY )
->on_action( sub { "$NS$method" } )
->$method( @body, $self->{pids_header} )
->result;
return $METHODS{ $method }{ 'result' }->($r);
};
}
}
sub __validate_parameters {
my ( $m, %p ) = @_;
return 1 if not defined $METHODS{ $m }{ 'parameters' };
for my $param ( @{ $METHODS{ $m }{ 'parameters' } } ) {
defined $p{ $param->{ param } }
or return "Mandatory parameter $param->{ param } missing";
( $p{ $param->{ param } } =~ $param->{ format } )
or return "Value of parameter $param->{ param } does not conform to expected format";
}
return 1
}
sub __construct_body {
my ( $m, %p ) = @_;
my @b;
for my $param ( @{ $METHODS{ $m }{ 'parameters' } } ) {
push @b, SOAP::Data->name( $param->{ param } => $p{ $param->{ param } } )
->type( $param->{ type } )
}
return @b
}
sub new {
my ( $class, %args ) = @_;
my $self = bless {}, $class;
for my $a ( keys %ATTR ) {
defined $args{ $a }
? $self->{ $a } = $args{ $a }
: $self->{ $a } = $ATTR{ $a } ;
}
defined $self->{ 'ClientGuid' } or $self->{ 'ClientGuid' } = $self->GetNewClientGuid();
$ATTR{ 'ClientGuid' } = $self->{ 'ClientGuid' };
$self->{pids_header} = SOAP::Header->name( 'PidsClientHeader' )
->attr( { 'xmlns' => $NS } )
->value( \SOAP::Header->value(
SOAP::Header->name( 'ClientGuid' => $ATTR{ 'ClientGuid' } ),
SOAP::Header->name( 'ClientType' => $ATTR{ 'ClientType' } ),
SOAP::Header->name( 'ClientVersion' => $ATTR{ 'ClientVersion' } ),
SOAP::Header->name( 'ClientWebServiceVersion' => $ATTR{ 'ClientWebServiceVersion' } )
) );
return $self
}
1;
__END__
=head1 NAME
WWW::PIDS - Perl API for the tramTRACKER PIDS Web Service
=head1 SYNOPSIS
WWW::PIDS is a Perl API to the PIDS tramTRACKER web service.
The tramTRACKER PIDS web service I<"is a public Web Service that provides a set
of Web Methods to request real-time and scheduled tram arrival times, as well
as stops and routes information.">.
You can find more information on the tramTRACKER PIDS web service here
L<http://ws.tramtracker.com.au/pidsservice/pids.asmx>.
use WWW::PIDS;
my $p = WWW::PIDS->new();
# Get a list of route summaries as WWW::PIDS::RouteSummary objects
my @routes = $p->GetRouteSummaries();
# Print all route numbers and descriptions
for my $route ( @routes ) {
printf( "%-3s : %s\n", $route->RouteNo, $route->Description )
}
# Tweaking our recipe above; let's display an in-oder list of the
# stop names for each route and add pretty up our output.
for my $route ( @routes ) {
printf( "%s\n| %-3s | %-71s|\n%s\n",
('+-----+' . ('-'x72).'+'), # Ugly ascii "table"
$route->RouteNo,
$route->Description,
('+-----+' . ('-'x72).'+') );
my @stops = $p->GetListOfStopsByRouteNoAndDirection(
routeNo => $route->RouteNo,
isUpDirection => 0
);
for my $stop ( @stops ) {
printf( " |__ %s\n", $stop->Description )
}
}
# Produces a route stop listing like:
+------------------------------------------------------------------------------+
| 1 | East Coburg - South Melbourne Beach |
+------------------------------------------------------------------------------+
|__ Beaconsfield Pde
( run in 1.891 second using v1.01-cache-2.11-cpan-39bf76dae61 )