use of no.stelar7.api.r4j.basic.calling.DataCallBuilder in project L4J8 by stelar7.
the class SummonerAPI method getSummonerByAccount.
/**
* The response object contains the summoner objects mapped by their username.
*
* @param server the region to execute against
* @param accountId accountId associated with summoner to retrieve.
* @return Optional Summoner
*/
public Summoner getSummonerByAccount(final Platform server, long accountId) {
DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.ACCOUNT_ID_PLACEHOLDER, String.valueOf(accountId)).withEndpoint(URLEndpoint.V3_SUMMONER_BY_ACCOUNT).withPlatform(server);
Optional chl = DataCall.getCacheProvider().get(URLEndpoint.V3_SUMMONER_BY_ACCOUNT, server, accountId);
if (chl.isPresent()) {
return (Summoner) chl.get();
}
try {
Summoner summoner = (Summoner) builder.build();
DataCall.getCacheProvider().store(URLEndpoint.V3_SUMMONER_BY_ACCOUNT, summoner, server, accountId);
return summoner;
} catch (ClassCastException e) {
return null;
}
}
use of no.stelar7.api.r4j.basic.calling.DataCallBuilder in project L4J8 by stelar7.
the class SummonerAPI method getSummonerById.
/**
* The response object contains the summoner objects mapped by their user id.
*
* @param server the region to execute against
* @param summonerId summonerId associated with summoners to retrieve.
* @return Optional Summoner
*/
public Summoner getSummonerById(final Platform server, long summonerId) {
DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, String.valueOf(summonerId)).withEndpoint(URLEndpoint.V3_SUMMONER_BY_ID).withPlatform(server);
Optional chl = DataCall.getCacheProvider().get(URLEndpoint.V3_SUMMONER_BY_ID, server, "", summonerId);
if (chl.isPresent()) {
return (Summoner) chl.get();
}
try {
Summoner summoner = (Summoner) builder.build();
DataCall.getCacheProvider().store(URLEndpoint.V3_SUMMONER_BY_ID, summoner, server, "", summonerId);
return summoner;
} catch (ClassCastException e) {
return null;
}
}
use of no.stelar7.api.r4j.basic.calling.DataCallBuilder in project L4J8 by stelar7.
the class LCUApi method customUrl.
/**
* Makes a call to a url not specifically supported in the api
*
* @param url the url to call
* @param postData null if not a POST call
* @param method the http method to use
* @return whatever the api returns
*/
public static Object customUrl(String url, String postData, String method) {
Pair<String, String> header = LCUConnection.getAuthorizationHeader();
DataCallBuilder obj = new DataCallBuilder().withLimiters(false).withProxy(LCUConnection.getConnectionString() + url).withPostData(postData).withRequestMethod(method).withHeader(header.getKey(), header.getValue());
return obj.build();
}
use of no.stelar7.api.r4j.basic.calling.DataCallBuilder in project L4J8 by stelar7.
the class LCUApi method setLobbyPositions.
/**
* Sets your roles in the lobby
* @param primary first role
* @param secondary second role
*/
public static void setLobbyPositions(LCULobbyPositionType primary, LCULobbyPositionType secondary) {
Pair<String, String> header = LCUConnection.getAuthorizationHeader();
StringWriter sw = new StringWriter();
try {
JsonWriter jw = new JsonWriter(sw);
jw.beginObject().name("firstPreference").value(primary.name()).name("secondPreference").value(secondary.name()).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_LOBBY_POSITION).withRequestMethod("PUT").withPostData(postData).withHeader(header.getKey(), header.getValue()).build();
}
use of no.stelar7.api.r4j.basic.calling.DataCallBuilder in project L4J8 by stelar7.
the class MasteryAPI method getChampionMastery.
/**
* The response object contains the summoners mastery of a champion.
* Only championid and summonerid is present if the level == 0
*
* @param server the region to execute against
* @param summonerId the summonerId
* @param championId the championId
* @return Optional ChampionMastery
*/
public ChampionMastery getChampionMastery(LeagueShard server, String summonerId, int championId) {
DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, summonerId).withURLParameter(Constants.CHAMPION_ID_PLACEHOLDER, String.valueOf(championId)).withEndpoint(URLEndpoint.V4_MASTERY_BY_CHAMPION).withPlatform(server);
Map<String, Object> data = new TreeMap<>();
data.put("platform", server);
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 masteryObj = builder.build();
if (masteryObj instanceof Pair) {
try {
ChampionMastery mastery = new ChampionMastery();
Field player = mastery.getClass().getDeclaredField("playerId");
player.setAccessible(true);
player.set(mastery, summonerId);
Field champ = mastery.getClass().getDeclaredField("championId");
champ.setAccessible(true);
champ.set(mastery, 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", masteryObj);
DataCall.getCacheProvider().store(URLEndpoint.V4_MASTERY_BY_CHAMPION, data);
return (ChampionMastery) masteryObj;
}
Aggregations