Search in sources :

Example 1 with LeagueShard

use of no.stelar7.api.r4j.basic.constants.api.regions.LeagueShard 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)

Example 2 with LeagueShard

use of no.stelar7.api.r4j.basic.constants.api.regions.LeagueShard in project L4J8 by stelar7.

the class TFTSummonerAPI 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 LeagueShard server, String summonerId) {
    DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, summonerId).withHeader(Constants.X_RIOT_TOKEN_HEADER_KEY, DataCall.getCredentials().getTFTAPIKey()).withEndpoint(URLEndpoint.V1_TFT_SUMMONER_BY_ID).withPlatform(server);
    Map<String, Object> data = new TreeMap<>();
    data.put("platform", server);
    data.put("id", summonerId);
    Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V1_TFT_SUMMONER_BY_ID, data);
    if (chl.isPresent()) {
        return (Summoner) chl.get();
    }
    try {
        Summoner summoner = (Summoner) builder.build();
        data.put("value", summoner);
        DataCall.getCacheProvider().store(URLEndpoint.V1_TFT_SUMMONER_BY_ID, data);
        return summoner;
    } catch (ClassCastException e) {
        return null;
    }
}
Also used : Summoner(no.stelar7.api.r4j.pojo.lol.summoner.Summoner)

Example 3 with LeagueShard

use of no.stelar7.api.r4j.basic.constants.api.regions.LeagueShard 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;
    }
}
Also used : ChampionRotationInfo(no.stelar7.api.r4j.pojo.lol.champion.ChampionRotationInfo)

Example 4 with LeagueShard

use of no.stelar7.api.r4j.basic.constants.api.regions.LeagueShard in project L4J8 by stelar7.

the class RatelimitTest method testRateLimitStatic.

@Test
@Disabled
public void testRateLimitStatic() {
    long start = System.currentTimeMillis();
    LeagueShard plat = LeagueShard.values()[1];
    for (int i = 0; i < 30; i++) {
        r4J.getDDragonAPI().getRealm();
        r4J.getDDragonAPI().getVersions();
        r4J.getDDragonAPI().getLanguages();
        if (i % 9 == 0) {
            plat = LeagueShard.values()[plat.ordinal() + 1];
        }
        System.out.format("call no. %s Total time: %sms%n", i + 1, System.currentTimeMillis() - start);
    }
}
Also used : LeagueShard(no.stelar7.api.r4j.basic.constants.api.regions.LeagueShard)

Example 5 with LeagueShard

use of no.stelar7.api.r4j.basic.constants.api.regions.LeagueShard in project L4J8 by stelar7.

the class DivTests method test.

@Test
public void test() {
    R4J api = new R4J(SecretFile.CREDS);
    String user = "stelar7";
    LeagueShard region = LeagueShard.EUW1;
    Summoner summoner = new SummonerBuilder().withPlatform(region).withName(user).get();
    Map<Integer, StaticChampion> champData = api.getDDragonAPI().getChampions();
    // pfp
    String pfp = ImageAPI.getInstance().getProfileIcon(region, user);
    // name and lv
    int level = summoner.getSummonerLevel();
    String name = summoner.getName();
    // most recent game
    List<String> matches = summoner.getLeagueGames().get();
    LOLMatch match = LOLMatch.get(region, matches.get(0));
    MatchParticipant self = match.getParticipants().stream().filter(p -> p.getPuuid().equals(summoner.getPUUID())).findFirst().get();
    StaticChampion champion = champData.get(self.getChampionId());
    MatchPerks summs = self.getPerks();
    boolean won = self.didWin();
    System.out.println("Profile icon: " + pfp);
    System.out.println(name + ", Level " + level);
    System.out.println();
    System.out.format(name + " %s their most recent game.", won ? "won" : "lost");
    System.out.println();
    System.out.println("They were playing " + self.getChampionSelectLane() + " " + champion.getName());
}
Also used : Summoner(no.stelar7.api.r4j.pojo.lol.summoner.Summoner) SummonerBuilder(no.stelar7.api.r4j.impl.lol.builders.summoner.SummonerBuilder) StaticChampion(no.stelar7.api.r4j.pojo.lol.staticdata.champion.StaticChampion) R4J(no.stelar7.api.r4j.impl.R4J) LeagueShard(no.stelar7.api.r4j.basic.constants.api.regions.LeagueShard) Test(org.junit.jupiter.api.Test)

Aggregations

Summoner (no.stelar7.api.r4j.pojo.lol.summoner.Summoner)5 LeagueShard (no.stelar7.api.r4j.basic.constants.api.regions.LeagueShard)2 Field (java.lang.reflect.Field)1 Pair (no.stelar7.api.r4j.basic.utils.Pair)1 R4J (no.stelar7.api.r4j.impl.R4J)1 SummonerBuilder (no.stelar7.api.r4j.impl.lol.builders.summoner.SummonerBuilder)1 ChampionRotationInfo (no.stelar7.api.r4j.pojo.lol.champion.ChampionRotationInfo)1 ChampionMastery (no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery)1 StaticChampion (no.stelar7.api.r4j.pojo.lol.staticdata.champion.StaticChampion)1 Realm (no.stelar7.api.r4j.pojo.lol.staticdata.realm.Realm)1 PlatformData (no.stelar7.api.r4j.pojo.lol.status.PlatformData)1 Test (org.junit.jupiter.api.Test)1