Cercanias
Retrieve Renfe's Cercanías[1] information easily., (*1)
[1]: Spain's commuter trains service., (*2)
, (*3)
Requirements
The Cercanias library has the following requirements:, (*4)
Depending on the chosen HttpAdapter, you may need:, (*5)
php5-curl
kriswallsmith/Buzz
Installation
The recommended way to install Cercanias is through Composer., (*6)
Create a composer.json file:, (*7)
``` json
{
"require": {
"rmhdev/cercanias": "0.2.*"
}
}, (*8)
Then install `Composer`:
``` bash
$ curl -sS https://getcomposer.org/installer | php
$ composer install
After that, the autoloader will be available:, (*9)
``` php
<?php
require 'vendor/autoload.php';, (*10)
## How to use it
1. Choose a `HttpAdapter`
2. Choose a `Provider`
3. Create a `Cercanias` object and call `getRoute` or `getTimetable`.
For example, if you want to retrieve all the stations from a route (*San Sebastián*):
``` php
<?php
require 'vendor/autoload.php';
use Cercanias\HttpAdapter\CurlHttpAdapter;
use Cercanias\Provider\HorariosRenfeCom\Provider;
use Cercanias\Cercanias;
$httpAdapter = new CurlHttpAdapter(); // 1. HttpAdapter
$provider = new Provider($httpAdapter); // 2. Provider
$cercanias = new Cercanias($provider); // 3. Cercanias
$route = $cercanias->getRoute(Provider::ROUTE_SAN_SEBASTIAN);
If you want to know all the trips from Brinkola to Irun for tomorrow:, (*11)
``` php
<?php
require 'vendor/autoload.php';, (*12)
use Cercanias\HttpAdapter\CurlHttpAdapter;
use Cercanias\Provider\HorariosRenfeCom\Provider;
use Cercanias\Provider\TimetableQuery;
use Cercanias\Cercanias;, (*13)
$query = new TimetableQuery();
$query
->setRoute(Provider::ROUTE_SAN_SEBASTIAN)
->setDeparture("11305") // from Brinkola
->setDestination("11600") // to Irun
->setDate(new \DateTime("tomorrow"));, (*14)
$httpAdapter = new CurlHttpAdapter(); // 1. HttpAdapter
$provider = new Provider($httpAdapter); // 2. Provider
$cercanias = new Cercanias($provider); // 3. Cercanias
$timetable = $cercanias->getTimetable($query);
```, (*15)
View more examples., (*16)
Basic classes
HttpAdapter
Responsible for making the HTTP connection. Available adapters:, (*17)
-
CurlHttpAdapter: cURL
-
BuzzHttpAdapter: Kris Wallsmith's Buzz HTTP client.
Provider
Indicates where is the information taken. Available providers:, (*18)
Results
-
Route: Information about a specific route.
-
Timetable: Information about trips between stations for a given day.
Other classes
-
Station: information about a station from a Route.
-
Trip: information about a trip from a Timetable.
-
Train: information about departure and arrival time for a train in a Trip.
Changelog
-
0.0.1 (June 21, 2014): initial release.
-
0.0.2 (June 22, 2014): added BuzzHttpAdapter.
-
0.0.3 (June 24, 2014): simplify timetable queries.
-
0.0.4 (June 29, 2014): fix bugs, improve naming and parsing.
-
0.0.5 (July 01, 2014): improve queries generation.
-
0.0.6 (July 06, 2014): add Cercanias class to simplify usage.
-
0.1.0 (July 06, 2014): add library to Packagist.
-
0.2.0 (July 28, 2014): fix a couple of bugs.
Copyright and license
Code and documentation copyright 2014 Rober Martín H.
Code released under MIT license.
Docs released under Creative Commons CC BY 4.0., (*19)
Part of the project is based on William Durand's Geocoder., (*20)
Author
My name is Rober Martín H (@rmhdev). I'm a developer from Donostia / San Sebastián., (*21)