use of no.stelar7.api.r4j.basic.utils.Pair in project L4J8 by stelar7.
the class SummonerBuilder method get.
/**
* gets a summoner based on the parameters passed to the builder
*
* @return Summoner
*/
public Summoner get() {
DataCallBuilder builder = new DataCallBuilder().withPlatform(this.platform);
URLEndpoint endpoint = null;
if (accId > 0) {
builder.withURLParameter(Constants.ACCOUNT_ID_PLACEHOLDER, String.valueOf(this.accId));
endpoint = URLEndpoint.V3_SUMMONER_BY_ACCOUNT;
}
if (sumId > 0) {
builder.withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, String.valueOf(this.sumId));
endpoint = URLEndpoint.V3_SUMMONER_BY_ID;
}
if (name.length() > 0) {
builder.withURLParameter(Constants.SUMMONER_NAME_PLACEHOLDER, Utils.normalizeSummonerName(this.name));
endpoint = URLEndpoint.V3_SUMMONER_BY_NAME;
}
builder.withEndpoint(endpoint);
Optional chl = DataCall.getCacheProvider().get(endpoint, this.platform, this.accId, this.sumId, this.name);
if (chl.isPresent()) {
return (Summoner) chl.get();
}
Object sob = builder.build();
if (sob instanceof Pair) {
return null;
}
DataCall.getCacheProvider().store(endpoint, sob, this.platform, this.accId, this.sumId, this.name);
return (Summoner) sob;
}
use of no.stelar7.api.r4j.basic.utils.Pair 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.utils.Pair 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.utils.Pair 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.utils.Pair 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