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

com.playfab.PlayFabLocalizationAPI Maven / Gradle / Ivy

Go to download

PlayFab is the unified backend platform for games — everything you need to build and operate your game, all in one place, so you can focus on creating and delivering a great player experience.

There is a newer version: 0.122.201027
Show newest version
package com.playfab;

import com.playfab.internal.*;
import com.playfab.PlayFabLocalizationModels.*;
import com.playfab.PlayFabErrors.*;
import com.playfab.PlayFabSettings;
import java.util.concurrent.*;
import java.util.*;
import com.google.gson.*;
import com.google.gson.reflect.*;

    /** The Localization APIs give you the tools needed to manage language setup in your title. */
public class PlayFabLocalizationAPI {
    private static Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").create();

    /**
     * Retrieves the list of allowed languages, only accessible by title entities
     * @param request GetLanguageListRequest
     * @return Async Task will return GetLanguageListResponse
     */
    @SuppressWarnings("unchecked")
    public static FutureTask> GetLanguageListAsync(final GetLanguageListRequest request) {
        return new FutureTask(new Callable>() {
            public PlayFabResult call() throws Exception {
                return privateGetLanguageListAsync(request);
            }
        });
    }

    /**
     * Retrieves the list of allowed languages, only accessible by title entities
     * @param request GetLanguageListRequest
     * @return GetLanguageListResponse
     */
    @SuppressWarnings("unchecked")
    public static PlayFabResult GetLanguageList(final GetLanguageListRequest request) {
        FutureTask> task = new FutureTask(new Callable>() {
            public PlayFabResult call() throws Exception {
                return privateGetLanguageListAsync(request);
            }
        });
        try {
            task.run();
            return task.get();
        } catch(Exception e) {
            return null;
        }
    }

    /** Retrieves the list of allowed languages, only accessible by title entities */
    @SuppressWarnings("unchecked")
    private static PlayFabResult privateGetLanguageListAsync(final GetLanguageListRequest request) throws Exception {
        if (PlayFabSettings.EntityToken == null) throw new Exception ("Must call GetEntityToken before you can use the Entity API");

        FutureTask task = PlayFabHTTP.doPost(PlayFabSettings.GetURL("/Locale/GetLanguageList"), request, "X-EntityToken", PlayFabSettings.EntityToken);
        task.run();
        Object httpResult = task.get();
        if (httpResult instanceof PlayFabError) {
            PlayFabError error = (PlayFabError)httpResult;
            if (PlayFabSettings.GlobalErrorHandler != null)
                PlayFabSettings.GlobalErrorHandler.callback(error);
            PlayFabResult result = new PlayFabResult();
            result.Error = error;
            return result;
        }
        String resultRawJson = (String) httpResult;

        PlayFabJsonSuccess resultData = gson.fromJson(resultRawJson, new TypeToken>(){}.getType());
        GetLanguageListResponse result = resultData.data;

        PlayFabResult pfResult = new PlayFabResult();
        pfResult.Result = result;
        return pfResult;
    }
}