Moved Steam API key to separate class

(and yes, I changed my API key)
This commit is contained in:
Jeddunk 2019-11-26 16:02:11 +01:00
parent 3e203f43b3
commit c65a800515
3 changed files with 24 additions and 2 deletions

1
.gitignore vendored
View File

@ -159,3 +159,4 @@ $RECYCLE.BIN/
/steamapps.json /steamapps.json
/test.json /test.json
/steam_api.md5 /steam_api.md5
/src/main/java/util/env/Default.java

View File

@ -11,6 +11,7 @@ import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
import pojo.App; import pojo.App;
import pojo.SteamAppsList; import pojo.SteamAppsList;
import util.env.MainEnv;
import java.io.*; import java.io.*;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@ -24,11 +25,22 @@ import java.util.stream.Collectors;
public class SteamAppsListCache { public class SteamAppsListCache {
private static final String KEY = "E427256C579D3CDF1D504810E8F5B948";
private SteamAppsList list = new SteamAppsList(); private SteamAppsList list = new SteamAppsList();
private File cacheFile = new File("steamapps.json"); private File cacheFile = new File("steamapps.json");
private MainEnv env;
//private String key;
public SteamAppsListCache() { public SteamAppsListCache() {
try {
Class envDefault = Class.forName("util.env.Default");
env = (MainEnv) envDefault.newInstance();
//System.out.println(env.getKey());
} catch (ClassNotFoundException e) {
env = new MainEnv();
} catch (IllegalAccessException | InstantiationException e) {
// Only thrown by newInstance()
e.printStackTrace();
}
boolean fileFound = true; boolean fileFound = true;
try { try {
getListFromFile(); getListFromFile();
@ -85,7 +97,7 @@ public class SteamAppsListCache {
private List<App> getApps() { private List<App> getApps() {
HttpResponse<String> httpResponse = HttpResponse<String> httpResponse =
Unirest.get("https://api.steampowered.com/IStoreService/GetAppList/v1/" + Unirest.get("https://api.steampowered.com/IStoreService/GetAppList/v1/" +
"?key=" + KEY + "&include_games=1&max_results=50000").asString(); "?key=" + env.getKey() + "&include_games=1&max_results=50000").asString();
return new Gson() return new Gson()
.fromJson(httpResponse.getBody(), App.Rezponze.Download.class) .fromJson(httpResponse.getBody(), App.Rezponze.Download.class)
.getResponse().getApps(); .getResponse().getApps();

9
src/main/java/util/env/MainEnv.java vendored Normal file
View File

@ -0,0 +1,9 @@
package util.env;
public class MainEnv {
String key = "";
public String getKey() {
return key;
}
}