diff --git a/src/de/schildbach/pte/VrnProvider.java b/src/de/schildbach/pte/VrnProvider.java new file mode 100644 index 00000000..908b9702 --- /dev/null +++ b/src/de/schildbach/pte/VrnProvider.java @@ -0,0 +1,93 @@ +/* + * Copyright 2010 the original author or authors. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.schildbach.pte; + +import java.io.IOException; +import java.util.Date; + +/** + * @author Andreas Schildbach + */ +public class VrnProvider extends AbstractEfaProvider +{ + public static final String NETWORK_ID = "fahrplanauskunft.vrn.de"; + private static final String API_BASE = "http://fahrplanauskunft.vrn.de/vrn_mobile/"; + + public boolean hasCapabilities(final Capability... capabilities) + { + for (final Capability capability : capabilities) + if (capability == Capability.DEPARTURES) + return true; + + return false; + } + + @Override + protected String autocompleteUri(CharSequence constraint) + { + throw new UnsupportedOperationException(); + } + + @Override + protected String nearbyLatLonUri(final int lat, final int lon) + { + return null; + } + + private static final String NEARBY_STATION_URI = API_BASE + + "XSLT_DM_REQUEST" + + "?outputFormat=XML&coordOutputFormat=WGS84&name_dm=%s&type_dm=stop&itOptionsActive=1&ptOptionsActive=1&useProxFootSearch=1&mergeDep=1&useAllStops=1&mode=direct&deleteAssignedStop=0"; + + @Override + protected String nearbyStationUri(final String stationId) + { + return String.format(NEARBY_STATION_URI, stationId); + } + + public StationLocationResult stationLocation(String stationId) throws IOException + { + throw new UnsupportedOperationException(); + } + + public String departuresQueryUri(final String stationId, final int maxDepartures) + { + final StringBuilder uri = new StringBuilder(); + uri.append(API_BASE).append("XSLT_DM_REQUEST"); + uri.append("?outputFormat=XML"); + uri.append("&coordOutputFormat=WGS84"); + uri.append("&type_dm=stop"); + uri.append("&name_dm=").append(stationId); + uri.append("&mode=direct"); + return uri.toString(); + } + + public QueryConnectionsResult queryConnections(LocationType fromType, String from, LocationType viaType, String via, LocationType toType, + String to, Date date, boolean dep, WalkSpeed walkSpeed) throws IOException + { + throw new UnsupportedOperationException(); + } + + public QueryConnectionsResult queryMoreConnections(String uri) throws IOException + { + throw new UnsupportedOperationException(); + } + + public GetConnectionDetailsResult getConnectionDetails(String connectionUri) throws IOException + { + throw new UnsupportedOperationException(); + } +} diff --git a/test/de/schildbach/pte/live/VrnProviderLiveTest.java b/test/de/schildbach/pte/live/VrnProviderLiveTest.java new file mode 100644 index 00000000..bc8721fa --- /dev/null +++ b/test/de/schildbach/pte/live/VrnProviderLiveTest.java @@ -0,0 +1,49 @@ +/* + * Copyright 2010 the original author or authors. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.schildbach.pte.live; + +import java.util.List; + +import org.junit.Test; + +import de.schildbach.pte.QueryDeparturesResult; +import de.schildbach.pte.Station; +import de.schildbach.pte.VrnProvider; + +/** + * @author Andreas Schildbach + */ +public class VrnProviderLiveTest +{ + private final VrnProvider provider = new VrnProvider(); + + @Test + public void nearbyStation() throws Exception + { + final List results = provider.nearbyStations("6032236", 0, 0, 0, 0); + + System.out.println(results.size() + " " + results); + } + + @Test + public void departures() throws Exception + { + final QueryDeparturesResult result = provider.queryDepartures(provider.departuresQueryUri("6032236", 0)); + + System.out.println(result.departures.size() + " " + result.departures); + } +}