Example usage for com.google.gson JsonObject getAsJsonArray

List of usage examples for com.google.gson JsonObject getAsJsonArray

Introduction

In this page you can find the example usage for com.google.gson JsonObject getAsJsonArray.

Prototype

public JsonArray getAsJsonArray(String memberName) 

Source Link

Document

Convenience method to get the specified member as a JsonArray.

Usage

From source file:com.ibasco.agql.protocols.supercell.coc.webapi.interfaces.CocLocations.java

License:Open Source License

/**
 * <p>List all available locations</p>
 *
 * @param limit/*from w  w  w.j  av  a 2  s .co m*/
 *         An {@link Integer} limiting the number of records returned
 * @param before
 *         (optional) An {@link 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 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 CompletableFuture} containing a future result for a {@link List} of {@link CocLocation}
 */
public CompletableFuture<List<CocLocation>> getLocations(int limit, int before, int after) {
    CompletableFuture<JsonObject> json = sendRequest(new GetLocations(VERSION_1, limit, before, after));
    return json.thenApply(new Function<JsonObject, List<CocLocation>>() {
        @Override
        public List<CocLocation> apply(JsonObject root) {
            JsonArray items = root.getAsJsonArray("items");
            return builder().fromJson(items, new TypeToken<List<CocLocation>>() {
            }.getType());
        }
    });
}

From source file:com.ibasco.agql.protocols.supercell.coc.webapi.interfaces.CocLocations.java

License:Open Source License

/**
 * <p>Get clan rankings for a specific location</p>
 *
 * @param locationId//from   ww  w. jav a 2s.  c  om
 *         An {@link Integer} representing the identifier of the location to retrieve.
 * @param limit
 *         An {@link Integer} limiting the number of records returned
 * @param before
 *         (optional) An {@link 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 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 CompletableFuture} containing a future result of a {@link List} of {@link CocClanRankInfo}
 */
public CompletableFuture<List<CocClanRankInfo>> getClanRankingsFromLocation(int locationId, int limit,
        int before, int after) {
    CompletableFuture<JsonObject> json = sendRequest(
            new GetClanRankingsForLoc(VERSION_1, locationId, limit, before, after));
    return json.thenApply(new Function<JsonObject, List<CocClanRankInfo>>() {
        @Override
        public List<CocClanRankInfo> apply(JsonObject root) {
            JsonArray items = root.getAsJsonArray("items");
            return builder().fromJson(items, new TypeToken<List<CocClanRankInfo>>() {
            }.getType());
        }
    });
}

From source file:com.ibasco.agql.protocols.supercell.coc.webapi.interfaces.CocLocations.java

License:Open Source License

/**
 * <p>Get player rankings for a specific location</p>
 *
 * @param locationId//from w ww.  j av a  2 s.c o m
 *         An {@link Integer} representing the identifier of the location to retrieve.
 * @param limit
 *         An {@link Integer} limiting the number of records returned
 * @param before
 *         (optional) An {@link 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 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 CompletableFuture} containing a future result of a {@link List} of {@link CocPlayerRankInfo}
 */
public CompletableFuture<List<CocPlayerRankInfo>> getPlayerRankingsFromLocation(int locationId, int limit,
        int before, int after) {
    CompletableFuture<JsonObject> json = sendRequest(
            new GetPlayerRankingsForLoc(VERSION_1, locationId, limit, before, after));
    return json.thenApply(new Function<JsonObject, List<CocPlayerRankInfo>>() {
        @Override
        public List<CocPlayerRankInfo> apply(JsonObject root) {
            JsonArray items = root.getAsJsonArray("items");
            return builder().fromJson(items, new TypeToken<List<CocPlayerRankInfo>>() {
            }.getType());
        }
    });
}

From source file:com.ibasco.agql.protocols.valve.dota2.webapi.Dota2WebApiInterface.java

License:Open Source License

@SuppressWarnings("all")
protected <T> List<T> asListOf(Class type, String listName, JsonObject root, boolean strict) {
    //Process json
    JsonArray items = null;/*from ww w  . jav a  2  s. c o m*/
    try {
        items = getValidResult(root).getAsJsonArray(listName);
    } catch (Dota2WebException e) {
        //if we didn't find a result container, check the top level
        if (root.has(listName) && root.get(listName).isJsonArray())
            items = root.getAsJsonArray(listName);
    }
    if (items == null) {
        if (strict)
            throw new Dota2WebException(String.format("Unable to find '%s' from the response", listName));
        else
            return new ArrayList<>();
    }
    //Parse then return the Parameterized List
    return fromJson(items, new CollectionParameterizedType(type, ArrayList.class));
}

From source file:com.ibasco.agql.protocols.valve.steam.webapi.interfaces.SteamApps.java

License:Open Source License

public CompletableFuture<List<SteamGameServer>> getServersAtAddress(InetAddress address) {
    final CompletableFuture<JsonObject> json = sendRequest(
            new GetServersAtAddress(1, address.getHostAddress()));
    return json.thenApply(root -> {
        JsonObject response = root.getAsJsonObject("response");
        Boolean success = response.getAsJsonPrimitive("success").getAsBoolean();
        JsonArray serverList = response.getAsJsonArray("servers");
        if (success) {
            Type serverListType = new TypeToken<List<SteamGameServer>>() {
            }.getType();/*from w  w w  . j a va2s .  co m*/
            return builder().fromJson(serverList, serverListType);
        }
        throw new AsyncGameLibUncheckedException("Server returned an invalid response");
    });
}

From source file:com.ibasco.agql.protocols.valve.steam.webapi.interfaces.SteamEconItems.java

License:Open Source License

public CompletableFuture<List<SteamEconPlayerItem>> getPlayerItems(int appId, long steamId, int apiVersion) {
    CompletableFuture<JsonObject> json = sendRequest(new GetPlayerItems(appId, steamId, apiVersion));
    return json.thenApply(root -> {
        JsonObject result = root.getAsJsonObject("result");
        int status = result.getAsJsonPrimitive("status").getAsInt();
        JsonArray items = result.getAsJsonArray("items");
        Type type = new TypeToken<List<SteamEconPlayerItem>>() {
        }.getType();/*from w  w w. j a  v a  2s.  c  om*/
        return fromJson(items, type);
    });
}

From source file:com.ibasco.agql.protocols.valve.steam.webapi.interfaces.SteamEconomy.java

License:Open Source License

public CompletableFuture<List<SteamAssetPriceInfo>> getAssetPrices(int appId, String currency,
        String language) {//from  w  w  w . j  a v  a 2  s. c  om
    CompletableFuture<JsonObject> json = sendRequest(new GetAssetPrices(VERSION_1, appId, currency, language));
    return json.thenApply(root -> {
        JsonObject result = root.getAsJsonObject("result");
        boolean success = result.getAsJsonPrimitive("success").getAsBoolean();
        if (success) {
            JsonArray assets = result.getAsJsonArray("assets");
            Type type = new TypeToken<List<SteamAssetPriceInfo>>() {
            }.getType();
            return builder().fromJson(assets, type);
        }
        return new ArrayList<SteamAssetPriceInfo>();
    });
}

From source file:com.ibasco.agql.protocols.valve.steam.webapi.interfaces.SteamNews.java

License:Open Source License

public CompletableFuture<List<SteamNewsItem>> getNewsForApp(int appId, int maxLength, int endDate, int count,
        String feeds) {//w  w  w .ja  v a2 s  .  c  om
    GetNewsForApp request = new GetNewsForApp(2, appId).maxLength(maxLength).endDate(endDate).count(count)
            .feeds(feeds);
    CompletableFuture<JsonObject> newsItems = sendRequest(request);
    return newsItems.thenApply(root -> {
        JsonObject appNews = root.getAsJsonObject("appnews");
        JsonArray newsItems1 = appNews.getAsJsonArray("newsitems");
        Type newsListType = new TypeToken<List<SteamNewsItem>>() {
        }.getType();
        return builder().fromJson(newsItems1, newsListType);
    });
}

From source file:com.ibasco.agql.protocols.valve.steam.webapi.interfaces.SteamUserStats.java

License:Open Source License

public CompletableFuture<List<SteamGameAchievement>> getGlobalAchievementPercentagesForApp(int appId) {
    CompletableFuture<JsonObject> 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<List<SteamGameAchievement>>() {
        }.getType();// ww w .j av a2s .c  om
        return builder().fromJson(achievements, type);
    });
}

From source file:com.ibasco.agql.protocols.valve.steam.webapi.interfaces.SteamUserStats.java

License:Open Source License

public CompletableFuture<SteamGameStatsSchemaInfo> getSchemaForGame(int appId) {
    CompletableFuture<JsonObject> 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<List<SteamGameAchievementSchema>>() {
        }.getType();/*from   w w w  .  ja v a2 s  .c  o m*/
        Type statsSchemaType = new TypeToken<List<SteamGameStatsSchema>>() {
        }.getType();
        info.setAchievementSchemaList(
                fromJson(availableGameStats.getAsJsonArray("achievements"), achievementsSchemaType));
        info.setStatsSchemaList(fromJson(availableGameStats.getAsJsonArray("stats"), statsSchemaType));
        return info;
    });
}