public PGNTournament scanTournament(String tournamentId) throws ChessHogScannerException {
String decodeTournament = decodeUrlByRegex(
assignUrl(tournamentId, null),
- getSettings().getTournamentGamesUrlRegex()
+ getSettings().getTournamentJsonUrlRegex()
);
TournamentFormat tournamentFormat = Format.formatTournament(decodeTournament);
@Override
public PGNGame scanGame(String gameId, String tournamentId) throws ChessHogScannerException {
- String decodeGame = decodeUrlByRegex(
+ return scanGameByRegex(
assignUrl(gameId, tournamentId, true),
- getSettings().getGameUrlRegex()
+ getSettings().getGameJsonUrlRegex()
+ );
+ }
+
+ @Override
+ public PGNGame scanUrl(String gameUrl) throws ChessHogScannerException {
+ return scanGameByRegex(
+ gameUrl,
+ getSettings().getGameJsonUrlRegex()
+ );
+ }
+
+ private PGNGame scanGameByRegex(String gameUrl, String regex) throws ChessHogScannerException {
+ String decodeGame = decodeUrlByRegex(
+ gameUrl,
+ regex
);
GameFormat gameFormat = Format.formatGame(decodeGame);
);
}
- @Override
- public PGNGame scanUrl(String gameUrl) throws ChessHogScannerException {
- return null;
- }
private String decodeUrlByRegex(String url, String regex) throws ChessHogScannerException {
String encodeString = match(
url,
regex
);
+ if (encodeString == null) {
+ throw new ChessHogScannerException(
+ String.format("Failed to decode source data for requesting URL: %s", url)
+ );
+ }
return new String(
- Base64.getDecoder().decode(encodeString)
+ Base64.getDecoder().decode(
+ encodeString
+ )
);
}