use of no.stelar7.api.r4j.basic.calling.DataCallBuilder in project L4J8 by stelar7.
the class DDragonAPI method getRealm.
public Realm getRealm(LeagueShard region) {
DataCallBuilder builder = new DataCallBuilder().withLimiters(false).withProxy(Constants.DDRAGON_PROXY).withURLParameter(Constants.REGION_PLACEHOLDER, region.getRealmValue()).withEndpoint(URLEndpoint.DDRAGON_REALMS);
Map<String, Object> data = new TreeMap<>();
data.put("platform", region);
Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.DDRAGON_REALMS, data);
if (chl.isPresent()) {
return (Realm) chl.get();
}
try {
Realm list = (Realm) builder.build();
data.put("value", list);
DataCall.getCacheProvider().store(URLEndpoint.DDRAGON_REALMS, data);
return list;
} 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 == LeagueShard.UNKNOWN) {
return null;
}
DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, this.summonerId).withURLParameter(Constants.CHAMPION_ID_PLACEHOLDER, String.valueOf(this.championId)).withEndpoint(URLEndpoint.V4_MASTERY_BY_CHAMPION).withPlatform(this.platform);
Map<String, Object> data = new TreeMap<>();
data.put("platform", platform);
data.put("id", summonerId);
data.put("champion", championId);
Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V4_MASTERY_BY_CHAMPION, data);
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);
data.put("value", mastery);
DataCall.getCacheProvider().store(URLEndpoint.V4_MASTERY_BY_CHAMPION, data);
return mastery;
} catch (NoSuchFieldException | IllegalAccessException e) {
Logger.getGlobal().warning("Class has changed, please fix me");
}
}
data.put("value", masterObj);
DataCall.getCacheProvider().store(URLEndpoint.V4_MASTERY_BY_CHAMPION, data);
return (ChampionMastery) masterObj;
}
use of no.stelar7.api.r4j.basic.calling.DataCallBuilder in project L4J8 by stelar7.
the class MatchBuilder method getMatchRAW.
public GAMHSMatch getMatchRAW() {
if (this.id.isEmpty() || this.platform == RegionShard.UNKNOWN) {
return null;
}
DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.MATCH_ID_PLACEHOLDER, this.id).withEndpoint(URLEndpoint.V5_MATCH).withPlatform(this.platform);
Map<String, Object> data = new TreeMap<>();
data.put("platform", this.platform);
data.put("gameid", this.id);
Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V5_MATCH, data);
if (chl.isPresent()) {
return (GAMHSMatch) chl.get();
}
Object matchObj = builder.build();
if (matchObj instanceof Pair) {
return null;
}
GAMHSMatch match = (GAMHSMatch) matchObj;
data.put("value", match);
DataCall.getCacheProvider().store(URLEndpoint.V5_MATCH, data);
return match;
}
use of no.stelar7.api.r4j.basic.calling.DataCallBuilder in project L4J8 by stelar7.
the class LCUApi method createNotification.
/**
* Creates a notification
*
* @param title title of notification
* @param content body of notification
* @param icon icon of notification
* @param background background image of notification
* @param dismissable true if able to dismiss
* @param state read or unread
* @return the notification id
*/
public static int createNotification(String title, String content, String icon, String background, boolean dismissable, String state) {
Pair<String, String> header = LCUConnection.getAuthorizationHeader();
StringWriter sw = new StringWriter();
try {
JsonWriter jw = new JsonWriter(sw);
jw.beginObject().name("backgroundUrl").value(background).name("created").value(LocalDateTime.now().toString()).name("dismissible").value(dismissable).name("detailKey").value("pre_translated_details").name("titleKey").value("pre_translated_title").name("data").beginObject().name("title").value(title).name("content").value(content).endObject().name("iconUrl").value(icon).name("state").value(state).endObject();
} catch (IOException e) {
e.printStackTrace();
}
String postData = sw.toString();
JsonObject obj = (JsonObject) new DataCallBuilder().withLimiters(false).withProxy(LCUConnection.getConnectionString() + Constants.GSVR).withEndpoint(URLEndpoint.LCU_CREATE_NOTIFICATION).withRequestMethod("POST").withPostData(postData).withHeader(header.getKey(), header.getValue()).build();
return obj.get("id").getAsInt();
}
use of no.stelar7.api.r4j.basic.calling.DataCallBuilder in project L4J8 by stelar7.
the class LCUApi method getReplaySavePath.
/**
* Fetches the replay save path
* @return the path
*/
public static String getReplaySavePath() {
Pair<String, String> header = LCUConnection.getAuthorizationHeader();
StringWriter sw = new StringWriter();
String obj = (String) new DataCallBuilder().withLimiters(false).withProxy(LCUConnection.getConnectionString() + Constants.GSVR).withEndpoint(URLEndpoint.LCU_REPLAY_DOWNLOAD_PATH).withRequestMethod("GET").withHeader(header.getKey(), header.getValue()).build();
return obj;
}
Aggregations