A wrapper for the iRail API for Java programming languages
Java
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/be/irail
tests/be/irail/api/test
.gitignore
README

README

This is the official Java wrapper for the iRail API.

USAGE
------

1. Download the .jar at https://github.com/downloads/iRail/iRailForJ/iRailForJ.jar
2. copy iRailForJ jar file in your project


Example: construct an IRail instance connecting to the dev API, with language set to dutch.
		 get connections from LIEDEKERKE to BRUSSELS CENTRAL stations.
		 list departure and arrival for each, skipping non-direct connections.
         formatted a la NMBS.

---cut here---

public class IRailExample
{
    public static final String TEST_URL="http://api.irail.be";

    public static void main(String[] argv) throws Exception
    {
        IRail       iRail       =new IRail(TEST_URL,"nl");
        Calendar    cal         =Calendar.getInstance();
        
        List<Connection> connections = iRail.getConnections("LIEDEKERKE","BRUSSEL CENTRAAL");
        for(Connection connection : connections)
        {
            // skip connections that have transfers, to keep this example simple
            if(connection.hasVias())        
                continue;

           TripNode departure=connection.getDeparture();
           TripNode arrival  =connection.getArrival();

           cal.setTime(departure.getTime());
           System.out.printf("DEPARTURE [%2d:%02d %-22s %-3s %2s +%02dH%02d] -> ",
                    cal.get(Calendar.HOUR_OF_DAY),
                    cal.get(Calendar.MINUTE),
                    departure.getStation().getName(),
                    departure.getVehicle().getType(),
                    departure.getPlatform(),
                    (departure.getDelay()/60)/60,
                    (departure.getDelay()/60)%60);

            cal.setTime(arrival.getTime());
            System.out.printf("ARRIVAL [%2d:%02d %-22s %-3s %2s]\n",
                    cal.get(Calendar.HOUR_OF_DAY),
                    cal.get(Calendar.MINUTE),
                    arrival.getStation().getName(),
                    arrival.getVehicle().getType(),
                    arrival.getPlatform());

        }
    }
}

---cut here---

output example:

DEPARTURE [20:47 LIEDEKERKE             IC   3 +00H10] -> ARRIVAL [21:11 BRUSSEL CENTRAAL       IC   1]
DEPARTURE [21:17 LIEDEKERKE             IR   3 +00H00] -> ARRIVAL [21:39 BRUSSEL CENTRAAL       IR   3]
DEPARTURE [21:19 LIEDEKERKE             CR   1 +00H00] -> ARRIVAL [21:55 BRUSSEL CENTRAAL       CR   2]
DEPARTURE [21:47 LIEDEKERKE             IC   3 +00H00] -> ARRIVAL [22:16 BRUSSEL CENTRAAL       IC   1]
DEPARTURE [22:17 LIEDEKERKE             IR   3 +00H00] -> ARRIVAL [22:39 BRUSSEL CENTRAAL       IR   3]


LINKS
------

http://project.iRail.be
http://iRail.be


LICENSE
---------

The Code is released under GPL v3. This means you can take this code, and put it into your project.
Your project however should be licensed under a GPL v3 compatible license.

Author: Pieter Colpaert <pieter[aŧ]iRail.be> - http://bonsansnom.wordpress.com