com.ibasco.agql.protocols.valve.steam.webapi.interfaces.SteamUserStats Maven / Gradle / Ivy
/*
* Copyright (c) 2022 Asynchronous Game Query Library
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ibasco.agql.protocols.valve.steam.webapi.interfaces;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.ibasco.agql.protocols.valve.steam.webapi.SteamWebApiClient;
import com.ibasco.agql.protocols.valve.steam.webapi.SteamWebApiInterface;
import com.ibasco.agql.protocols.valve.steam.webapi.interfaces.userstats.GetGlobalAchievementPercentagesForApp;
import com.ibasco.agql.protocols.valve.steam.webapi.interfaces.userstats.GetGlobalStatsForGame;
import com.ibasco.agql.protocols.valve.steam.webapi.interfaces.userstats.GetNumberOfCurrentPlayers;
import com.ibasco.agql.protocols.valve.steam.webapi.interfaces.userstats.GetPlayerAchievements;
import com.ibasco.agql.protocols.valve.steam.webapi.interfaces.userstats.GetSchemaForGame;
import com.ibasco.agql.protocols.valve.steam.webapi.interfaces.userstats.GetUserStatsForGame;
import com.ibasco.agql.protocols.valve.steam.webapi.pojos.SteamGameAchievement;
import com.ibasco.agql.protocols.valve.steam.webapi.pojos.SteamGameAchievementSchema;
import com.ibasco.agql.protocols.valve.steam.webapi.pojos.SteamGameStatsSchema;
import com.ibasco.agql.protocols.valve.steam.webapi.pojos.SteamGameStatsSchemaInfo;
import com.ibasco.agql.protocols.valve.steam.webapi.pojos.SteamPlayerAchievement;
import com.ibasco.agql.protocols.valve.steam.webapi.pojos.SteamPlayerStats;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
/**
* Created by raffy on 10/26/2016.
*
* @author Rafael Luis Ibasco
*/
public class SteamUserStats extends SteamWebApiInterface {
/**
* Constructor for SteamUserStats.
*
* @param client
* a {@link com.ibasco.agql.protocols.valve.steam.webapi.SteamWebApiClient} object
*/
public SteamUserStats(SteamWebApiClient client) {
super(client);
}
/**
* getGlobalAchievementPercentagesForApp.
*
* @param appId
* a int
*
* @return a {@link java.util.concurrent.CompletableFuture} object
*/
public CompletableFuture> getGlobalAchievementPercentagesForApp(int appId) {
CompletableFuture json = sendRequest(new GetGlobalAchievementPercentagesForApp(VERSION_2, appId));
return json.thenApply(root -> {
JsonObject achievementPct = root.getAsJsonObject("achievementpercentages");
JsonArray achievements = achievementPct.getAsJsonArray("achievements");
Type type = new TypeToken>() {
}.getType();
return builder().fromJson(achievements, type);
});
}
/**
* getGlobalStatsForGame.
*
* @param appId
* a int
* @param count
* a int
* @param name
* a {@link java.lang.String} object
*
* @return a {@link java.util.concurrent.CompletableFuture} object
*/
public CompletableFuture> getGlobalStatsForGame(int appId, int count, String name) {
CompletableFuture json = sendRequest(new GetGlobalStatsForGame(VERSION_2, appId, count, name));
return json.thenApply(root -> null);
}
/**
* getSchemaForGame.
*
* @param appId
* a int
*
* @return a {@link java.util.concurrent.CompletableFuture} object
*/
public CompletableFuture getSchemaForGame(int appId) {
CompletableFuture json = sendRequest(new GetSchemaForGame(VERSION_2, appId));
return json.thenApply(root -> {
SteamGameStatsSchemaInfo info = new SteamGameStatsSchemaInfo();
JsonObject availableGameStats = root.getAsJsonObject("game").getAsJsonObject("availableGameStats");
Type achievementsSchemaType = new TypeToken>() {}.getType();
Type statsSchemaType = new TypeToken>() {}.getType();
info.setAchievementSchemaList(fromJson(availableGameStats.getAsJsonArray("achievements"), achievementsSchemaType));
info.setStatsSchemaList(fromJson(availableGameStats.getAsJsonArray("stats"), statsSchemaType));
return info;
});
}
/**
* getNumberOfCurrentPlayers.
*
* @param appId
* a int
*
* @return a {@link java.util.concurrent.CompletableFuture} object
*/
public CompletableFuture getNumberOfCurrentPlayers(int appId) {
CompletableFuture json = sendRequest(new GetNumberOfCurrentPlayers(VERSION_1, appId));
return json.thenApply(root -> root.getAsJsonObject("response").getAsJsonPrimitive("player_count").getAsInt());
}
/**
* getPlayerAchievements.
*
* @param steamId
* a long
* @param appId
* a int
*
* @return a {@link java.util.concurrent.CompletableFuture} object
*/
public CompletableFuture> getPlayerAchievements(long steamId, int appId) {
return getPlayerAchievements(steamId, appId, null);
}
/**
* getPlayerAchievements.
*
* @param steamId
* a long
* @param appId
* a int
* @param language
* a {@link java.lang.String} object
*
* @return a {@link java.util.concurrent.CompletableFuture} object
*/
public CompletableFuture> getPlayerAchievements(long steamId, int appId, String language) {
CompletableFuture json = sendRequest(new GetPlayerAchievements(VERSION_1, steamId, appId, language));
return json.thenApply(r -> asCollectionOf(SteamPlayerAchievement.class, "achievements", r.getAsJsonObject("playerstats"), ArrayList.class, true));
}
/**
* getUserStatsForGame.
*
* @param steamId
* a long
* @param appId
* a int
*
* @return a {@link java.util.concurrent.CompletableFuture} object
*/
public CompletableFuture getUserStatsForGame(long steamId, int appId) {
CompletableFuture json = sendRequest(new GetUserStatsForGame(VERSION_2, steamId, appId));
return json.thenApply(root -> fromJson(root.getAsJsonObject("playerstats"), SteamPlayerStats.class));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy