Remove Gist
This commit is contained in:
@@ -1,29 +1,22 @@
|
||||
package de.jeyp91.apifootball;
|
||||
|
||||
import de.jeyp91.gists.GistProvider;
|
||||
import de.jeyp91.S3Provider;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class APIFootballConnector {
|
||||
|
||||
private static APIFootballConnector conn = null;
|
||||
private final int season;
|
||||
private final String gistId;
|
||||
private final HashMap<String, JSONObject> rounds = new HashMap<>();
|
||||
private final HashMap<String, JSONObject> matches = new HashMap<>();
|
||||
private final HashMap<Integer, JSONObject> rounds = new HashMap<>();
|
||||
private final HashMap<Integer, JSONObject> matches = new HashMap<>();
|
||||
|
||||
private APIFootballConnector(int season) {
|
||||
this.season = season;
|
||||
GistProvider prov = GistProvider.getInstance();
|
||||
this.gistId = prov.getGistID("APIFootball_" + (season + 1));
|
||||
}
|
||||
|
||||
public static APIFootballConnector getAPIFootballConnectorInstance(int season) {
|
||||
@@ -62,14 +55,14 @@ public class APIFootballConnector {
|
||||
return matchesOfMatchday;
|
||||
}
|
||||
|
||||
public ArrayList<APIFootballMatch> getMatchesFromLeagueFromFile(int id) {
|
||||
public ArrayList<APIFootballMatch> getMatchesFromLeagueFromFile(int leagueId) {
|
||||
ArrayList<APIFootballMatch> matchesList = new ArrayList<>();
|
||||
S3Provider prov = new S3Provider();
|
||||
|
||||
String filename = "matches_league_" + id + ".json";
|
||||
if(!this.matches.containsKey(filename)) {
|
||||
this.matches.put(filename, readObjectFromFile(filename));
|
||||
if(!this.matches.containsKey(leagueId)) {
|
||||
this.matches.put(leagueId, prov.getFixturesJSONFromS3(leagueId));
|
||||
}
|
||||
JSONObject matches = this.matches.get(filename);
|
||||
JSONObject matches = this.matches.get(leagueId);
|
||||
JSONArray matchArray = (JSONArray) (((JSONObject)matches.get("api")).get("fixtures"));
|
||||
|
||||
for(int i = 0; i < matchArray.size(); i++) {
|
||||
@@ -79,52 +72,17 @@ public class APIFootballConnector {
|
||||
return matchesList;
|
||||
}
|
||||
|
||||
public JSONObject getMatchdays(int id) {
|
||||
|
||||
String filename = "rounds_" + id + ".json";
|
||||
if(!this.rounds.containsKey(filename)) {
|
||||
this.rounds.put(filename, readObjectFromFile(filename));
|
||||
public JSONObject getMatchdays(int leagueId) {
|
||||
S3Provider prov = new S3Provider();
|
||||
if(!this.rounds.containsKey(leagueId)) {
|
||||
this.rounds.put(leagueId, prov.getRoundsJSONFromS3(leagueId));
|
||||
}
|
||||
return this.rounds.get(filename);
|
||||
}
|
||||
|
||||
public JSONObject readObjectFromFile(String filename) {
|
||||
|
||||
JSONObject object = null;
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
|
||||
GistProvider prov = GistProvider.getInstance();
|
||||
String jsonConfig = prov.getFileFromGist(filename);
|
||||
|
||||
try {
|
||||
object = (JSONObject) jsonParser.parse(jsonConfig);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
public JSONArray readArrayFromFile(String filename) {
|
||||
|
||||
JSONArray object = null;
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
|
||||
GistProvider prov = GistProvider.getInstance();
|
||||
String jsonConfig = prov.getFileFromGist(filename);
|
||||
|
||||
try {
|
||||
object = (JSONArray) jsonParser.parse(jsonConfig);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return object;
|
||||
return this.rounds.get(leagueId);
|
||||
}
|
||||
|
||||
public JSONObject getTeamsForLeague(int league) {
|
||||
String url = "https://v2.api-football.com/teams/league/" + league;
|
||||
String content = new APIFootballUpdater(0).getRawData(url);
|
||||
String content = new APIFootballUpdater().getRawData(url);
|
||||
return stringToJSONObject(content);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user