Browse Source

Added connection to steam api to get names and friends lists.

pull/8/head
jrtechs 6 years ago
parent
commit
c658ed32cf
1 changed files with 55 additions and 0 deletions
  1. +55
    -0
      src/main/java/net/jrtechs/www/SteamAPI/APIConnection.java

+ 55
- 0
src/main/java/net/jrtechs/www/SteamAPI/APIConnection.java View File

@ -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<String> getFriends(String steamid)
{
List<String> 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<String, String>)(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<String, String>) 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"));
}
}

Loading…
Cancel
Save