com.ibasco.agql.protocols.supercell.coc.webapi.interfaces.CocLocations 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.supercell.coc.webapi.interfaces;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.ibasco.agql.protocols.supercell.coc.webapi.CocWebApiClient;
import com.ibasco.agql.protocols.supercell.coc.webapi.CocWebApiInterface;
import com.ibasco.agql.protocols.supercell.coc.webapi.interfaces.locations.GetClanRankingsForLoc;
import com.ibasco.agql.protocols.supercell.coc.webapi.interfaces.locations.GetLocationInfo;
import com.ibasco.agql.protocols.supercell.coc.webapi.interfaces.locations.GetLocations;
import com.ibasco.agql.protocols.supercell.coc.webapi.interfaces.locations.GetPlayerRankingsForLoc;
import com.ibasco.agql.protocols.supercell.coc.webapi.pojos.CocClanRankInfo;
import com.ibasco.agql.protocols.supercell.coc.webapi.pojos.CocLocation;
import com.ibasco.agql.protocols.supercell.coc.webapi.pojos.CocPlayerRankInfo;
import org.jetbrains.annotations.ApiStatus;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
/**
* A Web API Implementation of the Location interface. Contains methods for clan/player inquiries based on
* location.
*
* @author Rafael Luis Ibasco
* @see Clash of Clans API - Locations
*/
@Deprecated
@ApiStatus.ScheduledForRemoval
public class CocLocations extends CocWebApiInterface {
/**
* Default Constructor
*
* @param client
* A {@link com.ibasco.agql.protocols.supercell.coc.webapi.CocWebApiClient} instance
*/
public CocLocations(CocWebApiClient client) {
super(client);
}
/**
* List all available locations
*
* @return A {@link java.util.concurrent.CompletableFuture} containing a future result for a {@link java.util.List} of {@link com.ibasco.agql.protocols.supercell.coc.webapi.pojos.CocLocation}
*/
public CompletableFuture> getLocations() {
return getLocations(-1, -1, -1);
}
/**
* List all available locations
*
* @param limit
* An {@link java.lang.Integer} limiting the number of records returned
* @param before
* (optional) An {@link java.lang.Integer} that indicates to return only items that occur before this marker.
* Before marker can be found from the response, inside the 'paging' property. Note that only after
* or before can be specified for a request, not both. Otherwise use -1 to disregard.
* @param after
* (optional) An {@link java.lang.Integer} that indicates to return only items that occur after this marker.
* After marker can be found from the response, inside the 'paging' property. Note that only after
* or before can be specified for a request, not both. Otherwise use -1 to disregard.
*
* @return A {@link java.util.concurrent.CompletableFuture} containing a future result for a {@link java.util.List} of {@link com.ibasco.agql.protocols.supercell.coc.webapi.pojos.CocLocation}
*/
public CompletableFuture> getLocations(int limit, int before, int after) {
CompletableFuture json = sendRequest(new GetLocations(VERSION_1, limit, before, after));
return json.thenApply(new Function>() {
@Override
public List apply(JsonObject root) {
JsonArray items = root.getAsJsonArray("items");
return builder().fromJson(items, new TypeToken>() {
}.getType());
}
});
}
/**
* List all available locations
*
* @param limit
* An {@link java.lang.Integer} limiting the number of records returned
*
* @return A {@link java.util.concurrent.CompletableFuture} containing a future result for a {@link java.util.List} of {@link com.ibasco.agql.protocols.supercell.coc.webapi.pojos.CocLocation}
*/
public CompletableFuture> getLocations(int limit) {
return getLocations(limit, -1, -1);
}
/**
* Get information about specific location
*
* @param locationId
* An {@link java.lang.Integer} representing the identifier of the location to retrieve.
*
* @return A {@link java.util.concurrent.CompletableFuture} containing a future result of {@link com.ibasco.agql.protocols.supercell.coc.webapi.pojos.CocLocation}
*
* @see CocLocations#getLocations()
*/
public CompletableFuture getLocationInfo(int locationId) {
CompletableFuture json = sendRequest(new GetLocationInfo(VERSION_1, locationId));
return json.thenApply(root -> builder().fromJson(root, CocLocation.class));
}
/**
* Get clan rankings for a specific location
*
* @param locationId
* An {@link java.lang.Integer} representing the identifier of the location to retrieve.
*
* @return A {@link java.util.concurrent.CompletableFuture} containing a future result of a {@link java.util.List} of {@link com.ibasco.agql.protocols.supercell.coc.webapi.pojos.CocClanRankInfo}
*/
public CompletableFuture> getClanRankingsFromLocation(int locationId) {
return getClanRankingsFromLocation(locationId, -1);
}
/**
* Get clan rankings for a specific location
*
* @param locationId
* An {@link java.lang.Integer} representing the identifier of the location to retrieve.
* @param limit
* An {@link java.lang.Integer} limiting the number of records returned
*
* @return A {@link java.util.concurrent.CompletableFuture} containing a future result for a {@link java.util.List} of {@link com.ibasco.agql.protocols.supercell.coc.webapi.pojos.CocClanRankInfo}
*/
public CompletableFuture> getClanRankingsFromLocation(int locationId, int limit) {
return getClanRankingsFromLocation(locationId, limit, -1, -1);
}
/**
* Get clan rankings for a specific location
*
* @param locationId
* An {@link java.lang.Integer} representing the identifier of the location to retrieve.
* @param limit
* An {@link java.lang.Integer} limiting the number of records returned
* @param before
* (optional) An {@link java.lang.Integer} that indicates to return only items that occur before this marker.
* Before marker can be found from the response, inside the 'paging' property. Note that only after
* or before can be specified for a request, not both. Otherwise use -1 to disregard.
* @param after
* (optional) An {@link java.lang.Integer} that indicates to return only items that occur after this marker.
* After marker can be found from the response, inside the 'paging' property. Note that only after
* or before can be specified for a request, not both. Otherwise use -1 to disregard.
*
* @return A {@link java.util.concurrent.CompletableFuture} containing a future result of a {@link java.util.List} of {@link com.ibasco.agql.protocols.supercell.coc.webapi.pojos.CocClanRankInfo}
*/
public CompletableFuture> getClanRankingsFromLocation(int locationId, int limit, int before, int after) {
CompletableFuture json = sendRequest(new GetClanRankingsForLoc(VERSION_1, locationId, limit, before, after));
return json.thenApply(new Function>() {
@Override
public List apply(JsonObject root) {
JsonArray items = root.getAsJsonArray("items");
return builder().fromJson(items, new TypeToken>() {
}.getType());
}
});
}
/**
* Get player rankings for a specific location
*
* @param locationId
* An {@link java.lang.Integer} representing the identifier of the location to retrieve.
*
* @return A {@link java.util.concurrent.CompletableFuture} containing a future result of a {@link java.util.List} of {@link com.ibasco.agql.protocols.supercell.coc.webapi.pojos.CocPlayerRankInfo}
*/
public CompletableFuture> getPlayerRankingsFromLocation(int locationId) {
return getPlayerRankingsFromLocation(locationId, -1);
}
/**
* Get player rankings for a specific location
*
* @param locationId
* An {@link java.lang.Integer} representing the identifier of the location to retrieve.
* @param limit
* An {@link java.lang.Integer} limiting the number of records returned
*
* @return A {@link java.util.concurrent.CompletableFuture} containing a future result of a {@link java.util.List} of {@link com.ibasco.agql.protocols.supercell.coc.webapi.pojos.CocPlayerRankInfo}
*/
public CompletableFuture> getPlayerRankingsFromLocation(int locationId, int limit) {
return getPlayerRankingsFromLocation(locationId, limit, -1, -1);
}
/**
* Get player rankings for a specific location
*
* @param locationId
* An {@link java.lang.Integer} representing the identifier of the location to retrieve.
* @param limit
* An {@link java.lang.Integer} limiting the number of records returned
* @param before
* (optional) An {@link java.lang.Integer} that indicates to return only items that occur before this marker.
* Before marker can be found from the response, inside the 'paging' property. Note that only after
* or before can be specified for a request, not both. Otherwise use -1 to disregard.
* @param after
* (optional) An {@link java.lang.Integer} that indicates to return only items that occur after this marker.
* After marker can be found from the response, inside the 'paging' property. Note that only after
* or before can be specified for a request, not both. Otherwise use -1 to disregard.
*
* @return A {@link java.util.concurrent.CompletableFuture} containing a future result of a {@link java.util.List} of {@link com.ibasco.agql.protocols.supercell.coc.webapi.pojos.CocPlayerRankInfo}
*/
public CompletableFuture> getPlayerRankingsFromLocation(int locationId, int limit, int before, int after) {
CompletableFuture json = sendRequest(new GetPlayerRankingsForLoc(VERSION_1, locationId, limit, before, after));
return json.thenApply(new Function>() {
@Override
public List apply(JsonObject root) {
JsonArray items = root.getAsJsonArray("items");
return builder().fromJson(items, new TypeToken>() {
}.getType());
}
});
}
}