/
example.txt
146 lines (121 loc) · 5.8 KB
/
example.txt
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import be.irail.api.IRailAPI;
import be.irail.api.core.LanguageCode;
import be.irail.api.data.liveboard.Liveboard;
import be.irail.api.data.liveboard.LiveboardDeparture;
import be.irail.api.data.scheduler.DateTimeIndicator;
import be.irail.api.data.scheduler.IRConnection;
import be.irail.api.data.stations.IRStation;
import be.irail.api.data.stations.IRStationFilterType;
import be.irail.api.data.stations.IRStationListFilter;
import be.irail.api.data.vehicle.IRVehicleInformation;
import be.irail.api.data.vehicle.VehicleStop;
import be.irail.api.event.IRailErrorEvent;
import be.irail.api.event.IRailResult;
import be.irail.api.event.IRailResultEvent;
private var _irail:IRailAPI;
private function init():void {
_irail = new IRailAPI();
_irail.stations.addEventListener(IRailErrorEvent.IO_ERROR, handeIRailIOError);
_irail.scheduler.addEventListener(IRailErrorEvent.IO_ERROR, handeIRailIOError);
_irail.liveboards.addEventListener(IRailErrorEvent.IO_ERROR, handeIRailIOError);
_irail.vehicles.addEventListener(IRailErrorEvent.IO_ERROR, handeIRailIOError);
//Activate one of these methods to test it
//getAllStations();
//getLiveBoardInfo();
//getAllStationsFiltered();
//getRoute();
//getLiveBoardInfo();
//getVehicleInfo();
}
// ----------------------------------------
// Station list
// ----------------------------------------
private function getAllStations():void {
_irail.stations.getAllStations();
_irail.stations.addEventListener(IRailResultEvent.STATION_LIST_RESULT, onAllStationsResult);
}
private function getAllStationsFiltered():void {
var filter1:IRStationListFilter = new IRStationListFilter(IRStationFilterType.COUNTRY, "belgium");
var filter2:IRStationListFilter = new IRStationListFilter(IRStationFilterType.TYPE_OF_TRANSPORT, "train");
_irail.stations.getFilteredStationList([filter1, filter2]);
_irail.stations.addEventListener(IRailResultEvent.STATION_LIST_RESULT, onAllStationsResult);
}
private function onAllStationsResult(event:IRailResultEvent):void {
_irail.stations.removeEventListener(IRailResultEvent.STATION_LIST_RESULT, onAllStationsResult);
var result:IRailResult = event.result;
//traces the name of every station
for each (var train:IRStation in result.data) {
trace(train.formattedName + " (" + train.longitude + "," + train.latitude + ")");
}
}
// ----------------------------------------
// Scheduler
// ----------------------------------------
private function getRoute():void {
_irail.scheduler.getRoutes(new IRStation("TORHOUT"), new IRStation("GENK"), new Date(), true, DateTimeIndicator.DEPARTURE, ["train"], 4, LanguageCode.DUTCH);
_irail.scheduler.addEventListener(IRailResultEvent.SCHEDULER_RESULT, onSchedulerResult);
}
private function onSchedulerResult(event:IRailResultEvent):void {
_irail.scheduler.removeEventListener(IRailResultEvent.SCHEDULER_RESULT, onSchedulerResult);
var result:IRailResult = event.result;
for each (var connection:IRConnection in result.data) {
trace("DEPARTURE::\n" +
"date: " + connection.departure.dateTime + "\n",
"station: " + connection.departure.station.name + "\n",
"duration: " + connection.duration + " seconds\n",
"delay: " + connection.isDelayed + "\n",
"ARRIVAL::\n" +
"via: " + connection.vias.length + " stations\n" +
"date: " + connection.arrival.dateTime + "\n",
"platform: " + connection.arrival.platform.platformNo + "\n",
"station: " + connection.arrival.station.name + "\n");
trace("--------------");
}
trace("Number of results: " + result.data.length);
}
// ----------------------------------------
// Liveboard
// ----------------------------------------
private function getLiveBoardInfo():void {
_irail.liveboards.getStationLiveboardByStationName("Brussel-Zuid", new Date(), true);
_irail.liveboards.addEventListener(IRailResultEvent.LIVEBOARD_RESULT, onLiveboardResult);
}
private function onLiveboardResult(event:IRailResultEvent):void {
_irail.liveboards.removeEventListener(IRailResultEvent.LIVEBOARD_RESULT, onLiveboardResult);
var result:IRailResult = event.result;
var lb:Liveboard = result.data as Liveboard;
trace("Liveboard for station: " + lb.station.formattedName);
trace("Departures:");
for each (var departure:LiveboardDeparture in lb.departures) {
trace("Departure no. " + departure.id);
trace("Destination: " + departure.station.formattedName);
trace("Departing at " + departure.dateTime.toDateString() + " " + departure.dateTime.toTimeString());
trace("with " + departure.delay + " seconds of delay");
trace("at platform " + departure.platform.platformNo);
trace("with train " + departure.vehicle.vehicleCode);
trace("")
}
}
// ----------------------------------------
// Vehicle information
// ----------------------------------------
private function getVehicleInfo():void {
_irail.vehicles.getVehicleInformationByVehicleCode("BE.NMBS.IC545");
_irail.vehicles.addEventListener(IRailResultEvent.VEHICLE_INFO_RESULT, onVehicleResult);
}
private function onVehicleResult(event:IRailResultEvent):void {
_irail.vehicles.removeEventListener(IRailResultEvent.VEHICLE_INFO_RESULT, onVehicleResult);
var vehiculeInfo:IRVehicleInformation = event.result.data as IRVehicleInformation;
trace("Information retrieved for vehicule: " + vehiculeInfo.vehicle.vehicleCode);
trace("This vehicle will stop at following stations:")
for each (var stop:VehicleStop in vehiculeInfo.stops) {
trace("Stop " + (stop.id + 1) + ":");
trace("Station: " + stop.station.formattedName);
trace(stop.dateTime.toDateString(), "at " + stop.dateTime.toTimeString());
trace("with a delay of " + stop.delay + " seconds");
}
}
private function handeIRailIOError(event:IRailErrorEvent):void {
//EUH OH, could not connect to the server
trace("ERROR! ", event.text)
}