diff --git a/src/main/java/de/jeyp91/App.java b/src/main/java/de/jeyp91/App.java index 86ec894..e8f0fae 100644 --- a/src/main/java/de/jeyp91/App.java +++ b/src/main/java/de/jeyp91/App.java @@ -51,6 +51,7 @@ public class App { case "APIFootballUpdater": APIFootballUpdater apiFootballUpdater = new APIFootballUpdater(); apiFootballUpdater.updateAllFixtures(); + apiFootballUpdater.updateAllRounds(); break; case "MatchesListGistUpdater": MatchesListForumUpdater matchesListForumUpdater = new MatchesListForumUpdater(); diff --git a/src/main/java/de/jeyp91/apifootball/APIFootballConnector.java b/src/main/java/de/jeyp91/apifootball/APIFootballConnector.java index 69e2346..41fcebf 100644 --- a/src/main/java/de/jeyp91/apifootball/APIFootballConnector.java +++ b/src/main/java/de/jeyp91/apifootball/APIFootballConnector.java @@ -80,7 +80,7 @@ public class APIFootballConnector { return this.rounds.get(leagueId); } - public JSONObject getTeamsForLeague(int league) { + public JSONObject getTeamsForLeague(int league) throws Exception { String url = "https://v2.api-football.com/teams/league/" + league; String content = new APIFootballUpdater().getRawData(url); return stringToJSONObject(content); diff --git a/src/main/java/de/jeyp91/apifootball/APIFootballUpdater.java b/src/main/java/de/jeyp91/apifootball/APIFootballUpdater.java index 74405ef..801d660 100644 --- a/src/main/java/de/jeyp91/apifootball/APIFootballUpdater.java +++ b/src/main/java/de/jeyp91/apifootball/APIFootballUpdater.java @@ -15,12 +15,13 @@ import java.util.HashSet; public class APIFootballUpdater { private final String exceededLimitError = "{\"api\":{\"results\":0,\"error\":\"You have reached the request limit for the day\"}}"; + private final String wrongEndpointError = "{\"api\":{\"results\":0,\"error\":\"This endpoint does not exist or your parameters are incorrect, contact our support.\"}}"; public APIFootballUpdater() { } - public void updateFixtures(int league) { + public void updateFixtures(int league) throws Exception { String apiFootballUrl = "https://v2.api-football.com/fixtures/league/" + league + "?timezone=Europe/Berlin"; String content = getRawData(apiFootballUrl); if(!content.equals(this.exceededLimitError)) { @@ -29,21 +30,21 @@ public class APIFootballUpdater { } } - public void updateAllFixtures() { + public void updateAllFixtures() throws Exception { HashSet leagues = getLeagues(); for (Integer league : leagues) { updateFixtures(league); } } - public void updateAllRounds() { + public void updateAllRounds() throws Exception { HashSet leagues = getLeagues(); for (Integer league : leagues) { updateRounds(league); } } - public void updateRounds(int league) { + public void updateRounds(int league) throws Exception { String apiFootballUrl = "https://v2.api-football.com/fixtures/rounds/" + league; String content = getRawData(apiFootballUrl); if(!content.equals(this.exceededLimitError)) { @@ -52,7 +53,7 @@ public class APIFootballUpdater { } } - public String getRawData(String requestUrl) { + public String getRawData(String requestUrl) throws Exception { HttpClient client = HttpClientBuilder.create().build(); HttpGet request = new HttpGet(requestUrl); @@ -94,6 +95,9 @@ public class APIFootballUpdater { result.append(line); } + if (result.toString().equals(wrongEndpointError)) { + throw new Exception(requestUrl + " gave error:" + wrongEndpointError); + } return result.toString(); } diff --git a/src/main/java/de/jeyp91/teamidmatcher/TeamIDMatcherTemplateCreator.java b/src/main/java/de/jeyp91/teamidmatcher/TeamIDMatcherTemplateCreator.java index 4cba5d0..fe9ddaa 100644 --- a/src/main/java/de/jeyp91/teamidmatcher/TeamIDMatcherTemplateCreator.java +++ b/src/main/java/de/jeyp91/teamidmatcher/TeamIDMatcherTemplateCreator.java @@ -8,7 +8,7 @@ public class TeamIDMatcherTemplateCreator { APIFootballConnector con; JSONArray teams; - public TeamIDMatcherTemplateCreator(int season, int league) { + public TeamIDMatcherTemplateCreator(int season, int league) throws Exception { this.con = APIFootballConnector.getAPIFootballConnectorInstance(season); JSONObject apiObject = con.getTeamsForLeague(league); JSONObject teamsObject = (JSONObject) apiObject.get("api"); diff --git a/src/test/java/de/jeyp91/apifootball/APIFootballUpdaterTest.java b/src/test/java/de/jeyp91/apifootball/APIFootballUpdaterTest.java index 77c5ce0..b28d84b 100644 --- a/src/test/java/de/jeyp91/apifootball/APIFootballUpdaterTest.java +++ b/src/test/java/de/jeyp91/apifootball/APIFootballUpdaterTest.java @@ -5,19 +5,19 @@ import org.junit.Test; public class APIFootballUpdaterTest { @Test - public void updateFixturesTest() { + public void updateFixturesTest() throws Exception { APIFootballUpdater updater = new APIFootballUpdater(); -// updater.updateFixtures(1240); + updater.updateFixtures(1240); } @Test - public void updateAllFixturesTest() { + public void updateAllFixturesTest() throws Exception { APIFootballUpdater updater = new APIFootballUpdater(); // updater.updateAllFixtures(); } @Test - public void updateAllRoundsTest() { + public void updateAllRoundsTest() throws Exception { APIFootballUpdater updater = new APIFootballUpdater(); // updater.updateAllRounds(); }