From 760587018cec3414c0bb33befdcf176d978c726b Mon Sep 17 00:00:00 2001 From: Manos Paterakis Date: Thu, 11 Jul 2019 15:03:20 +0300 Subject: [PATCH] Added non-steam platforms compatibility. --- README.md | 50 +++- pom.xml | 2 +- .../com/steamgriddb/Enums/SGDBIdTypes.java | 4 + src/main/java/com/steamgriddb/Game.java | 162 ++++++++-- src/main/java/com/steamgriddb/Grid.java | 281 ++++++++++++++++-- src/main/java/com/steamgriddb/Search.java | 2 +- 6 files changed, 426 insertions(+), 75 deletions(-) diff --git a/README.md b/README.md index 4a6b080..562dccc 100644 --- a/README.md +++ b/README.md @@ -33,13 +33,28 @@ var gamesJson = Search.searchGamesByNameJSON("cyberpunk"); #### Get a game object without searching: ```java // Get a Game using a GameId -var game = Game.getGameByGameId(1234); +var game = Game.getGameByGameId("1234"); // Get a Game using a SteamAppId -var game = Game.getGameBySteamAppId(567890); +var game = Game.getGameBySteamAppId("567890"); + +// Get a Game using an EgsId +var game = Game.getGameByGogId("OFB-EAST:57557"); + +// Get a Game using an OriginId +var game = Game.getGameByOriginId("OFB-EAST:57557"); + +// Get a Game using an UplayId +var game = Game.getGameByUplayId("4a1562a4-c4d2-4bc5-a85e-f3db588b0072"); + +// Get a Game using an GogId +var game = Game.getGameByGogId("2031519202"); // Get a Game using its constructor -var game = new Game(567890, SGDBIdTypes.SteamAppId); +var game = new Game("567890", SGDBIdTypes.SteamAppId); + +// Get a JSONObject containing the response from the API +var gameJson = Search.getGameJSONBySteamAppId("567890"); ``` #### Do something with a game object: @@ -54,13 +69,16 @@ var stylesArray = game.getStyles(); #### Get some grids: ```java // Get grids by game ID -var grid = Grid.getGridsByGameId(1234); +var grid = Grid.getGridsByGameId("1234"); // Get grids by Steam App Id -var grids = Grid.getGridsBySteamAppId(1234); +var grids = Grid.getGridsBySteamAppId("1234"); // Alternatively, you can do it like this: -var grids = Grid.getGridsById(1234, SGDBIdTypes.GameId); +var grids = Grid.getGridsById("1234", SGDBIdTypes.GameId); + +// Get a JSONObject containing the response from the API +var gridJson = Search.getGridJSONBySteamAppId("567890"); ``` #### Filter the styles: @@ -69,11 +87,11 @@ var grids = Grid.getGridsById(1234, SGDBIdTypes.GameId); SGDBStyles styles[] = {SGDBStyles.Alternate, SGDBStyles.NoLogo}; // Same as before, but using the styles filter -var grid = Grid.getGridsByGameId(1234, styles); +var grid = Grid.getGridsByGameId("1234", styles); -var grids = Grid.getGridsBySteamAppId(1234, styles); +var grids = Grid.getGridsBySteamAppId("1234", styles); -var grids = Grid.getGridsById(1234, SGDBIdTypes.GameId, styles); +var grids = Grid.getGridsById("1234", SGDBIdTypes.GameId, styles); ``` #### Do something with a grid object: @@ -89,22 +107,22 @@ var authorName = grids.get(0).getAuthor().getName(); #### Vote on grids: ```java // Upvote the first grid of the game with ID 1234 -var grid = Grid.getGridsByGameId(1234).get(0); +var grid = Grid.getGridsByGameId("1234").get(0); grid.upvote(); // Downvote the same grid -var grid = Grid.getGridsByGameId(1234).get(0); +var grid = Grid.getGridsByGameId("1234").get(0); grid.upvote(); // Alternatively, use the Grid's ID (80 in this case) to vote: -Grid.upvoteById(80); -Grid.downvoteById(80); +Grid.upvoteById("80"); +Grid.downvoteById("80"); ``` #### Upload a grid: ```java // Upload a blurred grid to Half-Life 2 (2254) -Grid.upload(2254, SGDBStyles.Blurred, "path/of/image.img"); +Grid.upload("2254", SGDBStyles.Blurred, "path/of/image.img"); ``` #### Delete grids: @@ -113,10 +131,10 @@ Grid.upload(2254, SGDBStyles.Blurred, "path/of/image.img"); Grid.deleteByGridID(gameID); // Delete multiple grids by ID -var gameIDs = {123, 456}; +var gameIDs = {"123", "456"}; Grid.deleteByGridIDs(gameIDs); // Delete a Grid object -var grid = Grid.getGridsByGameId(1234).get(0); +var grid = Grid.getGridsByGameId("1234").get(0); grid.delete(); ``` diff --git a/pom.xml b/pom.xml index 4e754d5..0b54e1a 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.steamgriddb java-steamgriddb - 1.0 + 1.1 jar diff --git a/src/main/java/com/steamgriddb/Enums/SGDBIdTypes.java b/src/main/java/com/steamgriddb/Enums/SGDBIdTypes.java index 377c586..ea0d649 100644 --- a/src/main/java/com/steamgriddb/Enums/SGDBIdTypes.java +++ b/src/main/java/com/steamgriddb/Enums/SGDBIdTypes.java @@ -7,5 +7,9 @@ */ public enum SGDBIdTypes { SteamAppId, + OriginId, + EgsId, + UplayId, + GogId, GameId } diff --git a/src/main/java/com/steamgriddb/Game.java b/src/main/java/com/steamgriddb/Game.java index 7d13ccf..d50f47b 100644 --- a/src/main/java/com/steamgriddb/Game.java +++ b/src/main/java/com/steamgriddb/Game.java @@ -2,41 +2,67 @@ import com.steamgriddb.Enums.SGDBIdTypes; import com.steamgriddb.Connection.SGDBConnectionManager; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; import org.json.JSONObject; import org.json.JSONArray; /** * Represents a Game as found on SteamGridDB.com - * + * * @author mpaterakis */ public class Game { /* * Fields - */ - private int id = -1; + */ + private String id = ""; private String name = ""; private ArrayList types = new ArrayList<>(); /** * Constructor for Game. - * + * * @param id The id of the Game - * @param type The type of the given id + * @param type The type of the given id [OriginId, EgsId, UplayId] */ - public Game(int id, SGDBIdTypes type) { + public Game(String id, SGDBIdTypes type) { + try { + id = URLEncoder.encode(id, "UTF-8"); + } catch (UnsupportedEncodingException ex) { + Logger.getLogger(Game.class.getName()).log(Level.SEVERE, null, ex); + } JSONObject json = new JSONObject(); - if (type == SGDBIdTypes.SteamAppId) { - json = SGDBConnectionManager.getJSON("games/steam/" + id); - } else if (type == SGDBIdTypes.GameId) { - json = SGDBConnectionManager.getJSON("games/id/" + id); + switch (type) { + case SteamAppId: + json = getGameJSONBySteamAppId(id); + break; + case GameId: + json = getGameJSONByGameId(id); + break; + case GogId: + json = getGameJSONByGogId(id); + break; + case OriginId: + json = getGameJSONByOriginId(id); + break; + case EgsId: + json = getGameJSONByEgsId(id); + break; + case UplayId: + json = getGameJSONByUplayId(id); + break; + default: + break; } - + if (json.getBoolean("success")) { - this.id = json.getJSONObject("data").getInt("id"); + this.id = String.valueOf(json.getJSONObject("data").getInt("id")); this.name = json.getJSONObject("data").getString("name"); JSONArray typesArray = json.getJSONObject("data").getJSONArray("types"); for (int i = 0; i < typesArray.length(); i++) { @@ -47,60 +73,148 @@ public Game(int id, SGDBIdTypes type) { /** * Get a Game object from a SteamAppId. - * + * * @param steamAppId The Game's SteamAppId * @return A Game object */ - public static Game getGameBySteamAppId(int steamAppId) { + public static Game getGameBySteamAppId(String steamAppId) { Game game = new Game(steamAppId, SGDBIdTypes.SteamAppId); return game; } /** * Get a JSONObject of a Game from a SteamAppId. - * + * * @param steamAppId The Game's SteamAppId * @return A JSONObject object with the Game's data */ - public static JSONObject getGameJSONBySteamAppId(int steamAppId) { + public static JSONObject getGameJSONBySteamAppId(String steamAppId) { JSONObject json = SGDBConnectionManager.getJSON("games/steam/" + steamAppId); return json; } + /** + * Get a Game object from an EgsId. + * + * @param egsId The Game's EgsId + * @return A Game object + */ + public static Game getGameByEgsId(String egsId) { + Game game = new Game(egsId, SGDBIdTypes.EgsId); + return game; + } + + /** + * Get a JSONObject of a Game from an EgsId. + * + * @param egsId The Game's EgsId + * @return A JSONObject object with the Game's data + */ + public static JSONObject getGameJSONByEgsId(String egsId) { + JSONObject json = SGDBConnectionManager.getJSON("games/egs/" + egsId); + return json; + } + + /** + * Get a Game object from an OriginId. + * + * @param originId The Game's OriginId + * @return A Game object + */ + public static Game getGameByOriginId(String originId) { + Game game = new Game(originId, SGDBIdTypes.OriginId); + return game; + } + + /** + * Get a JSONObject of a Game from an OriginId. + * + * @param originId The Game's OriginId + * @return A JSONObject object with the Game's data + */ + public static JSONObject getGameJSONByOriginId(String originId) { + JSONObject json = SGDBConnectionManager.getJSON("games/origin/" + originId); + return json; + } + + /** + * Get a Game object from a UplayId. + * + * @param uplayId The Game's UplayId + * @return A Game object + */ + public static Game getGameByUplayId(String uplayId) { + Game game = new Game(uplayId, SGDBIdTypes.UplayId); + return game; + } + + /** + * Get a JSONObject of a Game from a UplayId. + * + * @param uplayId The Game's UplayId + * @return A JSONObject object with the Game's data + */ + public static JSONObject getGameJSONByUplayId(String uplayId) { + JSONObject json = SGDBConnectionManager.getJSON("games/uplay/" + uplayId); + return json; + } + + /** + * Get a Game object from a GogId. + * + * @param gogId The Game's GogId + * @return A Game object + */ + public static Game getGameByGogId(String gogId) { + Game game = new Game(gogId, SGDBIdTypes.GogId); + return game; + } + + /** + * Get a JSONObject of a Game from a GogId. + * + * @param gogId The Game's GogId + * @return A JSONObject object with the Game's data + */ + public static JSONObject getGameJSONByGogId(String gogId) { + JSONObject json = SGDBConnectionManager.getJSON("games/gog/" + gogId); + return json; + } + /** * Get a Game object from a GameId. - * + * * @param gameId The Game's GameId * @return A Game object */ - public static Game getGameByGameId(int gameId) { + public static Game getGameByGameId(String gameId) { Game game = new Game(gameId, SGDBIdTypes.GameId); return game; } /** * Get a JSONObject of a Game from a GameId. - * + * * @param gameId The Game's GameId * @return A JSONObject object with the Game's data */ - public static JSONObject getGameJSONByGameId(int gameId) { + public static JSONObject getGameJSONByGameId(String gameId) { JSONObject json = SGDBConnectionManager.getJSON("games/id/" + gameId); return json; } /** * Get the Game's id. - * + * * @return id of the Game */ - public int getId() { + public String getId() { return id; } /** * Get the Game's name. - * + * * @return name of the Game */ public String getName() { @@ -109,7 +223,7 @@ public String getName() { /** * Get the Game's types. - * + * * @return types of the Game */ public ArrayList getTypes() { diff --git a/src/main/java/com/steamgriddb/Grid.java b/src/main/java/com/steamgriddb/Grid.java index ebd881f..4b0482b 100644 --- a/src/main/java/com/steamgriddb/Grid.java +++ b/src/main/java/com/steamgriddb/Grid.java @@ -20,8 +20,8 @@ public class Grid { /* * Fields */ - private int id = -1; private double score = -1; + private String id = ""; private String style = ""; private String url = ""; private String thumb = ""; @@ -39,7 +39,7 @@ public class Grid { * @param tags The Grid's Tags * @param author The Grid's Author */ - public Grid(int id, double score, SGDBStyles style, String url, String thumb, ArrayList tags, Author author) { + public Grid(String id, double score, SGDBStyles style, String url, String thumb, ArrayList tags, Author author) { switch (style) { case Alternate: { this.style = "alternate"; @@ -76,15 +76,32 @@ public Grid(int id, double score, SGDBStyles style, String url, String thumb, Ar * @param styles An array of styles for filtering the results * @return An ArrayList of Grid objects */ - public static ArrayList getGridsById(int id, SGDBIdTypes idType, SGDBStyles[] styles) { + public static ArrayList getGridsById(String id, SGDBIdTypes idType, SGDBStyles[] styles) { ArrayList grids = new ArrayList<>(); String apiUrl = ""; String stylesStr = buildStylesString(styles); - if (idType == SGDBIdTypes.GameId) { - apiUrl = "grids/game/"; - } else if (idType == SGDBIdTypes.SteamAppId) { - apiUrl = "grids/steam/"; + switch (idType) { + case GameId: + apiUrl = "grids/game/"; + break; + case SteamAppId: + apiUrl = "grids/steam/"; + break; + case EgsId: + apiUrl = "grids/egs/"; + break; + case UplayId: + apiUrl = "grids/uplay/"; + break; + case OriginId: + apiUrl = "grids/origin/"; + break; + case GogId: + apiUrl = "grids/gog/"; + break; + default: + break; } JSONObject json = SGDBConnectionManager.getJSON(apiUrl + id + "?styles=" + stylesStr); @@ -128,7 +145,7 @@ public static ArrayList getGridsById(int id, SGDBIdTypes idType, SGDBStyle break; } - Grid grid = new Grid(jsonGrid.getInt("id"), jsonGrid.getDouble("score"), style, + Grid grid = new Grid(String.valueOf(jsonGrid.getInt("id")), jsonGrid.getDouble("score"), style, jsonGrid.getString("url"), jsonGrid.getString("thumb"), tagStrings, authorObject); grids.add(grid); } @@ -144,7 +161,7 @@ public static ArrayList getGridsById(int id, SGDBIdTypes idType, SGDBStyle * @param idType The type of ID (SteamAppID or GameID) * @return An ArrayList of Grid objects */ - public static ArrayList getGridsById(int id, SGDBIdTypes idType) { + public static ArrayList getGridsById(String id, SGDBIdTypes idType) { ArrayList grids = new ArrayList<>(); grids = getGridsById(id, idType, new SGDBStyles[0]); return grids; @@ -157,7 +174,7 @@ public static ArrayList getGridsById(int id, SGDBIdTypes idType) { * @param styles An array of SGDBStyles for filtering Grids * @return An ArrayList of Grid objects */ - public static ArrayList getGridsBySteamAppId(int steamAppId, SGDBStyles[] styles) { + public static ArrayList getGridsBySteamAppId(String steamAppId, SGDBStyles[] styles) { ArrayList grids = new ArrayList<>(); grids = getGridsById(steamAppId, SGDBIdTypes.SteamAppId, styles); return grids; @@ -169,12 +186,112 @@ public static ArrayList getGridsBySteamAppId(int steamAppId, SGDBStyles[] * @param steamAppId The SteamAppID of a Game * @return An ArrayList of Grid objects */ - public static ArrayList getGridsBySteamAppId(int steamAppId) { + public static ArrayList getGridsBySteamAppId(String steamAppId) { ArrayList grids = new ArrayList<>(); grids = getGridsById(steamAppId, SGDBIdTypes.SteamAppId); return grids; } + /** + * Get Grids by OriginId. + * + * @param originId The OriginId of a Game + * @param styles An array of SGDBStyles for filtering Grids + * @return An ArrayList of Grid objects + */ + public static ArrayList getGridsByOriginId(String originId, SGDBStyles[] styles) { + ArrayList grids = new ArrayList<>(); + grids = getGridsById(originId, SGDBIdTypes.OriginId, styles); + return grids; + } + + /** + * Get Grids by OriginId. + * + * @param originId The OriginId of a Game + * @return An ArrayList of Grid objects + */ + public static ArrayList getGridsByOriginId(String originId) { + ArrayList grids = new ArrayList<>(); + grids = getGridsById(originId, SGDBIdTypes.OriginId); + return grids; + } + + /** + * Get Grids by UplayId. + * + * @param uplayId The UplayId of a Game + * @param styles An array of SGDBStyles for filtering Grids + * @return An ArrayList of Grid objects + */ + public static ArrayList getGridsByUplayId(String uplayId, SGDBStyles[] styles) { + ArrayList grids = new ArrayList<>(); + grids = getGridsById(uplayId, SGDBIdTypes.UplayId, styles); + return grids; + } + + /** + * Get Grids by UplayId. + * + * @param uplayId The UplayId of a Game + * @return An ArrayList of Grid objects + */ + public static ArrayList getGridsByUplayId(String uplayId) { + ArrayList grids = new ArrayList<>(); + grids = getGridsById(uplayId, SGDBIdTypes.UplayId); + return grids; + } + + /** + * Get Grids by EgsId. + * + * @param egsId The EgsId of a Game + * @param styles An array of SGDBStyles for filtering Grids + * @return An ArrayList of Grid objects + */ + public static ArrayList getGridsByEgsId(String egsId, SGDBStyles[] styles) { + ArrayList grids = new ArrayList<>(); + grids = getGridsById(egsId, SGDBIdTypes.EgsId, styles); + return grids; + } + + /** + * Get Grids by EgsId. + * + * @param egsId The EgsId of a Game + * @return An ArrayList of Grid objects + */ + public static ArrayList getGridsByEgsId(String egsId) { + ArrayList grids = new ArrayList<>(); + grids = getGridsById(egsId, SGDBIdTypes.EgsId); + return grids; + } + + /** + * Get Grids by GogId. + * + * @param gogId The GogId of a Game + * @param styles An array of SGDBStyles for filtering Grids + * @return An ArrayList of Grid objects + */ + public static ArrayList getGridsByGogId(String gogId, SGDBStyles[] styles) { + ArrayList grids = new ArrayList<>(); + grids = getGridsById(gogId, SGDBIdTypes.GogId, styles); + return grids; + } + + /** + * Get Grids by GogId. + * + * @param gogId The GogId of a Game + * @return An ArrayList of Grid objects + */ + public static ArrayList getGridsByGogId(String gogId) { + ArrayList grids = new ArrayList<>(); + grids = getGridsById(gogId, SGDBIdTypes.GogId); + return grids; + } + /** * Get Grids by GameID. * @@ -182,7 +299,7 @@ public static ArrayList getGridsBySteamAppId(int steamAppId) { * @param styles An array of SGDBStyles for filtering Grids * @return An ArrayList of Grid objects */ - public static ArrayList getGridsByGameId(int gameId, SGDBStyles[] styles) { + public static ArrayList getGridsByGameId(String gameId, SGDBStyles[] styles) { ArrayList grids = new ArrayList<>(); grids = getGridsById(gameId, SGDBIdTypes.GameId, styles); return grids; @@ -194,7 +311,7 @@ public static ArrayList getGridsByGameId(int gameId, SGDBStyles[] styles) * @param gameId The GameID of a Game * @return An ArrayList of Grid objects */ - public static ArrayList getGridsByGameId(int gameId) { + public static ArrayList getGridsByGameId(String gameId) { ArrayList grids = new ArrayList<>(); grids = getGridsById(gameId, SGDBIdTypes.GameId); return grids; @@ -207,7 +324,7 @@ public static ArrayList getGridsByGameId(int gameId) { * @param styles An array of SGDBStyles for filtering Grids * @return A JSONObject object with the Grid data */ - public static JSONObject getGridJSONBySteamAppId(int steamAppId, SGDBStyles[] styles) { + public static JSONObject getGridJSONBySteamAppId(String steamAppId, SGDBStyles[] styles) { String stylesStr = buildStylesString(styles); JSONObject json = SGDBConnectionManager.getJSON("grids/steam/" + steamAppId + "?styles=" + stylesStr); return json; @@ -219,11 +336,107 @@ public static JSONObject getGridJSONBySteamAppId(int steamAppId, SGDBStyles[] st * @param steamAppId A Game's SteamAppId * @return A JSONObject object with the Grid data */ - public static JSONObject getGridJSONBySteamAppId(int steamAppId) { + public static JSONObject getGridJSONBySteamAppId(String steamAppId) { JSONObject json = SGDBConnectionManager.getJSON("grids/steam/" + steamAppId); return json; } + /** + * Get a JSONObject of a Grids array from an OriginId. + * + * @param originId A Game's OriginId + * @param styles An array of SGDBStyles for filtering Grids + * @return A JSONObject object with the Grid data + */ + public static JSONObject getGridJSONByOriginId(String originId, SGDBStyles[] styles) { + String stylesStr = buildStylesString(styles); + JSONObject json = SGDBConnectionManager.getJSON("grids/origin/" + originId + "?styles=" + stylesStr); + return json; + } + + /** + * Get a JSONObject of a Grids array from an OriginId. + * + * @param originId A Game's OriginId + * @return A JSONObject object with the Grid data + */ + public static JSONObject getGridJSONByOriginId(String originId) { + JSONObject json = SGDBConnectionManager.getJSON("grids/origin/" + originId); + return json; + } + + /** + * Get a JSONObject of a Grids array from an EgsId. + * + * @param egsId A Game's EgsId + * @param styles An array of SGDBStyles for filtering Grids + * @return A JSONObject object with the Grid data + */ + public static JSONObject getGridJSONByEgsId(String egsId, SGDBStyles[] styles) { + String stylesStr = buildStylesString(styles); + JSONObject json = SGDBConnectionManager.getJSON("grids/egs/" + egsId + "?styles=" + stylesStr); + return json; + } + + /** + * Get a JSONObject of a Grids array from an EgsId(. + * + * @param egsId A Game's EgsId( + * @return A JSONObject object with the Grid data + */ + public static JSONObject getGridJSONByEgsId(String egsId) { + JSONObject json = SGDBConnectionManager.getJSON("grids/egs/" + egsId); + return json; + } + + /** + * Get a JSONObject of a Grids array from a UplayId. + * + * @param uplayId A Game's UplayId + * @param styles An array of SGDBStyles for filtering Grids + * @return A JSONObject object with the Grid data + */ + public static JSONObject getGridJSONByUplayId(String uplayId, SGDBStyles[] styles) { + String stylesStr = buildStylesString(styles); + JSONObject json = SGDBConnectionManager.getJSON("grids/uplay/" + uplayId + "?styles=" + stylesStr); + return json; + } + + /** + * Get a JSONObject of a Grids array from a UplayId. + * + * @param uplayId A Game's UplayId + * @return A JSONObject object with the Grid data + */ + public static JSONObject getGridJSONByUplayId(String uplayId) { + JSONObject json = SGDBConnectionManager.getJSON("grids/uplay/" + uplayId); + return json; + } + + /** + * Get a JSONObject of a Grids array from a GogId. + * + * @param gogId A Game's GogId + * @param styles An array of SGDBStyles for filtering Grids + * @return A JSONObject object with the Grid data + */ + public static JSONObject getGridJSONByGogId(String gogId, SGDBStyles[] styles) { + String stylesStr = buildStylesString(styles); + JSONObject json = SGDBConnectionManager.getJSON("grids/gog/" + gogId + "?styles=" + stylesStr); + return json; + } + + /** + * Get a JSONObject of a Grids array from a GogId. + * + * @param gogId A Game's GogId + * @return A JSONObject object with the Grid data + */ + public static JSONObject getGridJSONByGogId(String gogId) { + JSONObject json = SGDBConnectionManager.getJSON("grids/gog/" + gogId); + return json; + } + /** * Get a JSONObject of a Grids array from a GameId. * @@ -231,7 +444,7 @@ public static JSONObject getGridJSONBySteamAppId(int steamAppId) { * @param styles An array of SGDBStyles for filtering Grids * @return A JSONObject object with the Grid data */ - public static JSONObject getGridJSONByGameId(int gameId, SGDBStyles[] styles) { + public static JSONObject getGridJSONByGameId(String gameId, SGDBStyles[] styles) { String stylesStr = buildStylesString(styles); JSONObject json = SGDBConnectionManager.getJSON("grids/game/" + gameId + "?styles=" + stylesStr); return json; @@ -243,24 +456,24 @@ public static JSONObject getGridJSONByGameId(int gameId, SGDBStyles[] styles) { * @param gameId A Game's GameId * @return A JSONObject object with the Grid data */ - public static JSONObject getGridJSONByGameId(int gameId) { + public static JSONObject getGridJSONByGameId(String gameId) { JSONObject json = SGDBConnectionManager.getJSON("grids/game/" + gameId); return json; } /** * Upload a Grid by entering its required data. - * + * * @param gameId The GameID of a Game * @param style The style of the Grid * @param filePath The file path of an image * @return True if the upload was successful, false if otherwise */ - public static boolean uploadGrid(int gameId, SGDBStyles style, String filePath) { + public static boolean uploadGrid(String gameId, SGDBStyles style, String filePath) { File grid = new File(filePath); - + String styleStr = ""; - + switch (style) { case Alternate: { styleStr = "alternate"; @@ -286,19 +499,19 @@ public static boolean uploadGrid(int gameId, SGDBStyles style, String filePath) params.put("game_id", gameId); params.put("style", styleStr); params.put("grid", grid.toPath()); - + JSONObject json = SGDBConnectionManager.postMultipart("grids", params); return json.getBoolean("success"); } - + /** * Vote for a Grid using its ID. * * @param vote The vote's value (True = Upvote, False = Downvote) * @param gridID The Grid's ID */ - public static void vote(boolean vote, int gridID) { + public static void vote(boolean vote, String gridID) { if (vote) { upvoteById(gridID); } else { @@ -338,7 +551,7 @@ public void downvote() { * * @param gridId The Grid's ID */ - public static void upvoteById(int gridId) { + public static void upvoteById(String gridId) { SGDBConnectionManager.post("grids/vote/up/" + gridId); } @@ -347,7 +560,7 @@ public static void upvoteById(int gridId) { * * @param gridId The Grid's ID */ - public static void downvoteById(int gridId) { + public static void downvoteById(String gridId) { SGDBConnectionManager.post("grids/vote/down/" + gridId); } @@ -360,19 +573,19 @@ public void delete() { /** * Delete a Grid using its ID. - * + * * @param gridId The Grid's ID */ - public static void deleteByGridID(int gridId) { + public static void deleteByGridID(String gridId) { SGDBConnectionManager.delete("grids/" + gridId); } /** * Delete multiple Grids using an array of IDs. - * + * * @param gridIds The Grid's ID */ - public static void deleteByGridIDs(int[] gridIds) { + public static void deleteByGridIDs(String[] gridIds) { for (int i = 0; i < gridIds.length; i++) { deleteByGridID(gridIds[i]); } @@ -383,7 +596,7 @@ public static void deleteByGridIDs(int[] gridIds) { * * @return The Grid's ID */ - public int getId() { + public String getId() { return id; } @@ -442,7 +655,10 @@ public Author getAuthor() { } /** - * + * Build a string from and SGDBStyles array. + * + * @param styles The SGDBStyles array to be converted + * @return String containing the given SGDBStyles */ private static String buildStylesString(SGDBStyles[] styles) { String stylesStr = ""; @@ -477,5 +693,4 @@ private static String buildStylesString(SGDBStyles[] styles) { return stylesStr; } - } diff --git a/src/main/java/com/steamgriddb/Search.java b/src/main/java/com/steamgriddb/Search.java index d39b58c..945e607 100644 --- a/src/main/java/com/steamgriddb/Search.java +++ b/src/main/java/com/steamgriddb/Search.java @@ -35,7 +35,7 @@ public static ArrayList searchGamesByName(String searchTerm) { ArrayList games = new ArrayList<>(); JSONArray gamesArray = json.getJSONArray("data"); for (int i = 0; i < gamesArray.length(); i++) { - games.add(new Game(gamesArray.getJSONObject(i).getInt("id"), SGDBIdTypes.GameId)); + games.add(new Game(String.valueOf(gamesArray.getJSONObject(i).getInt("id")), SGDBIdTypes.GameId)); } return games; }