From 96c3312931905289a2543004cc8dcfacb48785e7 Mon Sep 17 00:00:00 2001 From: stelar7 Date: Fri, 1 Dec 2023 12:00:48 +0100 Subject: [PATCH] Minor rename and move around stuff --- .../stelar7/api/r4j/basic/APICredentials.java | 18 ++++++++++++ .../api/r4j/basic/constants/api/ApiKey.java | 9 ------ .../r4j/basic/constants/types/ApiKeyType.java | 10 +++++++ .../no/stelar7/api/r4j/basic/utils/Utils.java | 29 +------------------ .../api/r4j/impl/shared/AccountAPI.java | 19 ++++++------ 5 files changed, 39 insertions(+), 46 deletions(-) delete mode 100644 src/main/java/no/stelar7/api/r4j/basic/constants/api/ApiKey.java create mode 100644 src/main/java/no/stelar7/api/r4j/basic/constants/types/ApiKeyType.java diff --git a/src/main/java/no/stelar7/api/r4j/basic/APICredentials.java b/src/main/java/no/stelar7/api/r4j/basic/APICredentials.java index b6645581..7de75b20 100644 --- a/src/main/java/no/stelar7/api/r4j/basic/APICredentials.java +++ b/src/main/java/no/stelar7/api/r4j/basic/APICredentials.java @@ -1,5 +1,6 @@ package no.stelar7.api.r4j.basic; +import no.stelar7.api.r4j.basic.constants.types.ApiKeyType; import no.stelar7.api.r4j.basic.exceptions.APIUnsupportedActionException; import no.stelar7.api.r4j.basic.utils.Base32; @@ -129,6 +130,23 @@ public String getTournamentAPIKey() return this.tournamentApiKey; } + public String getKey(ApiKeyType type) { + switch (type) { + case LOL: + return getLoLAPIKey(); + case TOURNAMENT: + return getTournamentAPIKey(); + case TFT: + return getTFTAPIKey(); + case VAL: + return getVALAPIKey(); + case LOR: + return getLORAPIKey(); + default: + throw new APIUnsupportedActionException("API key not set!"); + } + } + public String getUniqueKeyCombination() { String unique = lolAPIKey + "separator" + tournamentApiKey + "separator" + TFTAPIKey + "separator" + LORAPIKey + "separator" + VALAPIKey; diff --git a/src/main/java/no/stelar7/api/r4j/basic/constants/api/ApiKey.java b/src/main/java/no/stelar7/api/r4j/basic/constants/api/ApiKey.java deleted file mode 100644 index ad10c8ef..00000000 --- a/src/main/java/no/stelar7/api/r4j/basic/constants/api/ApiKey.java +++ /dev/null @@ -1,9 +0,0 @@ -package no.stelar7.api.r4j.basic.constants.api; - -public enum ApiKey { - LOL, - TOURNAMENT, - TFT, - VAL, - LOR -} diff --git a/src/main/java/no/stelar7/api/r4j/basic/constants/types/ApiKeyType.java b/src/main/java/no/stelar7/api/r4j/basic/constants/types/ApiKeyType.java new file mode 100644 index 00000000..e793fbe6 --- /dev/null +++ b/src/main/java/no/stelar7/api/r4j/basic/constants/types/ApiKeyType.java @@ -0,0 +1,10 @@ +package no.stelar7.api.r4j.basic.constants.types; + +public enum ApiKeyType +{ + LOL, + TOURNAMENT, + TFT, + VAL, + LOR +} diff --git a/src/main/java/no/stelar7/api/r4j/basic/utils/Utils.java b/src/main/java/no/stelar7/api/r4j/basic/utils/Utils.java index 91c5d4c5..5bd36f47 100644 --- a/src/main/java/no/stelar7/api/r4j/basic/utils/Utils.java +++ b/src/main/java/no/stelar7/api/r4j/basic/utils/Utils.java @@ -1,15 +1,11 @@ package no.stelar7.api.r4j.basic.utils; import com.google.gson.*; - -import no.stelar7.api.r4j.basic.calling.DataCall; -import no.stelar7.api.r4j.basic.constants.api.ApiKey; import no.stelar7.api.r4j.basic.constants.api.regions.*; +import no.stelar7.api.r4j.basic.constants.types.*; import no.stelar7.api.r4j.basic.constants.types.lol.*; import no.stelar7.api.r4j.basic.constants.types.tft.TFTTier; import no.stelar7.api.r4j.basic.ratelimiting.RateLimit; -import no.stelar7.api.r4j.basic.serializer.GenericEnumSerializer; -import no.stelar7.api.r4j.basic.constants.types.*; import no.stelar7.api.r4j.basic.serializer.*; import no.stelar7.api.r4j.pojo.lor.offline.expedition.ExpeditionState; import no.stelar7.api.r4j.pojo.lor.offline.game.LoRGameState; @@ -87,29 +83,6 @@ private Utils() gson = builder.setPrettyPrinting().disableHtmlEscaping().create(); } - public static String getSelectedApiKey(ApiKey keySelection) - { - String key = null; - switch (keySelection) { - case LOL: - key = DataCall.getCredentials().getLoLAPIKey(); - break; - case LOR: - key = DataCall.getCredentials().getLORAPIKey(); - break; - case TFT: - key = DataCall.getCredentials().getTFTAPIKey(); - break; - case TOURNAMENT: - key = DataCall.getCredentials().getTournamentAPIKey(); - break; - case VAL: - key = DataCall.getCredentials().getVALAPIKey(); - break; - } - return key; - } - public static String padLeft(String input, String val, int length) { StringBuilder sb = new StringBuilder(input); diff --git a/src/main/java/no/stelar7/api/r4j/impl/shared/AccountAPI.java b/src/main/java/no/stelar7/api/r4j/impl/shared/AccountAPI.java index 90652dc3..646e23ad 100644 --- a/src/main/java/no/stelar7/api/r4j/impl/shared/AccountAPI.java +++ b/src/main/java/no/stelar7/api/r4j/impl/shared/AccountAPI.java @@ -3,6 +3,7 @@ import no.stelar7.api.r4j.basic.calling.*; import no.stelar7.api.r4j.basic.constants.api.*; import no.stelar7.api.r4j.basic.constants.api.regions.*; +import no.stelar7.api.r4j.basic.constants.types.ApiKeyType; import no.stelar7.api.r4j.basic.utils.Utils; import no.stelar7.api.r4j.pojo.shared.*; @@ -25,14 +26,14 @@ private AccountAPI() public RiotAccount getAccountByPUUID(RegionShard server, String puuid) { - return getAccountByPUUID(server, puuid, ApiKey.VAL); + return getAccountByPUUID(server, puuid, ApiKeyType.VAL); } - public RiotAccount getAccountByPUUID(RegionShard server, String puuid, ApiKey keySelected) + public RiotAccount getAccountByPUUID(RegionShard server, String puuid, ApiKeyType keyType) { DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.PUUID_ID_PLACEHOLDER, puuid) - .withHeader(Constants.X_RIOT_TOKEN_HEADER_KEY, Utils.getSelectedApiKey(keySelected)) + .withHeader(Constants.X_RIOT_TOKEN_HEADER_KEY, DataCall.getCredentials().getKey(keyType)) .withEndpoint(URLEndpoint.V1_SHARED_ACCOUNT_BY_PUUID) .withPlatform(server); Map data = new LinkedHashMap<>(); @@ -61,14 +62,14 @@ public RiotAccount getAccountByPUUID(RegionShard server, String puuid, ApiKey ke public RiotAccount getAccountByTag(RegionShard server, String name, String tag) { - return getAccountByTag(server, name, tag, ApiKey.VAL); + return getAccountByTag(server, name, tag, ApiKeyType.VAL); } - public RiotAccount getAccountByTag(RegionShard server, String name, String tag, ApiKey keySelected) + public RiotAccount getAccountByTag(RegionShard server, String name, String tag, ApiKeyType keyType) { DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.GAME_NAME_PLACEHOLDER, Utils.normalizeString(name)) .withURLParameter(Constants.TAG_LINE_PLACEHOLDER, Utils.normalizeString(tag)) - .withHeader(Constants.X_RIOT_TOKEN_HEADER_KEY, Utils.getSelectedApiKey(keySelected)) + .withHeader(Constants.X_RIOT_TOKEN_HEADER_KEY, DataCall.getCredentials().getKey(keyType)) .withEndpoint(URLEndpoint.V1_SHARED_ACCOUNT_BY_TAG) .withPlatform(server); Map data = new LinkedHashMap<>(); @@ -98,14 +99,14 @@ public RiotAccount getAccountByTag(RegionShard server, String name, String tag, public RiotAccountShard getActiveShard(RegionShard server, ShardableGame game, String puuid) { - return getActiveShard(server, game, puuid, ApiKey.VAL); + return getActiveShard(server, game, puuid, ApiKeyType.VAL); } - public RiotAccountShard getActiveShard(RegionShard server, ShardableGame game, String puuid, ApiKey keySelected) + public RiotAccountShard getActiveShard(RegionShard server, ShardableGame game, String puuid, ApiKeyType keyType) { DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.GAME_PLACEHOLDER, game.getRealmValue()) .withURLParameter(Constants.PUUID_ID_PLACEHOLDER, puuid) - .withHeader(Constants.X_RIOT_TOKEN_HEADER_KEY, Utils.getSelectedApiKey(keySelected)) + .withHeader(Constants.X_RIOT_TOKEN_HEADER_KEY, DataCall.getCredentials().getKey(keyType)) .withEndpoint(URLEndpoint.V1_SHARED_SHARD_BY_PUUID) .withPlatform(server); Map data = new LinkedHashMap<>();