mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-17 04:49:50 +00:00
DSB: Migrate to Hafas client interface.
This commit is contained in:
parent
db7b4c8a0d
commit
ec05c0a519
3 changed files with 26 additions and 89 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2010-2017 the original author or authors.
|
||||
* Copyright 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
|
||||
|
@ -19,7 +19,6 @@ package de.schildbach.pte;
|
|||
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import de.schildbach.pte.dto.Product;
|
||||
|
||||
|
@ -28,18 +27,18 @@ import okhttp3.HttpUrl;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class DsbProvider extends AbstractHafasLegacyProvider {
|
||||
private static final HttpUrl API_BASE = HttpUrl.parse("https://www.rejseplanen.dk/bin/");
|
||||
// http://dk.hafas.de/bin/fat/
|
||||
// http://www.dsb.dk/Rejseplan/bin/
|
||||
public class DsbProvider extends AbstractHafasClientInterfaceProvider {
|
||||
private static final HttpUrl API_BASE = HttpUrl.parse("http://mobilapps.rejseplanen.dk/bin/");
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN, Product.BUS, Product.BUS,
|
||||
Product.BUS, Product.BUS, Product.FERRY, Product.SUBWAY };
|
||||
Product.BUS, Product.BUS, Product.FERRY, Product.SUBWAY, Product.SUBURBAN_TRAIN /* Light Rail */ };
|
||||
|
||||
public DsbProvider() {
|
||||
super(NetworkId.DSB, API_BASE, "mn", PRODUCTS_MAP);
|
||||
|
||||
setStationBoardHasStationTable(false);
|
||||
public DsbProvider(final String apiAuthorization) {
|
||||
super(NetworkId.DSB, API_BASE, PRODUCTS_MAP);
|
||||
setApiEndpoint("iphone.exe");
|
||||
setApiVersion("1.14");
|
||||
setApiClient("{\"id\":\"DK\",\"type\":\"AND\"}");
|
||||
setApiAuthorization(apiAuthorization);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -47,7 +46,6 @@ public class DsbProvider extends AbstractHafasLegacyProvider {
|
|||
final Matcher m = P_SPLIT_NAME_PAREN.matcher(name);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(2), m.group(1) };
|
||||
|
||||
return super.splitStationName(name);
|
||||
}
|
||||
|
||||
|
@ -55,70 +53,4 @@ public class DsbProvider extends AbstractHafasLegacyProvider {
|
|||
public Set<Product> defaultProducts() {
|
||||
return Product.ALL;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Product normalizeType(final String type) {
|
||||
final String ucType = type.toUpperCase();
|
||||
|
||||
if ("ICL".equals(ucType))
|
||||
return Product.HIGH_SPEED_TRAIN;
|
||||
if ("IB".equals(ucType))
|
||||
return Product.HIGH_SPEED_TRAIN;
|
||||
if ("SJ".equals(ucType))
|
||||
return Product.HIGH_SPEED_TRAIN;
|
||||
|
||||
if ("ØR".equals(ucType))
|
||||
return Product.REGIONAL_TRAIN;
|
||||
if ("RA".equals(ucType))
|
||||
return Product.REGIONAL_TRAIN;
|
||||
if ("RX".equals(ucType))
|
||||
return Product.REGIONAL_TRAIN;
|
||||
if ("PP".equals(ucType))
|
||||
return Product.REGIONAL_TRAIN;
|
||||
if ("L".equals(ucType)) // Lokalbane
|
||||
return Product.REGIONAL_TRAIN;
|
||||
if ("PÅGATOG".equals(ucType))
|
||||
return Product.REGIONAL_TRAIN;
|
||||
|
||||
if ("S-TOG".equals(ucType))
|
||||
return Product.SUBURBAN_TRAIN;
|
||||
|
||||
if ("BYBUS".equals(ucType))
|
||||
return Product.BUS;
|
||||
if ("X-BUS".equals(ucType) || "X BUS".equals(ucType))
|
||||
return Product.BUS;
|
||||
if ("HV-BUS".equals(ucType)) // Havnebus
|
||||
return Product.BUS;
|
||||
if ("T-BUS".equals(ucType)) // Togbus
|
||||
return Product.BUS;
|
||||
if ("TOGBUS".equals(ucType))
|
||||
return Product.BUS;
|
||||
if ("FLEXBUS".equals(ucType))
|
||||
return Product.BUS;
|
||||
if ("FJERNBUS".equals(ucType))
|
||||
return Product.BUS;
|
||||
|
||||
if ("TELEBUS".equals(ucType))
|
||||
return Product.ON_DEMAND;
|
||||
if ("TELETAXI".equals(ucType))
|
||||
return Product.ON_DEMAND;
|
||||
|
||||
if ("FÆRGE".equals(ucType))
|
||||
return Product.FERRY;
|
||||
|
||||
return super.normalizeType(type);
|
||||
}
|
||||
|
||||
// Busses line name is formatted as "42#Bus 42" but we just want "42"
|
||||
private static final Pattern P_NORMALIZE_LINE_NAME_BUS_DSB = Pattern.compile(".*?#Bus (.*)",
|
||||
Pattern.CASE_INSENSITIVE);
|
||||
|
||||
@Override
|
||||
protected String normalizeLineName(final String lineName) {
|
||||
final Matcher mBus = P_NORMALIZE_LINE_NAME_BUS_DSB.matcher(lineName);
|
||||
if (mBus.matches())
|
||||
return mBus.group(1);
|
||||
|
||||
return super.normalizeLineName(lineName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import de.schildbach.pte.DsbProvider;
|
|||
import de.schildbach.pte.dto.Location;
|
||||
import de.schildbach.pte.dto.LocationType;
|
||||
import de.schildbach.pte.dto.NearbyLocationsResult;
|
||||
import de.schildbach.pte.dto.Point;
|
||||
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||
import de.schildbach.pte.dto.QueryTripsResult;
|
||||
import de.schildbach.pte.dto.SuggestLocationsResult;
|
||||
|
@ -36,13 +37,7 @@ import de.schildbach.pte.dto.SuggestLocationsResult;
|
|||
*/
|
||||
public class DsbProviderLiveTest extends AbstractProviderLiveTest {
|
||||
public DsbProviderLiveTest() {
|
||||
super(new DsbProvider());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nearbyStations() throws Exception {
|
||||
final NearbyLocationsResult result = queryNearbyStations(new Location(LocationType.STATION, "8600858"));
|
||||
print(result);
|
||||
super(new DsbProvider(secretProperty("dsb.api_authorization")));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -53,7 +48,7 @@ public class DsbProviderLiveTest extends AbstractProviderLiveTest {
|
|||
|
||||
@Test
|
||||
public void queryDepartures() throws Exception {
|
||||
final QueryDeparturesResult result = queryDepartures("8600858", false);
|
||||
final QueryDeparturesResult result = queryDepartures("860430302", false);
|
||||
print(result);
|
||||
}
|
||||
|
||||
|
@ -71,11 +66,20 @@ public class DsbProviderLiveTest extends AbstractProviderLiveTest {
|
|||
|
||||
@Test
|
||||
public void shortTrip() throws Exception {
|
||||
final QueryTripsResult result = queryTrips(
|
||||
new Location(LocationType.STATION, "900000011", null, "Copenhagen Airport"), null,
|
||||
new Location(LocationType.POI, "551922500", null, "Billund Airport"), new Date(), true, null);
|
||||
final Location from = new Location(LocationType.STATION, "900000011", null, "Copenhagen Airport");
|
||||
final Location to = new Location(LocationType.POI, "551922500", null, "Billund Airport");
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
|
||||
print(laterResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tripBetweenCoordinates() throws Exception {
|
||||
final Location from = Location.coord(Point.fromDouble(55.6724746, 12.5649895)); // Copenhagen Central
|
||||
// Station
|
||||
final Location to = Location.coord(Point.fromDouble(55.6650983, 12.5595897)); // Dybbølsbro
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ vvt.api_authorization =
|
|||
vmobil.api_authorization =
|
||||
vao.api_authorization =
|
||||
zvv.api_authorization =
|
||||
dsb.api_authorization =
|
||||
se.api_authorization =
|
||||
hsl.usertoken =
|
||||
hsl.passphrase =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue