All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ibasco.agql.protocols.valve.steam.webapi.interfaces.SteamUserStats Maven / Gradle / Ivy

There is a newer version: 1.2.2
Show newest version
/*
 * MIT License
 *
 * Copyright (c) 2016 Asynchronous Game Query Library
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

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.*;
import com.ibasco.agql.protocols.valve.steam.webapi.pojos.*;

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.
 */
public class SteamUserStats extends SteamWebApiInterface {
    public SteamUserStats(SteamWebApiClient client) {
        super(client);
    }

    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);
        });
    }

    //TODO: Figure out what that damn name[0] parameter should be
    public CompletableFuture> getGlobalStatsForGame(int appId, int count, String name) {
        CompletableFuture json = sendRequest(new GetGlobalStatsForGame(VERSION_2, appId, count, name));
        return json.thenApply(root -> null);
    }

    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;
        });
    }

    public CompletableFuture getNumberOfCurrentPlayers(int appId) {
        CompletableFuture json = sendRequest(new GetNumberOfCurrentPlayers(VERSION_1, appId));
        return json.thenApply(root -> root.getAsJsonObject("response").getAsJsonPrimitive("player_count").getAsInt());
    }

    public CompletableFuture> getPlayerAchievements(long steamId, int appId) {
        return getPlayerAchievements(steamId, appId, null);
    }

    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));
    }

    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