Skip to content

Commit

Permalink
Minor rename and move around stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
stelar7 committed Dec 1, 2023
1 parent fd3b5f5 commit 96c3312
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 46 deletions.
18 changes: 18 additions & 0 deletions src/main/java/no/stelar7/api/r4j/basic/APICredentials.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package no.stelar7.api.r4j.basic.constants.types;

public enum ApiKeyType
{
LOL,
TOURNAMENT,
TFT,
VAL,
LOR
}
29 changes: 1 addition & 28 deletions src/main/java/no/stelar7/api/r4j/basic/utils/Utils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/no/stelar7/api/r4j/impl/shared/AccountAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand All @@ -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<String, Object> data = new LinkedHashMap<>();
Expand Down Expand Up @@ -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<String, Object> data = new LinkedHashMap<>();
Expand Down Expand Up @@ -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<String, Object> data = new LinkedHashMap<>();
Expand Down

0 comments on commit 96c3312

Please sign in to comment.