|
|
@ -36,7 +36,7 @@ public class SteamWebApi { |
|
|
|
//todo mb store in db
|
|
|
|
private final HashMap<Long, SteamData> steamDataCache = new HashMap<>(); |
|
|
|
private final HashMap<String, SteamID> steamIdCache = new HashMap<>(); |
|
|
|
private static final int cache_lifetime = 60 * 60 * 24; |
|
|
|
private static final int cache_lifetime = 60 * 60 * 24 * 3; |
|
|
|
|
|
|
|
//mojno bilo sdelat 4erez spring cache no ne hochu
|
|
|
|
public SteamData getSteamData(long steam64) { |
|
|
@ -44,7 +44,7 @@ public class SteamWebApi { |
|
|
|
return steamDataCache.get(steam64); |
|
|
|
} else { |
|
|
|
try { |
|
|
|
SteamData result = this.getSteamDataFromSteam(steam64); |
|
|
|
SteamData result = this.getSteamDataFromSteamTwice(steam64); |
|
|
|
steamDataCache.put(steam64, result); |
|
|
|
return result; |
|
|
|
} catch (Exception e) { |
|
|
@ -53,6 +53,23 @@ public class SteamWebApi { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private SteamData getSteamDataFromSteamTwice(long steam64) throws Exception { |
|
|
|
int kd = 3; |
|
|
|
SteamData steamData = null; |
|
|
|
while (kd != 0 && steamData == null) { |
|
|
|
try { |
|
|
|
steamData = getSteamDataFromSteam(steam64); |
|
|
|
if (steamData == null) |
|
|
|
kd--; |
|
|
|
else |
|
|
|
return steamData; |
|
|
|
} catch (Exception e) { |
|
|
|
kd--; |
|
|
|
} |
|
|
|
} |
|
|
|
throw new Exception("cannot fetch steamdata with id:" + steam64); |
|
|
|
} |
|
|
|
|
|
|
|
private SteamData getSteamDataFromSteam(long steam64) throws Exception { |
|
|
|
String url = String.format("https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=%s&steamids=%s", webapi_key, steam64); |
|
|
|
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class); |
|
|
|