Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 36 lines (20 sloc) 2.769 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
This CTA class file is an API wrapper for interfacing with the Chicago Transit Authority's three web-based Application Programming Interfaces for Bus, Train ('El') and Alerts related information.

Due to the evolution of the CTA's API interfaces, there are three distinct APIs, one for Bus, Train and Customer Alert information. As a result there are three distinct URI endpoints and two distinct API keys.

This class brings all three APIs together into one object with related methods for accessing Bus, Train and Customer Alert information.

However, there is no requirement that both an Bus and Train API key are needed to use this class file. That is while this class file helps to unify the three distinct APIs together for a PHP developer, this class can also be used to interface with just the Bus, Train or Customer Alert API and nothing else.

More information about the CTA's APIs, including terms of use and how to request API Keys, can be found at: http://www.transitchicago.com/developers/default.aspx

DEPENDENCIES
This class file depends on PHP support of Client URL Library (cURL) and SimpleXML.

PHP's cURL functions are themselves built on libcurl, a library that enables support for a number of different network protocols. Information on how to build and enable cURL support in PHP can be found at: http://php.net/manual/en/book.curl.php

SimpleXML is a PHP extension that provides a simple and easily toolset for managing XML by converting XML data into an object. Similar to cURL, SimpleXML is itself dependent on libxml. Information on how to add SimpleXML can be found at: http://php.net/manual/en/book.simplexml.php


INSTALLATION
To install and use this class and its functions, simply copy the class.cta.php file into a directory that is accessible by your PHP script and include the file using the include (or similar require) function. Example:

// Load the class file in our current directory
include_once( 'class.cta.php' );

Once the class file has been loaded, the next step is to instantiate the class:

$transit = new CTA( 'YOUR-TRAIN-API_KEY_HERE', 'YOUR-BUS-API-KEY-HERE', false );

Note that you will need to provide your own API keys when initializing the object. If no valid API keys are provided the only methods that will return valid information are the Customer Alert based methods for system status information (statusRoutes and statusAlerts) as that specific API does not require an API key.

To invoke a method simple use the object and related function, providing an additional information as parameters:

// Get an array result of all stops for route 81 in going East Bound
$81EastBoundStops = $transit->busGetStops( '81', 'East Bound' ));

Further examples can be found in the provided example.php file.
Something went wrong with that request. Please try again.