Add check for wrong endpoint for APIFootball
This commit is contained in:
@@ -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<Integer> leagues = getLeagues();
|
||||
for (Integer league : leagues) {
|
||||
updateFixtures(league);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAllRounds() {
|
||||
public void updateAllRounds() throws Exception {
|
||||
HashSet<Integer> 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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user