diff --git a/src/main/java/net/jrtechs/www/SteamAPI/APIConnection.java b/src/main/java/net/jrtechs/www/SteamAPI/APIConnection.java index 653a174..03c6060 100644 --- a/src/main/java/net/jrtechs/www/SteamAPI/APIConnection.java +++ b/src/main/java/net/jrtechs/www/SteamAPI/APIConnection.java @@ -2,6 +2,13 @@ package net.jrtechs.www.SteamAPI; import net.jrtechs.www.utils.ConfigLoader; +import net.jrtechs.www.utils.WebScraper; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + /** * Class which is used to pull information from the Steam api * @@ -34,4 +41,52 @@ public class APIConnection apiKey = "?key=" + conf.getValue("api"); } + + + /** + * Returns a list of the UIDs of all the players friends + * + * @param steamid + * @return + */ + public List getFriends(String steamid) + { + List friendsId = new ArrayList<>(); + + new JSONObject(WebScraper + .getWebsite(this.baseURL + this.friendListURL + + this.apiKey + "&steamid=" + steamid)) + .getJSONObject("friendslist") + .getJSONArray("friends").toList() + .forEach(f-> + friendsId.add(((HashMap)(f)).get("steamid")) + ); + return friendsId; + } + + + /** + * Returns the name of the player with a specific steam id + * + * @param steamid the steam id of player + * @return + */ + public String getPlayerName(String steamid) + { + return ((HashMap) new JSONObject(WebScraper + .getWebsite(this.baseURL + this.playerInfoURL + + this.apiKey + "&steamids=" + steamid)) + .getJSONObject("response") + .getJSONArray("players") + .toList().stream().findAny().get()).get("personaname"); + } + + public static void main(String[] args) + { + APIConnection con = new APIConnection(); + + con.getFriends("76561198188400721").forEach(System.out::println); + + System.out.println(con.getPlayerName("76561198188400721")); + } }