use of no.stelar7.api.r4j.basic.calling.DataCallBuilder in project L4J8 by stelar7.
the class StatusAPI method getShardStatus.
public PlatformData getShardStatus(RuneterraShard server) {
DataCallBuilder builder = new DataCallBuilder().withEndpoint(URLEndpoint.V1_STATUS_LOR).withPlatform(server);
Map<String, Object> data = new TreeMap<>();
data.put("platform", server);
Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V1_STATUS_LOR, data);
if (chl.isPresent()) {
return (PlatformData) chl.get();
}
try {
PlatformData list = (PlatformData) builder.build();
data.put("value", list);
DataCall.getCacheProvider().store(URLEndpoint.V1_STATUS_LOR, data);
return list;
} catch (ClassCastException e) {
return null;
}
}
use of no.stelar7.api.r4j.basic.calling.DataCallBuilder in project L4J8 by stelar7.
the class ChampionBuilder method getFreeToPlayRotation.
public ChampionRotationInfo getFreeToPlayRotation() {
if (this.platform == LeagueShard.UNKNOWN) {
return null;
}
DataCallBuilder builder = new DataCallBuilder().withEndpoint(URLEndpoint.V3_CHAMPION_ROTATIONS).withPlatform(this.platform);
Map<String, Object> data = new TreeMap<>();
data.put("platform", this.platform);
Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V3_CHAMPION_ROTATIONS, data);
if (chl.isPresent()) {
return (ChampionRotationInfo) chl.get();
}
try {
ChampionRotationInfo cl = (ChampionRotationInfo) builder.build();
data.put("value", cl);
DataCall.getCacheProvider().store(URLEndpoint.V3_CHAMPION_ROTATIONS, data);
return cl;
} catch (ClassCastException e) {
return null;
}
}
use of no.stelar7.api.r4j.basic.calling.DataCallBuilder in project L4J8 by stelar7.
the class ChampionAPI method getFreeToPlayRotation.
public ChampionRotationInfo getFreeToPlayRotation(LeagueShard server) {
DataCallBuilder builder = new DataCallBuilder().withEndpoint(URLEndpoint.V3_CHAMPION_ROTATIONS).withPlatform(server);
Map<String, Object> data = new TreeMap<>();
data.put("platform", server);
Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V3_CHAMPION_ROTATIONS, data);
if (chl.isPresent()) {
return (ChampionRotationInfo) chl.get();
}
try {
ChampionRotationInfo cl = (ChampionRotationInfo) builder.build();
data.put("value", cl);
DataCall.getCacheProvider().store(URLEndpoint.V3_CHAMPION_ROTATIONS, data);
return cl;
} catch (ClassCastException e) {
return null;
}
}
use of no.stelar7.api.r4j.basic.calling.DataCallBuilder in project L4J8 by stelar7.
the class ChampionMasteryBuilder method getChampionMastery.
public ChampionMastery getChampionMastery() {
if (this.championId == null || this.summonerId == null || this.platform == Platform.UNKNOWN) {
return null;
}
DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, String.valueOf(this.summonerId)).withURLParameter(Constants.CHAMPION_ID_PLACEHOLDER, String.valueOf(this.championId)).withEndpoint(URLEndpoint.V3_MASTERY_BY_CHAMPION).withPlatform(this.platform);
Optional chl = DataCall.getCacheProvider().get(URLEndpoint.V3_MASTERY_BY_CHAMPION, this.platform, this.summonerId, this.championId);
if (chl.isPresent()) {
return (ChampionMastery) chl.get();
}
Object masterObj = builder.build();
if (masterObj instanceof Pair) {
try {
ChampionMastery mastery = new ChampionMastery();
Field player = mastery.getClass().getDeclaredField("playerId");
player.setAccessible(true);
player.set(mastery, this.summonerId);
Field champ = mastery.getClass().getDeclaredField("championId");
champ.setAccessible(true);
champ.set(mastery, this.championId);
Field level = mastery.getClass().getDeclaredField("championLevel");
level.setAccessible(true);
level.set(mastery, 0);
DataCall.getCacheProvider().store(URLEndpoint.V3_MASTERY_BY_CHAMPION, mastery, this.platform, this.summonerId, this.championId);
return mastery;
} catch (NoSuchFieldException | IllegalAccessException e) {
Logger.getGlobal().warning("Class has changed, please fix me");
}
}
DataCall.getCacheProvider().store(URLEndpoint.V3_MASTERY_BY_CHAMPION, masterObj, this.platform, this.summonerId, this.championId);
return (ChampionMastery) masterObj;
}
use of no.stelar7.api.r4j.basic.calling.DataCallBuilder in project L4J8 by stelar7.
the class MatchBuilder method get.
/**
* Gets a match based on the parameters passed to the builder.
* Matches older than 3 years will return null
*
* @return Match
*/
public Match get() {
if (this.id < 0 || this.platform == Platform.UNKNOWN) {
return null;
}
DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.MATCH_ID_PLACEHOLDER, String.valueOf(this.id)).withEndpoint(URLEndpoint.V3_MATCH).withPlatform(this.platform);
Optional chl = DataCall.getCacheProvider().get(URLEndpoint.V3_MATCH, this.platform, this.id);
if (chl.isPresent()) {
return (Match) chl.get();
}
Object matchObj = builder.build();
if (matchObj instanceof Pair) {
return null;
}
Match match = (Match) matchObj;
DataCall.getCacheProvider().store(URLEndpoint.V3_MATCH, match, this.platform, this.id);
return match;
}
Aggregations