Skip to content

Commit

Permalink
Add LOR match api
Browse files Browse the repository at this point in the history
  • Loading branch information
stelar7 committed Oct 2, 2020
1 parent 799b8bb commit 5ed5920
Show file tree
Hide file tree
Showing 9 changed files with 491 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ public Long get(URLEndpoint endpoint)
DEFAULTS.add(URLEndpoint.V4_LEAGUE_RANK, MINUTES_30);

DEFAULTS.add(URLEndpoint.V1_VAL_MATCHLIST_BY_PUUID, MINUTES_30);
DEFAULTS.add(URLEndpoint.V1_LOR_RANKED_LEADERBOARD, MINUTES_30);
DEFAULTS.add(URLEndpoint.V1_VAL_RECENT_MATCH_BY_QUEUE, MINUTES_10);

DEFAULTS.add(URLEndpoint.V1_LOR_RANKED_LEADERBOARD, MINUTES_30);
DEFAULTS.add(URLEndpoint.V1_LOR_MATCHES_BY_PUUID, MINUTES_30);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,13 @@ public enum URLEndpoint
V1_SHARED_ACCOUNT_BY_TAG("riot", "account", "v1", "accounts/by-riot-id/" + Constants.GAME_NAME_PLACEHOLDER + "/" + Constants.TAG_LINE_PLACEHOLDER, RiotAccount.class),
V1_SHARED_SHARD_BY_PUUID("riot", "account", "v1", "active-shards/by-game/" + Constants.GAME_PLACEHOLDER + "/by-puuid/" + Constants.PUUID_ID_PLACEHOLDER, RiotAccountShard.class),

V1_LOR_MATCHES_BY_PUUID("lor", "match", "v1", "matches/by-puuid/" + Constants.PUUID_ID_PLACEHOLDER + "/ids", StringList.class),
V1_LOR_MATCH("lor", "match", "v1", "matches/" + Constants.MATCH_ID_PLACEHOLDER, GAMHSMatch.class),

;


private final String game;
private final String game;
private final String service;
private final String version;
private final String resource;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/no/stelar7/api/r4j/impl/R4J.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ public LoRClientAPI getClientAPI()
{
return LoRClientAPI.getInstance();
}

/**
* Gets match api.
*
* @return the match api
*/
public LORMatchAPI getMatchAPI()
{
return LORMatchAPI.getInstance();
}

}

Expand Down
96 changes: 96 additions & 0 deletions src/main/java/no/stelar7/api/r4j/impl/lor/LORMatchAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package no.stelar7.api.r4j.impl.lor;

import no.stelar7.api.r4j.basic.calling.*;
import no.stelar7.api.r4j.basic.constants.api.*;
import no.stelar7.api.r4j.basic.constants.api.regions.RuneterraShard;
import no.stelar7.api.r4j.pojo.lor.match.*;
import no.stelar7.api.r4j.pojo.shared.GAMHSMatch;

import java.util.*;

public class LORMatchAPI
{
private static final LORMatchAPI INSTANCE = new LORMatchAPI();

private LORMatchAPI()
{
}

public static LORMatchAPI getInstance()
{
return LORMatchAPI.INSTANCE;
}

public List<String> getMatchList(RuneterraShard server, String puuid)
{
DataCallBuilder builder = new DataCallBuilder()
.withHeader(Constants.X_RIOT_TOKEN_HEADER_KEY, DataCall.getCredentials().getLORAPIKey())
.withEndpoint(URLEndpoint.V1_LOR_MATCHES_BY_PUUID)
.withURLParameter(Constants.PUUID_ID_PLACEHOLDER, puuid)
.withPlatform(server);

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

Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V1_LOR_MATCHES_BY_PUUID, data);
if (chl.isPresent())
{
return (List<String>) chl.get();
}

try
{
List<String> list = (List<String>) builder.build();

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

return list;
} catch (ClassCastException e)
{
return null;
}
}

public LORMatch getMatch(RuneterraShard platform, String gameId)
{
return getMatchRAW(platform, gameId).toLORMatch();
}

public LORMetadata getMetadata(RuneterraShard platform, String gameId)
{
return getMatchRAW(platform, gameId).toLORMetadata();
}

public GAMHSMatch getMatchRAW(RuneterraShard platform, String gameId)
{
DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.MATCH_ID_PLACEHOLDER, gameId)
.withHeader(Constants.X_RIOT_TOKEN_HEADER_KEY, DataCall.getCredentials().getTFTAPIKey())
.withEndpoint(URLEndpoint.V1_LOR_MATCH)
.withPlatform(platform);

Map<String, Object> data = new TreeMap<>();
data.put("platform", platform);
data.put("gameid", gameId);

Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V1_LOR_MATCH, data);
if (chl.isPresent())
{
return (GAMHSMatch) chl.get();
}

try
{
GAMHSMatch match = (GAMHSMatch) builder.build();

data.put("value", match);
DataCall.getCacheProvider().store(URLEndpoint.V1_LOR_MATCH, data);

return match;
} catch (ClassCastException e)
{
return null;
}
}
}
97 changes: 97 additions & 0 deletions src/main/java/no/stelar7/api/r4j/pojo/lor/match/LORMatch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package no.stelar7.api.r4j.pojo.lor.match;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.*;

public class LORMatch
{
private String game_mode;
private String game_type;
private String game_start_time_utc;
private String game_version;
private List<LORParticipant> players;
private Integer total_turn_count;

public String getGameMode()
{
return game_mode;
}

public String getGameType()
{
return game_type;
}

public String getGameStartTimeUTC()
{
return game_start_time_utc;
}

public ZonedDateTime getGameStartAsDate()
{
DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME;
TemporalAccessor dateTime = formatter.parse(game_start_time_utc);
return ZonedDateTime.from(dateTime);
}

public String getGameVersion()
{
return game_version;
}

public List<LORParticipant> getPlayers()
{
return players;
}

public LORParticipant getWinner()
{
return players.stream().filter(LORParticipant::didWin).findFirst().orElse(null);
}

public Integer getTotalTurnCount()
{
return total_turn_count;
}

@Override
public boolean equals(Object o)
{
if (this == o)
{
return true;
}
if (o == null || getClass() != o.getClass())
{
return false;
}
LORMatch lorMatch = (LORMatch) o;
return Objects.equals(game_mode, lorMatch.game_mode) &&
Objects.equals(game_type, lorMatch.game_type) &&
Objects.equals(game_start_time_utc, lorMatch.game_start_time_utc) &&
Objects.equals(game_version, lorMatch.game_version) &&
Objects.equals(players, lorMatch.players) &&
Objects.equals(total_turn_count, lorMatch.total_turn_count);
}

@Override
public int hashCode()
{
return Objects.hash(game_mode, game_type, game_start_time_utc, game_version, players, total_turn_count);
}

@Override
public String toString()
{
return "LORMatch{" +
"game_mode='" + game_mode + '\'' +
", game_type='" + game_type + '\'' +
", game_start_time_utc='" + game_start_time_utc + '\'' +
", game_version='" + game_version + '\'' +
", players=" + players +
", total_turn_count=" + total_turn_count +
'}';
}
}
58 changes: 58 additions & 0 deletions src/main/java/no/stelar7/api/r4j/pojo/lor/match/LORMetadata.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package no.stelar7.api.r4j.pojo.lor.match;

import java.util.*;

public class LORMetadata
{
private String data_version;
private String match_id;
private List<String> participants;

public String getDataVersion()
{
return data_version;
}

public String getMatchID()
{
return match_id;
}

public List<String> getParticipants()
{
return participants;
}

@Override
public boolean equals(Object o)
{
if (this == o)
{
return true;
}
if (o == null || getClass() != o.getClass())
{
return false;
}
LORMetadata that = (LORMetadata) o;
return Objects.equals(data_version, that.data_version) &&
Objects.equals(match_id, that.match_id) &&
Objects.equals(participants, that.participants);
}

@Override
public int hashCode()
{
return Objects.hash(data_version, match_id, participants);
}

@Override
public String toString()
{
return "LORMetadata{" +
"data_version='" + data_version + '\'' +
", match_id='" + match_id + '\'' +
", participants=" + participants +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package no.stelar7.api.r4j.pojo.lor.match;

import no.stelar7.api.r4j.impl.lor.LoRDeckCode;
import no.stelar7.api.r4j.pojo.lor.offline.card.LoRDeck;

import java.util.*;

public class LORParticipant
{
private String puuid;
private String deck_id;
private String deck_code;
private List<String> factions;
private String game_outcome;
private Integer order_of_play;

public String getPuuid()
{
return puuid;
}

public String getDeckID()
{
return deck_id;
}

public String getDeckCode()
{
return deck_code;
}

public LoRDeck getDeck()
{
return LoRDeckCode.decode(deck_code);
}

public List<String> getFactions()
{
return factions;
}

public String getGameOutcome()
{
return game_outcome;
}

public boolean didWin() {
return game_outcome.equalsIgnoreCase("win");
}

public Integer getOrderOfPlay()
{
return order_of_play;
}

@Override
public boolean equals(Object o)
{
if (this == o)
{
return true;
}
if (o == null || getClass() != o.getClass())
{
return false;
}
LORParticipant that = (LORParticipant) o;
return Objects.equals(puuid, that.puuid) &&
Objects.equals(deck_id, that.deck_id) &&
Objects.equals(deck_code, that.deck_code) &&
Objects.equals(factions, that.factions) &&
Objects.equals(game_outcome, that.game_outcome) &&
Objects.equals(order_of_play, that.order_of_play);
}

@Override
public int hashCode()
{
return Objects.hash(puuid, deck_id, deck_code, factions, game_outcome, order_of_play);
}

@Override
public String toString()
{
return "LORParticipant{" +
"puuid='" + puuid + '\'' +
", deck_id='" + deck_id + '\'' +
", deck_code='" + deck_code + '\'' +
", factions=" + factions +
", game_outcome='" + game_outcome + '\'' +
", order_of_play=" + order_of_play +
'}';
}
}
Loading

0 comments on commit 5ed5920

Please sign in to comment.