Skip to content

Commit

Permalink
Update to puuid versions of ChampionMastery endpoints
Browse files Browse the repository at this point in the history
closes #87
  • Loading branch information
stelar7 committed Dec 15, 2023
1 parent d159e96 commit 27f6584
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ public Long get(URLEndpoint endpoint)
DEFAULTS.add(URLEndpoint.V4_SPECTATOR_FEATURED, MINUTES_30);

DEFAULTS.add(URLEndpoint.V4_MASTERY_BY_CHAMPION, MINUTES_10);
DEFAULTS.add(URLEndpoint.V4_MASTERY_BY_ID, MINUTES_10);
DEFAULTS.add(URLEndpoint.V4_MASTERY_BY_PUUID, MINUTES_10);
DEFAULTS.add(URLEndpoint.V4_MASTERY_SCORE, MINUTES_10);
DEFAULTS.add(URLEndpoint.V4_MASTERY_TOP, MINUTES_10);

DEFAULTS.add(URLEndpoint.V3_CHAMPION_ROTATIONS, DAYS_1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@ public enum URLEndpoint
// lol/champion-mastery/v3/champion-masteries/by-summoner/{summonerId}
// lol/champion-mastery/v3/champion-masteries/by-summoner/{summonerId}/by-champion/{championId}
// lol/champion-mastery/v3/scores/by-summoner/{summonerId}
V4_MASTERY_BY_ID("lol", "champion-mastery", "v4", "champion-masteries/by-summoner/" + Constants.SUMMONER_ID_PLACEHOLDER, ChampionMasteryList.class),
V4_MASTERY_BY_CHAMPION("lol", "champion-mastery", "v4", "champion-masteries/by-summoner/" + Constants.SUMMONER_ID_PLACEHOLDER + "/by-champion/" + Constants.CHAMPION_ID_PLACEHOLDER, ChampionMastery.class),
V4_MASTERY_SCORE("lol", "champion-mastery", "v4", "scores/by-summoner/" + Constants.SUMMONER_ID_PLACEHOLDER, Integer.class),

// lol/champion-mastery/v4/champion-masteries/by-puuid/{encryptedPUUID}
// lol/champion-mastery/v4/champion-masteries/by-puuid/{encryptedPUUID}/by-champion/{championId}
// lol/champion-mastery/v4/champion-masteries/by-puuid/{encryptedPUUID}/top
// lol/champion-mastery/v4/scores/by-puuid/{encryptedPUUID}
V4_MASTERY_BY_PUUID("lol", "champion-mastery", "v4", "champion-masteries/by-puuid/" + Constants.PUUID_ID_PLACEHOLDER, ChampionMasteryList.class),
V4_MASTERY_BY_CHAMPION("lol", "champion-mastery", "v4", "champion-masteries/by-puuid/" + Constants.PUUID_ID_PLACEHOLDER + "/by-champion/" + Constants.CHAMPION_ID_PLACEHOLDER, ChampionMastery.class),
V4_MASTERY_TOP("lol", "champion-mastery", "v4", "champion-masteries/by-puuid/" + Constants.PUUID_ID_PLACEHOLDER + "/top", ChampionMasteryList.class),
V4_MASTERY_SCORE("lol", "champion-mastery", "v4", "scores/by-puuid/" + Constants.PUUID_ID_PLACEHOLDER, Integer.class),

// lol/platform/v3/champion-rotations
V3_CHAMPION_ROTATIONS("lol", "platform", "v3", "champion-rotations", ChampionRotationInfo.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,54 @@ public class ChampionMasteryBuilder
{

private final LeagueShard platform;
private String summonerId;
private final Integer championId;
private String puuid;
private final Integer championId;

private ChampionMasteryBuilder(LeagueShard platform, String summonerId, Integer championId)
private ChampionMasteryBuilder(LeagueShard platform, String puuid, Integer championId)
{
this.platform = platform;
this.summonerId = summonerId;
this.puuid = puuid;
this.championId = championId;
}

public ChampionMasteryBuilder()
{
this.platform = LeagueShard.UNKNOWN;
this.summonerId = null;
this.puuid = null;
this.championId = null;
}


public ChampionMasteryBuilder withSummonerId(String id)
public ChampionMasteryBuilder withPUUID(String id)
{
return new ChampionMasteryBuilder(this.platform, id, this.championId);
}

public ChampionMasteryBuilder withChampionId(Integer id)
{
return new ChampionMasteryBuilder(this.platform, this.summonerId, id);
return new ChampionMasteryBuilder(this.platform, this.puuid, id);
}

public ChampionMasteryBuilder withPlatform(LeagueShard platform)
{
return new ChampionMasteryBuilder(platform, this.summonerId, this.championId);
return new ChampionMasteryBuilder(platform, this.puuid, this.championId);
}

public Integer getMasteryScore()
{
if (this.summonerId == null || this.platform == LeagueShard.UNKNOWN)
if (this.puuid == null || this.platform == LeagueShard.UNKNOWN)
{
return null;
}


DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, this.summonerId)
DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.PUUID_ID_PLACEHOLDER, this.puuid)
.withEndpoint(URLEndpoint.V4_MASTERY_SCORE)
.withPlatform(this.platform);

Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", this.platform);
data.put("id", summonerId);
data.put("puuid", puuid);


Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V4_MASTERY_SCORE, data);
Expand All @@ -87,20 +87,20 @@ public Integer getMasteryScore()

public List<ChampionMastery> getChampionMasteries()
{
if (this.summonerId == null || this.platform == LeagueShard.UNKNOWN)
if (this.puuid == null || this.platform == LeagueShard.UNKNOWN)
{
return Collections.emptyList();
}

DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, this.summonerId)
.withEndpoint(URLEndpoint.V4_MASTERY_BY_ID)
DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.PUUID_ID_PLACEHOLDER, this.puuid)
.withEndpoint(URLEndpoint.V4_MASTERY_BY_PUUID)
.withPlatform(this.platform);

Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", platform);
data.put("id", summonerId);
data.put("puuid", puuid);

Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V4_MASTERY_BY_ID, data);
Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V4_MASTERY_BY_PUUID, data);
if (chl.isPresent())
{
return (List<ChampionMastery>) chl.get();
Expand All @@ -117,7 +117,7 @@ public List<ChampionMastery> getChampionMasteries()
List<ChampionMastery> list = (List<ChampionMastery>) ret;

data.put("value", list);
DataCall.getCacheProvider().store(URLEndpoint.V4_MASTERY_BY_ID, data);
DataCall.getCacheProvider().store(URLEndpoint.V4_MASTERY_BY_PUUID, data);

return list;
} catch (ClassCastException e)
Expand All @@ -139,19 +139,19 @@ public List<ChampionMastery> getTopChampions(Integer count)

public ChampionMastery getChampionMastery()
{
if (this.championId == null || this.summonerId == null || this.platform == LeagueShard.UNKNOWN)
if (this.championId == null || this.puuid == null || this.platform == LeagueShard.UNKNOWN)
{
return null;
}

DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, this.summonerId)
DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.PUUID_ID_PLACEHOLDER, this.puuid)
.withURLParameter(Constants.CHAMPION_ID_PLACEHOLDER, String.valueOf(this.championId))
.withEndpoint(URLEndpoint.V4_MASTERY_BY_CHAMPION)
.withPlatform(this.platform);

Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", platform);
data.put("id", summonerId);
data.put("puuid", puuid);
data.put("champion", championId);


Expand All @@ -171,7 +171,7 @@ public ChampionMastery getChampionMastery()

Field player = mastery.getClass().getDeclaredField("playerId");
player.setAccessible(true);
player.set(mastery, this.summonerId);
player.set(mastery, this.puuid);

Field champ = mastery.getClass().getDeclaredField("championId");
champ.setAccessible(true);
Expand Down
50 changes: 25 additions & 25 deletions src/main/java/no/stelar7/api/r4j/impl/lol/raw/MasteryAPI.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package no.stelar7.api.r4j.impl.lol.raw;

import no.stelar7.api.r4j.basic.constants.api.regions.LeagueShard;
import no.stelar7.api.r4j.basic.utils.Pair;
import no.stelar7.api.r4j.basic.calling.*;
import no.stelar7.api.r4j.basic.constants.api.*;
import no.stelar7.api.r4j.basic.constants.api.regions.LeagueShard;
import no.stelar7.api.r4j.basic.utils.Pair;
import no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery;

import java.lang.reflect.Field;
Expand All @@ -30,19 +30,19 @@ private MasteryAPI()
/**
* The response object contains the summoners masteryscore.
*
* @param server the region to execute against
* @param summonerId the summonerId
* @param server the region to execute against
* @param puuid the puuid
* @return Optional FeaturedGames
*/
public Integer getMasteryScore(LeagueShard server, String summonerId)
public Integer getMasteryScore(LeagueShard server, String puuid)
{
DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, summonerId)
DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.PUUID_ID_PLACEHOLDER, puuid)
.withEndpoint(URLEndpoint.V4_MASTERY_SCORE)
.withPlatform(server);

Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", server);
data.put("id", summonerId);
data.put("puuid", puuid);

Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V4_MASTERY_SCORE, data);
if (chl.isPresent())
Expand All @@ -68,14 +68,14 @@ public Integer getMasteryScore(LeagueShard server, String summonerId)
/**
* Gets the champions with the most masteryscore from the summoner
*
* @param server the server the summoner plays on
* @param summonerId the summonerid of the summoner
* @param count the amount of champions to get
* @param server the server the summoner plays on
* @param puuid the puuid of the summoner
* @param count the amount of champions to get
* @return A sorted list of ChampionMastery
*/
public List<ChampionMastery> getTopChampions(LeagueShard server, String summonerId, Integer count)
public List<ChampionMastery> getTopChampions(LeagueShard server, String puuid, Integer count)
{
List<ChampionMastery> list = getChampionMasteries(server, summonerId);
List<ChampionMastery> list = getChampionMasteries(server, puuid);

return list.stream().sorted(Comparator.comparing(ChampionMastery::getChampionPoints).reversed())
.limit(count != null ? count : 3)
Expand All @@ -89,20 +89,20 @@ public List<ChampionMastery> getTopChampions(LeagueShard server, String summoner
* Only championid and summonerid is present if the level == 0
*
* @param server the region to execute against
* @param summonerId the summonerId
* @param puuid the summonerId
* @param championId the championId
* @return Optional ChampionMastery
*/
public ChampionMastery getChampionMastery(LeagueShard server, String summonerId, int championId)
public ChampionMastery getChampionMastery(LeagueShard server, String puuid, int championId)
{
DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, summonerId)
DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.PUUID_ID_PLACEHOLDER, puuid)
.withURLParameter(Constants.CHAMPION_ID_PLACEHOLDER, String.valueOf(championId))
.withEndpoint(URLEndpoint.V4_MASTERY_BY_CHAMPION)
.withPlatform(server);

Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", server);
data.put("id", summonerId);
data.put("puuid", puuid);
data.put("champion", championId);

Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V4_MASTERY_BY_CHAMPION, data);
Expand All @@ -120,7 +120,7 @@ public ChampionMastery getChampionMastery(LeagueShard server, String summonerId,

Field player = mastery.getClass().getDeclaredField("playerId");
player.setAccessible(true);
player.set(mastery, summonerId);
player.set(mastery, puuid);

Field champ = mastery.getClass().getDeclaredField("championId");
champ.setAccessible(true);
Expand Down Expand Up @@ -152,21 +152,21 @@ public ChampionMastery getChampionMastery(LeagueShard server, String summonerId,
* The response object contains a list of the summoners mastery of champions.
* Does not return a value for champions with mastery level 0
*
* @param server the region to execute against
* @param summonerId the summonerId
* @param server the region to execute against
* @param puuid the puuid
* @return Optional ChampionMastery
*/
public List<ChampionMastery> getChampionMasteries(LeagueShard server, String summonerId)
public List<ChampionMastery> getChampionMasteries(LeagueShard server, String puuid)
{
DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, summonerId)
.withEndpoint(URLEndpoint.V4_MASTERY_BY_ID)
DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.PUUID_ID_PLACEHOLDER, puuid)
.withEndpoint(URLEndpoint.V4_MASTERY_BY_PUUID)
.withPlatform(server);

Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", server);
data.put("id", summonerId);
data.put("puuid", puuid);

Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V4_MASTERY_BY_ID, data);
Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V4_MASTERY_BY_PUUID, data);
if (chl.isPresent())
{
return (List<ChampionMastery>) chl.get();
Expand All @@ -183,7 +183,7 @@ public List<ChampionMastery> getChampionMasteries(LeagueShard server, String sum
List<ChampionMastery> list = (List<ChampionMastery>) ret;

data.put("value", list);
DataCall.getCacheProvider().store(URLEndpoint.V4_MASTERY_BY_ID, data);
DataCall.getCacheProvider().store(URLEndpoint.V4_MASTERY_BY_PUUID, data);

return list;
} catch (ClassCastException e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public List<String> getTFTGames()
*/
public ChampionMastery getChampionMastery(int championId)
{
return new ChampionMasteryBuilder().withPlatform(platform).withSummonerId(id).withChampionId(championId).getChampionMastery();
return new ChampionMasteryBuilder().withPlatform(platform).withPUUID(puuid).withChampionId(championId).getChampionMastery();
}

/**
Expand All @@ -170,7 +170,7 @@ public ChampionMastery getChampionMastery(int championId)
*/
public List<ChampionMastery> getChampionMasteries()
{
return new ChampionMasteryBuilder().withPlatform(platform).withSummonerId(id).getChampionMasteries();
return new ChampionMasteryBuilder().withPlatform(platform).withPUUID(puuid).getChampionMasteries();
}

public List<LeagueEntry> getLeagueEntry()
Expand All @@ -190,7 +190,7 @@ public String getThirdPartyCode()

public int getMasteryScore()
{
return new ChampionMasteryBuilder().withPlatform(platform).withSummonerId(id).getMasteryScore();
return new ChampionMasteryBuilder().withPlatform(platform).withPUUID(puuid).getMasteryScore();
}

/**
Expand Down
Loading

0 comments on commit 27f6584

Please sign in to comment.