Search in sources :

Example 6 with DataCallBuilder

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;
    }
}
Also used : Summoner(no.stelar7.api.l4j8.pojo.summoner.Summoner) Optional(java.util.Optional)

Example 7 with DataCallBuilder

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;
    }
}
Also used : Summoner(no.stelar7.api.l4j8.pojo.summoner.Summoner) Optional(java.util.Optional)

Example 8 with DataCallBuilder

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();
}
Also used : DataCallBuilder(no.stelar7.api.r4j.basic.calling.DataCallBuilder)

Example 9 with DataCallBuilder

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();
}
Also used : DataCallBuilder(no.stelar7.api.r4j.basic.calling.DataCallBuilder) JsonWriter(com.google.gson.stream.JsonWriter)

Example 10 with DataCallBuilder

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;
}
Also used : Field(java.lang.reflect.Field) ChampionMastery(no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery) Pair(no.stelar7.api.r4j.basic.utils.Pair)

Aggregations

DataCallBuilder (no.stelar7.api.r4j.basic.calling.DataCallBuilder)11 Optional (java.util.Optional)7 JsonWriter (com.google.gson.stream.JsonWriter)6 Field (java.lang.reflect.Field)4 Summoner (no.stelar7.api.l4j8.pojo.summoner.Summoner)4 Pair (no.stelar7.api.r4j.basic.utils.Pair)4 Summoner (no.stelar7.api.r4j.pojo.lol.summoner.Summoner)4 GAMHSMatch (no.stelar7.api.r4j.pojo.shared.GAMHSMatch)4 Pair (no.stelar7.api.l4j8.basic.utils.Pair)3 PlatformData (no.stelar7.api.r4j.pojo.lol.status.PlatformData)3 ChampionMastery (no.stelar7.api.l4j8.pojo.championmastery.ChampionMastery)2 APIResponseException (no.stelar7.api.r4j.basic.exceptions.APIResponseException)2 ChampionRotationInfo (no.stelar7.api.r4j.pojo.lol.champion.ChampionRotationInfo)2 ChampionMastery (no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery)2 Match (no.stelar7.api.l4j8.pojo.match.Match)1 MatchTimeline (no.stelar7.api.l4j8.pojo.match.MatchTimeline)1 LanguageStrings (no.stelar7.api.l4j8.pojo.staticdata.language.LanguageStrings)1 Realm (no.stelar7.api.l4j8.pojo.staticdata.realm.Realm)1 ShardStatus (no.stelar7.api.l4j8.pojo.status.ShardStatus)1 LanguageStrings (no.stelar7.api.r4j.pojo.lol.staticdata.language.LanguageStrings)1