mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-19 08:49:58 +00:00
SE: Migrate to Hafas client interface.
This commit is contained in:
parent
9c82857a67
commit
a9ee06de7f
3 changed files with 34 additions and 71 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2010-2015 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
|
||||
|
@ -21,9 +21,6 @@ import java.util.Set;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
import de.schildbach.pte.dto.Line;
|
||||
import de.schildbach.pte.dto.Product;
|
||||
|
||||
import okhttp3.HttpUrl;
|
||||
|
@ -31,23 +28,18 @@ import okhttp3.HttpUrl;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class SeProvider extends AbstractHafasLegacyProvider {
|
||||
public class SeProvider extends AbstractHafasClientInterfaceProvider {
|
||||
private static final HttpUrl API_BASE = HttpUrl.parse("https://reseplanerare.resrobot.se/bin/");
|
||||
// http://samtrafiken.hafas.de/bin/
|
||||
// http://reseplanerare.resrobot.se/bin/
|
||||
// http://api.vasttrafik.se/bin/
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.BUS, Product.REGIONAL_TRAIN, Product.SUBWAY, Product.TRAM, Product.BUS,
|
||||
Product.FERRY, Product.FERRY, Product.REGIONAL_TRAIN, null, null, null };
|
||||
// https://samtrafiken.hafas.de/bin/
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN /* Air */, Product.HIGH_SPEED_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.BUS, Product.SUBURBAN_TRAIN, Product.SUBWAY, Product.TRAM, Product.BUS,
|
||||
Product.FERRY, Product.ON_DEMAND /* Taxi */ };
|
||||
|
||||
public SeProvider() {
|
||||
super(NetworkId.SE, API_BASE, "sn", PRODUCTS_MAP);
|
||||
|
||||
setRequestUrlEncoding(Charsets.UTF_8);
|
||||
setJsonNearbyLocationsEncoding(Charsets.UTF_8);
|
||||
setUseIso8601(true);
|
||||
setStationBoardHasStationTable(false);
|
||||
setStationBoardCanDoEquivs(false);
|
||||
public SeProvider(final String jsonApiAuthorization) {
|
||||
super(NetworkId.SE, API_BASE, PRODUCTS_MAP);
|
||||
setApiVersion("1.14");
|
||||
setApiClient("{\"id\":\"SAMTRAFIKEN\",\"type\":\"AND\"}");
|
||||
setApiAuthorization(jsonApiAuthorization);
|
||||
}
|
||||
|
||||
private static final Pattern P_SPLIT_NAME_PAREN = Pattern.compile("(.*) \\((.{3,}?) kn\\)");
|
||||
|
@ -57,37 +49,19 @@ public class SeProvider extends AbstractHafasLegacyProvider {
|
|||
final Matcher mParen = P_SPLIT_NAME_PAREN.matcher(name);
|
||||
if (mParen.matches())
|
||||
return new String[] { mParen.group(2), mParen.group(1) };
|
||||
|
||||
return super.splitStationName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Product> defaultProducts() {
|
||||
return Product.ALL;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitAddress(final String address) {
|
||||
final Matcher m = P_SPLIT_NAME_LAST_COMMA.matcher(address);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(2), m.group(1) };
|
||||
|
||||
return super.splitStationName(address);
|
||||
}
|
||||
|
||||
private static final Pattern P_NORMALIZE_LINE_BUS = Pattern.compile("Buss\\s*(.*)");
|
||||
private static final Pattern P_NORMALIZE_LINE_SUBWAY = Pattern.compile("Tunnelbana\\s*(.*)");
|
||||
|
||||
@Override
|
||||
protected Line parseLineAndType(final String line) {
|
||||
final Matcher mBus = P_NORMALIZE_LINE_BUS.matcher(line);
|
||||
if (mBus.matches())
|
||||
return newLine(Product.BUS, mBus.group(1), null);
|
||||
|
||||
final Matcher mSubway = P_NORMALIZE_LINE_SUBWAY.matcher(line);
|
||||
if (mSubway.matches())
|
||||
return newLine(Product.SUBWAY, "T" + mSubway.group(1), null);
|
||||
|
||||
return newLine(null, line, null);
|
||||
public Set<Product> defaultProducts() {
|
||||
return Product.ALL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,13 +39,7 @@ import de.schildbach.pte.dto.SuggestLocationsResult;
|
|||
*/
|
||||
public class SeProviderLiveTest extends AbstractProviderLiveTest {
|
||||
public SeProviderLiveTest() {
|
||||
super(new SeProvider());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nearbyStations() throws Exception {
|
||||
final NearbyLocationsResult result = queryNearbyStations(new Location(LocationType.STATION, "7414867"));
|
||||
print(result);
|
||||
super(new SeProvider(secretProperty("se.api_authorization")));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -56,7 +50,7 @@ public class SeProviderLiveTest extends AbstractProviderLiveTest {
|
|||
|
||||
@Test
|
||||
public void queryDepartures() throws Exception {
|
||||
final QueryDeparturesResult result = queryDepartures("7414867", false);
|
||||
final QueryDeparturesResult result = queryDepartures("740017515", false);
|
||||
print(result);
|
||||
}
|
||||
|
||||
|
@ -76,55 +70,49 @@ public class SeProviderLiveTest extends AbstractProviderLiveTest {
|
|||
public void suggestLocationsUmlaut() throws Exception {
|
||||
final SuggestLocationsResult result = suggestLocations("Luleå");
|
||||
print(result);
|
||||
assertThat(result.getLocations(), hasItem(new Location(LocationType.STATION, "740098049")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void suggestLocationsCoverage() throws Exception {
|
||||
final SuggestLocationsResult salzburgResult = suggestLocations("Stockholm");
|
||||
print(salzburgResult);
|
||||
assertThat(salzburgResult.getLocations(), hasItem(new Location(LocationType.STATION, "740098000")));
|
||||
final SuggestLocationsResult result = suggestLocations("Stockholm");
|
||||
print(result);
|
||||
assertThat(result.getLocations(), hasItem(new Location(LocationType.STATION, "740098000")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shortTrip() throws Exception {
|
||||
final QueryTripsResult result = queryTrips(
|
||||
new Location(LocationType.STATION, "740014867", null, "Luleå Airport"), null,
|
||||
new Location(LocationType.STATION, "740098000", null, "STOCKHOLM"), new Date(), true, null);
|
||||
final Location from = new Location(LocationType.STATION, "740014867", null, "Luleå Airport");
|
||||
final Location to = new Location(LocationType.STATION, "740098000", null, "STOCKHOLM");
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
|
||||
if (!result.context.canQueryLater())
|
||||
return;
|
||||
|
||||
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
|
||||
print(laterResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shortStockholmTrip() throws Exception {
|
||||
final QueryTripsResult result = queryTrips(new Location(LocationType.STATION, "740098000", null, "STOCKHOLM"),
|
||||
null, new Location(LocationType.STATION, "740020101", "Stockholm", "Slussen T-bana"), new Date(), true,
|
||||
null);
|
||||
final Location from = new Location(LocationType.STATION, "740098000", null, "STOCKHOLM");
|
||||
final Location to = new Location(LocationType.STATION, "740020101", "Stockholm", "Slussen T-bana");
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
|
||||
if (!result.context.canQueryLater())
|
||||
return;
|
||||
|
||||
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
|
||||
print(laterResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longTrip() throws Exception {
|
||||
final Location from = new Location(LocationType.STATION, "740098086", Point.from1E6(67859847, 20212802), null,
|
||||
"KIRUNA");
|
||||
final Location from = new Location(LocationType.STATION, "740098086", null, "KIRUNA");
|
||||
final Location to = new Location(LocationType.STATION, "740098000", null, "STOCKHOLM");
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
}
|
||||
|
||||
if (!result.context.canQueryLater())
|
||||
return;
|
||||
|
||||
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
|
||||
print(laterResult);
|
||||
@Test
|
||||
public void tripBetweenCoordinates() throws Exception {
|
||||
final Location from = Location.coord(Point.fromDouble(59.3299775, 18.0576622)); // Stockholm Central
|
||||
final Location to = Location.coord(Point.fromDouble(59.3136500, 18.0620848)); // Stockholms södra
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,5 +12,6 @@ svv.api_authorization =
|
|||
vvt.api_authorization =
|
||||
vmobil.api_authorization =
|
||||
vao.api_authorization =
|
||||
se.api_authorization =
|
||||
hsl.usertoken =
|
||||
hsl.passphrase =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue