diff --git a/pom.xml b/pom.xml
index 6e442f3..0b790b3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,9 +9,13 @@
1.2
- 8
- 8
+ 11
+ 11
UTF-8
+ 2.10.1
+ 4.7.4
+ 4.10.0
+ 32.1.2-jre
@@ -109,7 +113,25 @@
com.google.code.gson
gson
- 2.10.1
+ ${gson.version}
+
+
+
+ info.picocli
+ picocli
+ ${picocli.version}
+
+
+
+ com.squareup.okhttp3
+ okhttp
+ ${okhttp.version}
+
+
+
+ com.google.guava
+ guava
+ ${guava.version}
diff --git a/src/main/java/net/socketconnection/jva/Main.java b/src/main/java/net/socketconnection/jva/Main.java
new file mode 100644
index 0000000..c923ed4
--- /dev/null
+++ b/src/main/java/net/socketconnection/jva/Main.java
@@ -0,0 +1,27 @@
+package net.socketconnection.jva;
+
+import net.socketconnection.jva.commands.*;
+import picocli.CommandLine;
+
+
+public class Main {
+ public static void main(String... args) {
+
+ /**Commands**/
+ CommandLine cmd = new CommandLine(new MainCommands())
+ .addSubcommand("PlayerRank", new PlayerCommand())
+ .addSubcommand("PlayerMatchHistory", new PlayerMatchHistoryCommand())
+ .addSubcommand("MatchById", new MatchWithIdCommand())
+ .addSubcommand("LeaderBoard", new LeaderBoardCommand())
+ .addSubcommand("RegionVersion", new RegionVersionCommand())
+ .addSubcommand("LatestValorantArticle", new LatestArticleCommand())
+ .addSubcommand("RegionUpdates", new RegionUpdatesCommand())
+ .addSubcommand("ValorantStoreItems", new StoreItemCommand())
+ .addSubcommand("ValorantStoreBundle", new StoreBundleCommand());
+
+ cmd.setExecutionStrategy(new CommandLine.RunAll());
+ int exitCode = cmd.execute(args);
+ System.exit(exitCode);
+
+ }
+}
diff --git a/src/main/java/net/socketconnection/jva/ValorantAPI.java b/src/main/java/net/socketconnection/jva/api/ValorantAPI.java
similarity index 77%
rename from src/main/java/net/socketconnection/jva/ValorantAPI.java
rename to src/main/java/net/socketconnection/jva/api/ValorantAPI.java
index 0ca0f90..e35eabe 100644
--- a/src/main/java/net/socketconnection/jva/ValorantAPI.java
+++ b/src/main/java/net/socketconnection/jva/api/ValorantAPI.java
@@ -1,4 +1,4 @@
-package net.socketconnection.jva;
+package net.socketconnection.jva.api;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
@@ -19,25 +19,29 @@
import net.socketconnection.jva.models.status.Update;
import net.socketconnection.jva.player.LeaderboardPlayer;
import net.socketconnection.jva.utils.GsonUtils;
+import okhttp3.HttpUrl;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
-import java.net.HttpURLConnection;
-import java.net.URL;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import static java.net.HttpURLConnection.*;
+import static net.socketconnection.jva.utils.RiotUtils.BASE_URL;
+
public class ValorantAPI {
- private final URL baseUrl;
private final String apiKey;
+ private final OkHttpClient okHttpClient;
public ValorantAPI(String apiKey) throws IOException {
- baseUrl = new URL("https://api.henrikdev.xyz/valorant");
this.apiKey = apiKey;
+ this.okHttpClient = new OkHttpClient();
}
public ValorantAPI() throws IOException {
@@ -47,10 +51,10 @@ public ValorantAPI() throws IOException {
public List getLeaderboard(Region region, String riotId) throws IOException {
JsonArray leaderboardData;
- if(riotId == null) {
+ if (riotId == null) {
leaderboardData = sendRestRequest("/v1/leaderboard/" + region.getQuery()).getAsJsonArray();
} else {
- if(!riotId.contains("#") || riotId.split("#").length < 2) {
+ if (!riotId.contains("#") || riotId.split("#").length < 2) {
throw new InvalidRiotIdentificationException("Unknown format (right format: NAME#TAG)");
}
@@ -81,15 +85,15 @@ public ServerStatus getServerStatus(Region region) throws IOException {
List maintenances = new LinkedList<>();
List incidents = new LinkedList<>();
- for(JsonElement maintenanceElement : maintenancesData) {
+ for (JsonElement maintenanceElement : maintenancesData) {
JsonObject maintenanceObject = maintenanceElement.getAsJsonObject();
List updates = new LinkedList<>();
- for(JsonElement updateElement : maintenanceObject.getAsJsonArray("updates")) {
+ for (JsonElement updateElement : maintenanceObject.getAsJsonArray("updates")) {
JsonObject updateObject = updateElement.getAsJsonObject();
Map translations = new LinkedHashMap<>();
- for(JsonElement translationElement : updateObject.getAsJsonArray("translations")) {
+ for (JsonElement translationElement : updateObject.getAsJsonArray("translations")) {
JsonObject translationObject = translationElement.getAsJsonObject();
translations.put(Language.getFromLocale(GsonUtils.getAsString(translationObject.get("locale"))),
@@ -98,7 +102,7 @@ public ServerStatus getServerStatus(Region region) throws IOException {
List publishLocations = new LinkedList<>();
- for(JsonElement publishElement : updateObject.getAsJsonArray("publish_locations")) {
+ for (JsonElement publishElement : updateObject.getAsJsonArray("publish_locations")) {
publishLocations.add(GsonUtils.getAsString(publishElement));
}
@@ -109,13 +113,13 @@ public ServerStatus getServerStatus(Region region) throws IOException {
List platforms = new LinkedList<>();
- for(JsonElement platformElement : maintenanceObject.getAsJsonArray("platforms")) {
+ for (JsonElement platformElement : maintenanceObject.getAsJsonArray("platforms")) {
platforms.add(GsonUtils.getAsString(platformElement));
}
Map titles = new LinkedHashMap<>();
- for(JsonElement titleElement : maintenanceObject.getAsJsonArray("titles")) {
+ for (JsonElement titleElement : maintenanceObject.getAsJsonArray("titles")) {
JsonObject titleObject = titleElement.getAsJsonObject();
titles.put(Language.getFromLocale(GsonUtils.getAsString(titleObject.get("locale"))), GsonUtils.getAsString(titleObject.get("content")));
@@ -127,15 +131,15 @@ public ServerStatus getServerStatus(Region region) throws IOException {
GsonUtils.getAsString(maintenanceObject.get("incident_severity"))));
}
- for(JsonElement incidentElement : incidentsData) {
+ for (JsonElement incidentElement : incidentsData) {
JsonObject incidentObject = incidentElement.getAsJsonObject();
List updates = new LinkedList<>();
- for(JsonElement updateElement : incidentObject.getAsJsonArray("updates")) {
+ for (JsonElement updateElement : incidentObject.getAsJsonArray("updates")) {
JsonObject updateObject = updateElement.getAsJsonObject();
Map translations = new LinkedHashMap<>();
- for(JsonElement translationElement : updateObject.getAsJsonArray("translations")) {
+ for (JsonElement translationElement : updateObject.getAsJsonArray("translations")) {
JsonObject translationObject = translationElement.getAsJsonObject();
translations.put(Language.getFromLocale(GsonUtils.getAsString(translationObject.get("locale"))), GsonUtils.getAsString(translationObject.get("content")));
@@ -143,7 +147,7 @@ public ServerStatus getServerStatus(Region region) throws IOException {
List publishLocations = new LinkedList<>();
- for(JsonElement publishElement : updateObject.getAsJsonArray("publish_locations")) {
+ for (JsonElement publishElement : updateObject.getAsJsonArray("publish_locations")) {
publishLocations.add(GsonUtils.getAsString(publishElement));
}
@@ -154,13 +158,13 @@ public ServerStatus getServerStatus(Region region) throws IOException {
List platforms = new LinkedList<>();
- for(JsonElement platformElement : incidentObject.getAsJsonArray("platforms")) {
+ for (JsonElement platformElement : incidentObject.getAsJsonArray("platforms")) {
platforms.add(GsonUtils.getAsString(platformElement));
}
Map titles = new LinkedHashMap<>();
- for(JsonElement titleElement : incidentObject.getAsJsonArray("titles")) {
+ for (JsonElement titleElement : incidentObject.getAsJsonArray("titles")) {
JsonObject titleObject = titleElement.getAsJsonObject();
titles.put(Language.getFromLocale(GsonUtils.getAsString(titleObject.get("locale"))), GsonUtils.getAsString(titleObject.get("content")));
@@ -187,7 +191,7 @@ public List getWebsiteArticles(Language language) throws IOExcep
List websiteArticles = new LinkedList<>();
- for(JsonElement articleElement : articleData) {
+ for (JsonElement articleElement : articleData) {
JsonObject articleObject = articleElement.getAsJsonObject();
websiteArticles.add(new WebsiteArticle(GsonUtils.getAsString(articleObject.get("banner_url")), WebsiteArticle.Category.getFromQuery(GsonUtils.getAsString(articleObject.get("category"))),
@@ -203,13 +207,13 @@ public List getStoreBundles() throws IOException {
List bundles = new LinkedList<>();
- for(JsonElement bundleElement : bundlesData) {
+ for (JsonElement bundleElement : bundlesData) {
JsonObject bundleObject = bundleElement.getAsJsonObject();
JsonArray itemData = bundleObject.getAsJsonArray("items");
List items = new LinkedList<>();
- for(JsonElement itemElement : itemData) {
+ for (JsonElement itemElement : itemData) {
JsonObject itemObject = itemElement.getAsJsonObject();
items.add(new BundleItem(GsonUtils.getAsString(itemObject.get("uuid")), GsonUtils.getAsString(itemObject.get("name")),
@@ -232,12 +236,12 @@ public List getStoreOffers() throws IOException {
List items = new LinkedList<>();
- for(JsonElement offerElement : offersData) {
+ for (JsonElement offerElement : offersData) {
JsonObject offerObject = offerElement.getAsJsonObject();
ContentTier contentTier = null;
- if(!offerObject.get("content_tier").isJsonNull()) {
+ if (!offerObject.get("content_tier").isJsonNull()) {
JsonObject contentTierObject = offerObject.getAsJsonObject("content_tier");
contentTier = new ContentTier(GsonUtils.getAsString(contentTierObject.get("name")),
@@ -253,36 +257,30 @@ public List getStoreOffers() throws IOException {
}
public JsonElement sendRestRequest(String uriPath) throws IOException {
- HttpURLConnection connection = (HttpURLConnection) new URL(baseUrl + uriPath).openConnection();
-
- if(apiKey != null) {
- connection.setRequestProperty("Authorization", apiKey);
- }
-
- connection.setRequestProperty("User-Agent", "Java Valorant API (JVA)");
- connection.setDoInput(true);
+ var request = constructURLBuilder(uriPath, apiKey != null);
+ var call = okHttpClient.newCall(request);
+ var response = call.execute();
- switch (connection.getResponseCode()) {
- case 200:
+ switch (response.code()) {
+ case HTTP_OK:
break;
- case 403:
- throw new InvalidAuthenticationException(connection.getResponseMessage());
- case 404:
- throw new IncorrectDataException(connection.getResponseMessage());
+ case HTTP_BAD_REQUEST:
+ throw new InvalidRequestException(response.message());
+ case HTTP_FORBIDDEN:
+ throw new InvalidAuthenticationException(response.message());
+ case HTTP_NOT_FOUND:
+ throw new IncorrectDataException(response.message());
case 429:
- throw new RateLimitedException(connection.getResponseMessage());
+ throw new RateLimitedException(response.message());
default:
- throw new FetchException("Rest API returned unknown error code: " + connection.getResponseMessage());
+ throw new FetchException("Rest API returned unknown error code: " + response.message());
}
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
- BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
- String msg;
+ var reader = new BufferedReader(new InputStreamReader(response.body().byteStream()));
- while ((msg = reader.readLine()) != null) {
- builder.append(msg).append("\n");
- }
+ reader.lines().forEach(builder::append);
return new Gson().fromJson(builder.toString(), JsonElement.class);
}
@@ -291,7 +289,23 @@ public String getApiKey() {
return apiKey;
}
- public URL getBaseUrl() {
- return baseUrl;
+ public Request constructURLBuilder(String uriPath, boolean hasApiKey) {
+ var url = BASE_URL + "valorant" + uriPath;
+ var urlBuilder = HttpUrl.parse(url).newBuilder();
+ var targetURL = urlBuilder.build().toString();
+ if (hasApiKey) {
+ return new Request.Builder()
+ .url(targetURL)
+ .addHeader("Authorization", apiKey)
+ .addHeader("User-Agent", "Java Valorant API (JVA)")
+ .build();
+ }
+
+ Request request = new Request.Builder()
+ .url(targetURL)
+ .addHeader("User-Agent", "Java Valorant API (JVA)")
+ .build();
+
+ return request;
}
}
diff --git a/src/main/java/net/socketconnection/jva/commands/LatestArticleCommand.java b/src/main/java/net/socketconnection/jva/commands/LatestArticleCommand.java
new file mode 100644
index 0000000..78162ad
--- /dev/null
+++ b/src/main/java/net/socketconnection/jva/commands/LatestArticleCommand.java
@@ -0,0 +1,35 @@
+package net.socketconnection.jva.commands;
+
+
+import net.socketconnection.jva.api.ValorantAPI;
+import net.socketconnection.jva.enums.Language;
+import net.socketconnection.jva.models.WebsiteArticle;
+import picocli.CommandLine;
+
+import java.util.List;
+import java.util.concurrent.Callable;
+
+@CommandLine.Command(name = "LatestArticle", mixinStandardHelpOptions = true, version = "1.0",
+ description = "Get the last articles from the official VALORANT page.")
+public class LatestArticleCommand implements Callable {
+
+ @CommandLine.Option(names = {"-lg", "--language"}, description = "The language of the article", defaultValue = "en-en")
+ private String language;
+ @CommandLine.Option(names = {"-ak", "--apikey"}, description = "The api key")
+ private String apiKey;
+
+ @Override
+ public Integer call() throws Exception {
+
+ // Initialize the main instance (API key is NOT required)
+ ValorantAPI valorantAPI = new ValorantAPI(apiKey);
+ // Get the last articles from the valorant page in a specific language using the Language enu
+ List websiteArticles = valorantAPI.getWebsiteArticles(Language.getFromName(language));
+ WebsiteArticle websiteArticle = websiteArticles.get(0);
+
+ // Print out title and url of the last article
+ System.out.println(websiteArticle.getTitle());
+ System.out.println(websiteArticle.getUrl());
+ return 0;
+ }
+}
diff --git a/src/main/java/net/socketconnection/jva/commands/LeaderBoardCommand.java b/src/main/java/net/socketconnection/jva/commands/LeaderBoardCommand.java
new file mode 100644
index 0000000..6456531
--- /dev/null
+++ b/src/main/java/net/socketconnection/jva/commands/LeaderBoardCommand.java
@@ -0,0 +1,36 @@
+package net.socketconnection.jva.commands;
+
+import net.socketconnection.jva.api.ValorantAPI;
+import net.socketconnection.jva.enums.Region;
+import net.socketconnection.jva.player.LeaderboardPlayer;
+import picocli.CommandLine;
+
+import java.util.List;
+import java.util.concurrent.Callable;
+
+@CommandLine.Command(name = "LeaderBoard", mixinStandardHelpOptions = true, version = "1.0",
+ description = "Get the leaderboard for a region.")
+public class LeaderBoardCommand implements Callable {
+
+ @CommandLine.Option(names = {"-r", "--region"}, paramLabel = "region", description = "Region", required = true)
+ private String region;
+
+ @CommandLine.Option(paramLabel = "apikey", names = {"-ak", "--apikey"}, description = "The api key")
+ private String apiKey;
+
+ @CommandLine.Option(names = {"-h", "--help"}, usageHelp = true, description = "display a help message")
+ private boolean helpRequested = false;
+
+ @Override
+ public Integer call() throws Exception {
+ var valorantAPI = new ValorantAPI(apiKey);
+ // Get the first 1000 leaderboard entries in a list using the Leaderboard class
+ List leaderboardPlayers = valorantAPI.getLeaderboard(Region.getFromQuery(region));
+ LeaderboardPlayer leaderboardPlayer = leaderboardPlayers.get(0);
+ // Print out the current placement and rank rating of the first player
+ System.out.println(leaderboardPlayer.getLeaderboardRank());
+ System.out.println(leaderboardPlayer.getRankRating());
+ return 0;
+ }
+
+}
diff --git a/src/main/java/net/socketconnection/jva/commands/MainCommands.java b/src/main/java/net/socketconnection/jva/commands/MainCommands.java
new file mode 100644
index 0000000..82e9c42
--- /dev/null
+++ b/src/main/java/net/socketconnection/jva/commands/MainCommands.java
@@ -0,0 +1,14 @@
+package net.socketconnection.jva.commands;
+
+import picocli.CommandLine;
+
+import java.util.concurrent.Callable;
+
+@CommandLine.Command(name = "Valorant CLI", mixinStandardHelpOptions = true, version = "1.0",
+ description = "Welcome to Valorant CLI use the following commands.")
+public class MainCommands implements Callable {
+ @Override
+ public Integer call() throws Exception {
+ return 0;
+ }
+}
diff --git a/src/main/java/net/socketconnection/jva/commands/MatchWithIdCommand.java b/src/main/java/net/socketconnection/jva/commands/MatchWithIdCommand.java
new file mode 100644
index 0000000..14e0aee
--- /dev/null
+++ b/src/main/java/net/socketconnection/jva/commands/MatchWithIdCommand.java
@@ -0,0 +1,30 @@
+package net.socketconnection.jva.commands;
+
+import net.socketconnection.jva.api.ValorantAPI;
+import net.socketconnection.jva.match.Match;
+import picocli.CommandLine;
+
+import java.util.concurrent.Callable;
+
+@CommandLine.Command(name = "getMatch", mixinStandardHelpOptions = true, version = "1.0",
+ description = "Get a match using the match id.")
+public class MatchWithIdCommand implements Callable {
+
+ @CommandLine.Option(names = {"--id"}, paramLabel = "MatchId", description = "The Match id", required = true)
+ private String matchId;
+
+ @CommandLine.Option(names = {"-ak", "--apikey"}, description = "The api key")
+ private String apiKey;
+
+ @Override
+ public Integer call() throws Exception {
+ // Initialize the main instance (API key is NOT required)
+ ValorantAPI valorantAPI = new ValorantAPI(apiKey);
+ // Pass the main instance to the match instance and fill the match with a match id
+ Match match = new Match(valorantAPI).fetchData(matchId);
+
+ System.out.println(match);
+
+ return 0;
+ }
+}
diff --git a/src/main/java/net/socketconnection/jva/commands/PlayerCommand.java b/src/main/java/net/socketconnection/jva/commands/PlayerCommand.java
new file mode 100644
index 0000000..1bdbe98
--- /dev/null
+++ b/src/main/java/net/socketconnection/jva/commands/PlayerCommand.java
@@ -0,0 +1,54 @@
+package net.socketconnection.jva.commands;
+
+import net.socketconnection.jva.api.ValorantAPI;
+import net.socketconnection.jva.models.player.PlayerCard;
+import net.socketconnection.jva.player.ValorantPlayer;
+import picocli.CommandLine;
+
+import java.util.concurrent.Callable;
+
+@CommandLine.Command(name = "playerRank", mixinStandardHelpOptions = true, version = "1.0",
+ description = "Get player informations.")
+public class PlayerCommand implements Callable {
+
+ @CommandLine.Option(names = {"-u", "--username"}, paramLabel = "Username", description = "The player username", required = true)
+ private String username;
+
+ @CommandLine.Option(names = {"-t", "--tagname"}, paramLabel = "Tagname", description = "The player tag name", required = true)
+ private String tagName;
+
+ @CommandLine.Option(names = {"-ak", "--apikey"}, description = "The api key")
+ private String apiKey;
+
+ @CommandLine.Option(names = {"-h", "--help"}, usageHelp = true, description = "display a help message")
+ private boolean helpRequested = false;
+
+
+ @Override
+ public Integer call() throws Exception {
+ // Initialize the main instance (API key is NOT required)
+ var valorantAPI = new ValorantAPI(apiKey);
+ // Pass the main instance to the player instance and fill the player with an username and tag or riot id
+ var valorantPlayer = new ValorantPlayer(valorantAPI)
+ .fetchData(username, tagName);
+
+ // Read out the rank using the Rank enum for example
+ var rank = valorantPlayer.getRank();
+ // Print out the rank using the getName() method
+ System.out.println(rank.getName());
+
+ // Read out the level
+ int level = valorantPlayer.getLevel();
+ // Read out the last amount of RR he got or lost
+ int mmrChange = valorantPlayer.getMmrChange();
+
+ // Get the players banner using the PlayerCard model
+ PlayerCard playerCard = valorantPlayer.getPlayerCard();
+ // Print out the banners url in different sizes
+ System.out.println(playerCard.getSmall());
+ System.out.println(playerCard.getLarge());
+ System.out.println("Player leve = " + level);
+ System.out.println("Player MMR = " + mmrChange);
+ return 0;
+ }
+}
diff --git a/src/main/java/net/socketconnection/jva/commands/PlayerMatchHistoryCommand.java b/src/main/java/net/socketconnection/jva/commands/PlayerMatchHistoryCommand.java
new file mode 100644
index 0000000..67d98ad
--- /dev/null
+++ b/src/main/java/net/socketconnection/jva/commands/PlayerMatchHistoryCommand.java
@@ -0,0 +1,64 @@
+package net.socketconnection.jva.commands;
+
+import net.socketconnection.jva.api.ValorantAPI;
+import net.socketconnection.jva.enums.Map;
+import net.socketconnection.jva.enums.Region;
+import net.socketconnection.jva.match.Match;
+import net.socketconnection.jva.player.MatchPlayer;
+import net.socketconnection.jva.player.ValorantPlayer;
+import picocli.CommandLine;
+
+import java.util.List;
+import java.util.concurrent.Callable;
+
+@CommandLine.Command(name = "PlayerMatchHistory", mixinStandardHelpOptions = true, version = "1.0",
+ description = "Get a players match history.")
+public class PlayerMatchHistoryCommand implements Callable {
+
+ @CommandLine.Option(names = {"-u", "--username"}, paramLabel = "Username", description = "The player username", required = true)
+ private String username;
+
+ @CommandLine.Option(names = {"-t", "--tagname"}, paramLabel = "Tagname", description = "The player tag name", required = true)
+ private String tagName;
+
+ @CommandLine.Option(names = {"-ak", "--apikey"}, description = "The api key")
+ private String apiKey;
+
+ @CommandLine.Option(names = {"-h", "--help"}, usageHelp = true, description = "display a help message")
+ private boolean helpRequested = false;
+
+ @Override
+ public Integer call() throws Exception {
+
+ // Initialize the main instance (API key is NOT required)
+ var valorantAPI = new ValorantAPI(apiKey);
+ // Pass the main instance to the player instance and fill the player with an username and tag or riot id
+ var valorantPlayer = new ValorantPlayer(valorantAPI)
+ .fetchData(username, tagName);
+
+ // Saves the last 5 matches in an array of the Match object
+ Match[] matches = valorantPlayer.getMatchHistory();
+ // Saves the last one in a variable
+ Match match = matches[0];
+
+ // Saves the map in a variable using the Map enum
+ Map map = match.getMap();
+ // Print out the map using the getName() method
+ System.out.println(map.getName());
+
+ // Get match id and region of a match using the Region enum
+ String matchId = match.getMatchId();
+ Region region = match.getRegion();
+
+ // Get other players and their values from a match using the MatchPlayer instances
+ List matchPlayers = match.getPlayers();
+ MatchPlayer matchPlayer = matchPlayers.get(0);
+
+ // Print out stats of a match player
+ System.out.println(matchPlayer.getStats().getKills());
+ // Print out informations about a match players behavior and economy
+ System.out.println(matchPlayer.getBehavior().getAfkRounds());
+ System.out.println(matchPlayer.getEconomy().getOverallSpent());
+ return 0;
+ }
+}
diff --git a/src/main/java/net/socketconnection/jva/commands/RegionUpdatesCommand.java b/src/main/java/net/socketconnection/jva/commands/RegionUpdatesCommand.java
new file mode 100644
index 0000000..90638a6
--- /dev/null
+++ b/src/main/java/net/socketconnection/jva/commands/RegionUpdatesCommand.java
@@ -0,0 +1,35 @@
+package net.socketconnection.jva.commands;
+
+import net.socketconnection.jva.api.ValorantAPI;
+import net.socketconnection.jva.enums.Language;
+import net.socketconnection.jva.enums.Region;
+import net.socketconnection.jva.models.status.ServerStatus;
+import picocli.CommandLine;
+
+import java.util.concurrent.Callable;
+
+@CommandLine.Command(name = "RegionUpdates", mixinStandardHelpOptions = true, version = "1.0",
+ description = "Get current maintenances and incidents for a specific region.")
+public class RegionUpdatesCommand implements Callable {
+
+ @CommandLine.Option(names = {"-r", "--region"}, paramLabel = "region", description = "Region", required = true)
+ private String region;
+
+ @CommandLine.Option(names = {"-lg", "--language"}, description = "The language of the article", defaultValue = "en-en")
+ private String language;
+
+ @CommandLine.Option(paramLabel = "apikey", names = {"-ak", "--apikey"}, description = "The api key")
+ private String apiKey;
+
+ @Override
+ public Integer call() throws Exception {
+
+ ValorantAPI valorantAPI = new ValorantAPI(apiKey);
+ // Saves data about versions of a region in a Version model
+ ServerStatus serverStatus = valorantAPI.getServerStatus(Region.getFromQuery(region));
+
+ // Print out a current incident in a specific language using the Language enum
+ System.out.println(serverStatus.getIncidents()[0].getTitles().get(Language.getFromName(language)));
+ return 0;
+ }
+}
diff --git a/src/main/java/net/socketconnection/jva/commands/RegionVersionCommand.java b/src/main/java/net/socketconnection/jva/commands/RegionVersionCommand.java
new file mode 100644
index 0000000..4044261
--- /dev/null
+++ b/src/main/java/net/socketconnection/jva/commands/RegionVersionCommand.java
@@ -0,0 +1,32 @@
+package net.socketconnection.jva.commands;
+
+import net.socketconnection.jva.api.ValorantAPI;
+import net.socketconnection.jva.enums.Region;
+import net.socketconnection.jva.models.Version;
+import picocli.CommandLine;
+
+import java.util.concurrent.Callable;
+
+@CommandLine.Command(name = "RegionVersion", mixinStandardHelpOptions = true, version = "1.0",
+ description = "Get player informations.")
+public class RegionVersionCommand implements Callable {
+
+ @CommandLine.Option(names = {"-r", "--region"}, paramLabel = "region", description = "Region", required = true)
+ private String region;
+
+ @CommandLine.Option(paramLabel = "apikey", names = {"-ak", "--apikey"}, description = "The api key")
+ private String apiKey;
+
+ @Override
+ public Integer call() throws Exception {
+ ValorantAPI valorantAPI = new ValorantAPI(apiKey);
+ // Saves data about versions of a region in a Version model
+ Version version = valorantAPI.getVersion(Region.getFromQuery(region));
+
+ // Print out client and server version
+ System.out.println(version.getVersion());
+ System.out.println(version.getClientVersion());
+
+ return 0;
+ }
+}
diff --git a/src/main/java/net/socketconnection/jva/commands/StoreBundleCommand.java b/src/main/java/net/socketconnection/jva/commands/StoreBundleCommand.java
new file mode 100644
index 0000000..7b52eba
--- /dev/null
+++ b/src/main/java/net/socketconnection/jva/commands/StoreBundleCommand.java
@@ -0,0 +1,32 @@
+package net.socketconnection.jva.commands;
+
+
+import net.socketconnection.jva.api.ValorantAPI;
+import net.socketconnection.jva.models.shop.Bundle;
+import picocli.CommandLine;
+
+import java.util.List;
+import java.util.concurrent.Callable;
+
+@CommandLine.Command(name = "StoreBundle", mixinStandardHelpOptions = true, version = "1.0",
+ description = "Get all available store bundles.")
+public class StoreBundleCommand implements Callable {
+
+ @CommandLine.Option(names = {"-ak", "--apikey"}, description = "The api key")
+ private String apiKey;
+
+ @Override
+ public Integer call() throws Exception {
+
+ // Initialize the main instance (API key is NOT required)
+ ValorantAPI valorantAPI = new ValorantAPI(apiKey);
+
+ // Get all available store bundles
+ List offerItems = valorantAPI.getStoreBundles();
+ // Print out first bundles price
+ System.out.println(offerItems.get(0).getBundlePrice());
+ // Print ouf second bundles expiring date
+ System.out.println(offerItems.get(1).getExpiresAt());
+ return 0;
+ }
+}
diff --git a/src/main/java/net/socketconnection/jva/commands/StoreItemCommand.java b/src/main/java/net/socketconnection/jva/commands/StoreItemCommand.java
new file mode 100644
index 0000000..40bc6ab
--- /dev/null
+++ b/src/main/java/net/socketconnection/jva/commands/StoreItemCommand.java
@@ -0,0 +1,32 @@
+package net.socketconnection.jva.commands;
+
+
+import net.socketconnection.jva.api.ValorantAPI;
+import net.socketconnection.jva.models.shop.item.OfferItem;
+import picocli.CommandLine;
+
+import java.util.List;
+import java.util.concurrent.Callable;
+
+@CommandLine.Command(name = "StoreItem", mixinStandardHelpOptions = true, version = "1.0",
+ description = "Get all store items.")
+public class StoreItemCommand implements Callable {
+
+ @CommandLine.Option(names = {"-ak", "--apikey"}, description = "The api key")
+ private String apiKey;
+
+
+ @Override
+ public Integer call() throws Exception {
+
+ // Initialize the main instance (API key is NOT required)
+ ValorantAPI valorantAPI = new ValorantAPI(apiKey);
+
+ // Get all store items
+ List offerItems = valorantAPI.getStoreOffers();
+ // Print out first items name
+ System.out.println(offerItems.get(0).getName());
+
+ return 0;
+ }
+}
diff --git a/src/main/java/net/socketconnection/jva/exceptions/InvalidRequestException.java b/src/main/java/net/socketconnection/jva/exceptions/InvalidRequestException.java
new file mode 100644
index 0000000..f9e75de
--- /dev/null
+++ b/src/main/java/net/socketconnection/jva/exceptions/InvalidRequestException.java
@@ -0,0 +1,18 @@
+package net.socketconnection.jva.exceptions;
+
+import java.io.IOException;
+
+public class InvalidRequestException extends IOException {
+
+ private final String errorMessage;
+
+
+ public InvalidRequestException(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
+
+ @Override
+ public String getMessage() {
+ return errorMessage;
+ }
+}
diff --git a/src/main/java/net/socketconnection/jva/match/Match.java b/src/main/java/net/socketconnection/jva/match/Match.java
index 0f2af97..fb69b46 100644
--- a/src/main/java/net/socketconnection/jva/match/Match.java
+++ b/src/main/java/net/socketconnection/jva/match/Match.java
@@ -3,7 +3,7 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
-import net.socketconnection.jva.ValorantAPI;
+import net.socketconnection.jva.api.ValorantAPI;
import net.socketconnection.jva.enums.GameMode;
import net.socketconnection.jva.enums.Map;
import net.socketconnection.jva.enums.Region;
@@ -184,4 +184,27 @@ public String getMatchId() {
public ValorantAPI getValorantAPI() {
return valorantAPI;
}
+
+ @Override
+ public String toString() {
+ return "Match{" +
+ "valorantAPI=" + valorantAPI +
+ ", matchId='" + matchId + '\'' +
+ ", map=" + map +
+ ", gameVersion='" + gameVersion + '\'' +
+ ", gameLength=" + gameLength +
+ ", gameStart='" + gameStart + '\'' +
+ ", roundsPlayed=" + roundsPlayed +
+ ", gameMode=" + gameMode +
+ ", seasonId='" + seasonId + '\'' +
+ ", platform='" + platform + '\'' +
+ ", region=" + region +
+ ", server='" + server + '\'' +
+ ", players=" + players +
+ ", red=" + red +
+ ", blue=" + blue +
+ ", rounds=" + rounds +
+ ", fetched=" + fetched +
+ '}';
+ }
}
diff --git a/src/main/java/net/socketconnection/jva/player/LeaderboardPlayer.java b/src/main/java/net/socketconnection/jva/player/LeaderboardPlayer.java
index af5248c..bafcfba 100644
--- a/src/main/java/net/socketconnection/jva/player/LeaderboardPlayer.java
+++ b/src/main/java/net/socketconnection/jva/player/LeaderboardPlayer.java
@@ -1,7 +1,7 @@
package net.socketconnection.jva.player;
import com.google.gson.JsonObject;
-import net.socketconnection.jva.ValorantAPI;
+import net.socketconnection.jva.api.ValorantAPI;
import net.socketconnection.jva.enums.Rank;
import net.socketconnection.jva.exceptions.FetchException;
import net.socketconnection.jva.utils.GsonUtils;
diff --git a/src/main/java/net/socketconnection/jva/player/MatchPlayer.java b/src/main/java/net/socketconnection/jva/player/MatchPlayer.java
index d9f65fe..c283bf3 100644
--- a/src/main/java/net/socketconnection/jva/player/MatchPlayer.java
+++ b/src/main/java/net/socketconnection/jva/player/MatchPlayer.java
@@ -1,7 +1,7 @@
package net.socketconnection.jva.player;
import com.google.gson.JsonObject;
-import net.socketconnection.jva.ValorantAPI;
+import net.socketconnection.jva.api.ValorantAPI;
import net.socketconnection.jva.enums.Agent;
import net.socketconnection.jva.enums.Rank;
import net.socketconnection.jva.enums.Region;
diff --git a/src/main/java/net/socketconnection/jva/player/Player.java b/src/main/java/net/socketconnection/jva/player/Player.java
index 3cd180c..bf33463 100644
--- a/src/main/java/net/socketconnection/jva/player/Player.java
+++ b/src/main/java/net/socketconnection/jva/player/Player.java
@@ -1,7 +1,6 @@
package net.socketconnection.jva.player;
-import net.socketconnection.jva.ValorantAPI;
-import net.socketconnection.jva.enums.Rank;
+import net.socketconnection.jva.api.ValorantAPI;
import net.socketconnection.jva.utils.RiotUtils;
public abstract class Player {
diff --git a/src/main/java/net/socketconnection/jva/player/RoundPlayer.java b/src/main/java/net/socketconnection/jva/player/RoundPlayer.java
index 8122971..955fcbc 100644
--- a/src/main/java/net/socketconnection/jva/player/RoundPlayer.java
+++ b/src/main/java/net/socketconnection/jva/player/RoundPlayer.java
@@ -1,6 +1,6 @@
package net.socketconnection.jva.player;
-import net.socketconnection.jva.ValorantAPI;
+import net.socketconnection.jva.api.ValorantAPI;
import net.socketconnection.jva.exceptions.FetchException;
import java.io.IOException;
diff --git a/src/main/java/net/socketconnection/jva/player/ValorantPlayer.java b/src/main/java/net/socketconnection/jva/player/ValorantPlayer.java
index a7737a9..d2a578a 100644
--- a/src/main/java/net/socketconnection/jva/player/ValorantPlayer.java
+++ b/src/main/java/net/socketconnection/jva/player/ValorantPlayer.java
@@ -3,14 +3,14 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
-import net.socketconnection.jva.ValorantAPI;
+import net.socketconnection.jva.api.ValorantAPI;
import net.socketconnection.jva.enums.GameMode;
import net.socketconnection.jva.enums.Rank;
import net.socketconnection.jva.enums.Region;
import net.socketconnection.jva.exceptions.InvalidRiotIdentificationException;
import net.socketconnection.jva.match.Match;
-import net.socketconnection.jva.models.player.PlayerCard;
import net.socketconnection.jva.models.image.RankImage;
+import net.socketconnection.jva.models.player.PlayerCard;
import net.socketconnection.jva.utils.GsonUtils;
import java.io.IOException;
diff --git a/src/main/java/net/socketconnection/jva/utils/GsonUtils.java b/src/main/java/net/socketconnection/jva/utils/GsonUtils.java
index 55889dd..1bad407 100644
--- a/src/main/java/net/socketconnection/jva/utils/GsonUtils.java
+++ b/src/main/java/net/socketconnection/jva/utils/GsonUtils.java
@@ -4,8 +4,11 @@
public class GsonUtils {
+ private GsonUtils() {
+ }
+
public static String getAsString(JsonElement element) {
- if(element.isJsonNull()) {
+ if (element.isJsonNull()) {
return null;
}
diff --git a/src/main/java/net/socketconnection/jva/utils/RiotUtils.java b/src/main/java/net/socketconnection/jva/utils/RiotUtils.java
index 5270a9f..9ea3090 100644
--- a/src/main/java/net/socketconnection/jva/utils/RiotUtils.java
+++ b/src/main/java/net/socketconnection/jva/utils/RiotUtils.java
@@ -2,6 +2,11 @@
public class RiotUtils {
+ public static final String BASE_URL = "https://api.henrikdev.xyz/";
+
+ private RiotUtils() {
+ }
+
public static String toRiotId(String username, String tag) {
return username + "#" + tag;
}