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

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

There is a newer version: 1.2.2
Show newest version
/*
 * 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.core.exceptions.WebException;
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.gameservers.CreateAccount;
import com.ibasco.agql.protocols.valve.steam.webapi.interfaces.gameservers.DeleteAccount;
import com.ibasco.agql.protocols.valve.steam.webapi.interfaces.gameservers.GetAccountList;
import com.ibasco.agql.protocols.valve.steam.webapi.interfaces.gameservers.GetAccountPublicInfo;
import com.ibasco.agql.protocols.valve.steam.webapi.interfaces.gameservers.GetServerList;
import com.ibasco.agql.protocols.valve.steam.webapi.interfaces.gameservers.QueryLoginToken;
import com.ibasco.agql.protocols.valve.steam.webapi.interfaces.gameservers.ResetLoginToken;
import com.ibasco.agql.protocols.valve.steam.webapi.interfaces.gameservers.SetMemo;
import com.ibasco.agql.protocols.valve.steam.webapi.interfaces.gameservers.pojos.GameServer;
import com.ibasco.agql.protocols.valve.steam.webapi.interfaces.gameservers.pojos.GameServerAccount;
import com.ibasco.agql.protocols.valve.steam.webapi.interfaces.gameservers.pojos.GameServerAccountPublicInfo;
import com.ibasco.agql.protocols.valve.steam.webapi.interfaces.gameservers.pojos.LoginTokenStatus;
import com.ibasco.agql.protocols.valve.steam.webapi.interfaces.gameservers.pojos.NewGameServerAccount;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;

public class GameServersService extends SteamWebApiInterface {

    /**
     * 

Default Constructor

* * @param client * A {@link SteamWebApiClient} instance */ public GameServersService(SteamWebApiClient client) { super(client); } public CompletableFuture createAccount(int appId, String memo) { CompletableFuture json = sendRequest(new CreateAccount(VERSION_1, appId, memo)); return json.thenApply(this::getResponse).thenApply(response -> { Type listType = new TypeToken() {}.getType(); return builder().fromJson(response, listType); }); } private JsonObject getResponse(JsonObject element) { if (!element.has("response")) throw new WebException("Missing 'response' object"); return element.get("response").getAsJsonObject(); } public CompletableFuture deleteAccount(long steamId) { return sendRequest(new DeleteAccount(VERSION_1, steamId)); } public CompletableFuture getAccountList() { CompletableFuture json = sendRequest(new GetAccountList(VERSION_1)); return json.thenApply(this::getResponse).thenApply(response -> builder().fromJson(response, GameServerAccount.class)); } public CompletableFuture getAccountPublicInfo(long steamId) { CompletableFuture json = sendRequest(new GetAccountPublicInfo(VERSION_1, steamId)); return json.thenApply(this::getResponse).thenApply(response -> builder().fromJson(response, GameServerAccountPublicInfo.class)); } public CompletableFuture> getServerList(String filter) { return getServerList(filter, -1); } public CompletableFuture> getServerList(String filter, int limit) { CompletableFuture json = sendRequest(new GetServerList(VERSION_1, filter, limit)); return json.thenApply(this::getResponse).thenApply(new Function>() { @Override public List apply(JsonObject response) { List responseList; if (!response.has("servers")) { responseList = new ArrayList<>(); return responseList; } else { JsonArray array = response.getAsJsonArray("servers"); Type listType = new TypeToken>() {}.getType(); return builder().fromJson(array, listType); } } }); } public CompletableFuture resetLoginToken(long steamId) { CompletableFuture json = sendRequest(new ResetLoginToken(VERSION_1, steamId)); return json.thenApply(this::getResponse).thenApply(response -> { if (!response.has("login_token")) return null; return response.get("login_token").getAsString(); }); } public CompletableFuture setMemo(long steamId, String memo) { CompletableFuture json = sendRequest(new SetMemo(VERSION_1, steamId, memo)); return json.thenAccept(this::getResponse); } public CompletableFuture queryLoginTokenStatus(String loginToken) { CompletableFuture json = sendRequest(new QueryLoginToken(VERSION_1, loginToken)); return json.thenApply(this::getResponse).thenApply(response -> builder().fromJson(response, LoginTokenStatus.class)); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy