Browse Source

Added methods in api connection to download game information.

game_data
jrtechs 4 years ago
parent
commit
d51c202ae5
3 changed files with 88 additions and 20 deletions
  1. +3
    -18
      pom.xml
  2. +35
    -2
      src/main/java/net/jrtechs/www/SteamAPI/APIConnection.java
  3. +50
    -0
      src/main/java/net/jrtechs/www/server/Game.java

+ 3
- 18
pom.xml View File

@ -29,25 +29,10 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/com.tinkerpop/gremlin-core -->
<dependency> <dependency>
<groupId>com.tinkerpop</groupId>
<artifactId>gremlin-core</artifactId>
<version>3.0.0.M7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tinkerpop/gremlin-driver -->
<dependency>
<groupId>org.apache.tinkerpop</groupId>
<artifactId>gremlin-driver</artifactId>
<version>3.3.3</version>
</dependency>
<dependency>
<groupId>org.apache.tinkerpop</groupId>
<artifactId>tinkergraph-gremlin</artifactId>
<version>3.3.3</version>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph-berkeleyje</artifactId>
<version>0.3.1</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.json/json --> <!-- https://mvnrepository.com/artifact/org.json/json -->

+ 35
- 2
src/main/java/net/jrtechs/www/SteamAPI/APIConnection.java View File

@ -1,5 +1,6 @@
package net.jrtechs.www.SteamAPI; package net.jrtechs.www.SteamAPI;
import net.jrtechs.www.server.Game;
import net.jrtechs.www.server.Player; import net.jrtechs.www.server.Player;
import net.jrtechs.www.utils.ConfigLoader; import net.jrtechs.www.utils.ConfigLoader;
@ -8,14 +9,19 @@ import net.jrtechs.www.webCrawler.APIThrottler;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import javax.json.JsonArray;
import javax.json.JsonObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.IntStream;
/** /**
* Class which is used to pull information from the Steam api * Class which is used to pull information from the Steam api
* *
* Documentation at https://developer.valvesoftware.com/wiki/Steam_Web_API
*
* @author Jeffery Russell 5-26-18 * @author Jeffery Russell 5-26-18
*/ */
public class APIConnection public class APIConnection
@ -28,6 +34,8 @@ public class APIConnection
private final String friendListURL = "/ISteamUser/GetFriendList/v0001/"; private final String friendListURL = "/ISteamUser/GetFriendList/v0001/";
private final String gamesListURL = "/IPlayerService/GetOwnedGames/v0001/";
/** Path to conf file(from within the conf folder) **/ /** Path to conf file(from within the conf folder) **/
private final String confPath = "SteamAPIKey.json"; private final String confPath = "SteamAPIKey.json";
@ -57,6 +65,7 @@ public class APIConnection
*/ */
public String querySteamAPI(String url) public String querySteamAPI(String url)
{ {
System.out.println(url);
boolean downloaded = false; boolean downloaded = false;
String apiData = ""; String apiData = "";
while(!downloaded) while(!downloaded)
@ -111,6 +120,29 @@ public class APIConnection
} }
public List<Game> getGames(String steamID)
{
List<Game> games = new ArrayList<>();
String apiData = this.querySteamAPI(this.baseURL + this.gamesListURL +
this.apiKey + "&steamid=" + steamID +
"&include_appinfo=true&include_played_free_games=true");
if(apiData.isEmpty())
return games;
JSONObject object = new JSONObject(apiData);
System.out.println(object);
if(object.has("response"))
{
JSONArray gamesJ = object.getJSONObject("response").getJSONArray("games");
IntStream.range(0, gamesJ.length()).forEach(i ->
games.add(new Game(gamesJ.getJSONObject(i))));
}
return games;
}
/** /**
* Returns a list of the UIDs of all the players friends * Returns a list of the UIDs of all the players friends
* *
@ -257,8 +289,9 @@ public class APIConnection
APIConnection con = new APIConnection(); APIConnection con = new APIConnection();
//steam id of jrtechs //steam id of jrtechs
con.getFriends("76561198188400721").forEach(System.out::println);
//con.getFriends("76561198188400721").forEach(System.out::println);
System.out.println(con.getSingle("76561198188400721"));
//System.out.println(con.getSingle("76561198188400721"));
System.out.println(con.getGames("76561198188400721"));
} }
} }

+ 50
- 0
src/main/java/net/jrtechs/www/server/Game.java View File

@ -0,0 +1,50 @@
package net.jrtechs.www.server;
import org.json.JSONObject;
import javax.json.JsonObject;
/**
* Example URL: http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=XXXXXXXXXXXXXXXXX&steamid=76561197960434622&format=json
*/
public class Game
{
public static String KEY_DB = "game";
public static String KEY_STEAM_GAME_ID = "appid";
public static String KEY_GAME_NAME = "name";
public static String KEY_GAME_ICON = "img_icon_url";
public static String KEY_GAME_LOGO = "img_logo_url";
//other
public static String KEY_PLAY_TIME = "playtime_forever";
private Integer appID;
private String icon;
private String logo;
private String name;
private Integer timePlayed;
public Game(JSONObject g)
{
this.appID = g.getInt(Game.KEY_STEAM_GAME_ID);
this.name = g.getString(KEY_GAME_NAME);
this.icon = g.getString(KEY_GAME_ICON);
this.logo = g.getString(KEY_GAME_LOGO);
this.timePlayed = g.getInt(KEY_PLAY_TIME);
}
@Override
public String toString()
{
return "Game{" +
"appID=" + appID +
", icon='" + icon + '\'' +
", logo='" + logo + '\'' +
", name='" + name + '\'' +
", timePlayed=" + timePlayed +
'}';
}
}

Loading…
Cancel
Save