NAME

WebService::OCTranspo - Access Ottawa bus schedule information from www.octranspo.com

SYNOPSIS

    use WebService::OCTranspo;
    my $oc = WebService::OCTranspo->new();

    my $schedule = $oc->schedule_for_stop({
        stop_id  => $stop,
        route_id => $route,
        date     => DateTime->now(),
    });

    print "$s->{route_number} - $s->{route_name} departing $s->{stop_name} ($s->{stop_number})\n";

    foreach my $time ( @{ $s->{times} } ) {
        print " $time\n";
    }

  

DESCRIPTION

This module provides access to some of the bus schedule information available from OCTranspo -- the public transit service in Ottawa, Ontario, Canada.

METHODS

new ( )

Creates a new WebService::OCTranspo object

schedule_for_stop ( $args )

Fetch schedule for a single route at a single stop. Returns reference to hash containing schedule info for that route at that stop.

$args must be a hash reference containing all of:

stop_id

The numeric ID of the bus stop. This should be the "560 Code" displayed at each stop, usually used for retrieving the bus stop information by phone.

route_id

The bus route number. Use integers only -- 'X' routes should omit the X suffix.

date

A DateTime object

Return hashref contains:

stop_number

4-digit OC Transpo stop number

stop_name

Name of stop, or 'unknown' if not found

route_number

1 to 3 digit OC Transpo route number

route_name

Name of route, or 'unknown' if not found

times

Reference to array of scalars representing stop times in local Ottawa time. Time values will be in one of two formats: HH:MM for plain times with no modifier, and HH:MM (X) where X is the identifier of a route note mentioned in the notes section of the returned data.

notes

Reference to hash, containing note_identifier => note.

This method will die if the stop is not found, the route is not found, as well as on any WWW::Mechanize or HTML::Form errors that might be thrown.

DEPENDENCIES

WWW::Mechanize, HTML::Form::ForceValue, HTML::TableExtract, HTTP::Status, DateTime

INCOMPATIBILITIES

There are no known incompatibilities with this module, but they probably do exist.

BUGS AND LIMITATIONS

Current known issues:

  • If the desired route leaves a stop in more than one direction (ie: Transitway stations) this module will only show the first one found on the page. Some way of specifying direction is needed.

  • Stops must be specified by number, and not by name or nearest intersection, even though the OCTranspo website allows the alternate methods.

  • None of the advanced features (route planner, etc) are supported yet.

  • Should implement shortcuts to specify a weekday, Saturday, or Sunday schedule instead of requiring a DateTime object.

Please report any new problems to the author. Patches are welcome.

AUTHOR

Dave O'Neill (dmo@dmo.ca)

LICENCE AND COPYRIGHT

Copyright (C) 2007 Dave O'Neill

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.