-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
491 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/main/java/no/stelar7/api/r4j/impl/lor/LORMatchAPI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
97
src/main/java/no/stelar7/api/r4j/pojo/lor/match/LORMatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
58
src/main/java/no/stelar7/api/r4j/pojo/lor/match/LORMetadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + | ||
'}'; | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
src/main/java/no/stelar7/api/r4j/pojo/lor/match/LORParticipant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + | ||
'}'; | ||
} | ||
} |
Oops, something went wrong.