string ConvertAchievementSortByToString(AchievementSortBy sortBy) { switch (sortBy) { case AchievementSortBy.LISTORDER: return("listOrder"); case AchievementSortBy.LISTORDER_ASC: return("listOrder:asc"); case AchievementSortBy.LISTORDER_DESC: return("listOrder:desc"); case AchievementSortBy.CREATED_AT: return("createdAt"); case AchievementSortBy.CREATED_AT_ASC: return("createdAt:asc"); case AchievementSortBy.CREATED_AT_DESC: return("createdAt:desc"); case AchievementSortBy.UPDATED_AT: return("updatedAt"); case AchievementSortBy.UPDATED_AT_ASC: return("updatedAt:asc"); case AchievementSortBy.UPDATED_AT_DESC: return("updatedAt:desc"); } return(""); }
/// <summary> /// Query user's achievements. Include achieved and in-progress. /// </summary> /// <param name="sortBy">Sorting method for the achievements result.</param> /// <param name="callback">Returns a Result that contains PaginatedUserAchievement via callback when completed.</param> /// <param name="offset">The offset of the achievement result. Default value is 0.</param> /// <param name="limit">The limit of the achievement result. Default value is 20.</param> /// <param name="PreferUnlocked">True if the configuration to display unlocked achievements first active, the list order should display unlocked achievements first on top of locked achievements, and false otherwise. Default value is true.</param> public void QueryUserAchievements(AchievementSortBy sortBy, ResultCallback <PaginatedUserAchievement> callback, int offset = 0, int limit = 20, bool PreferUnlocked = true) { Report.GetFunctionLog(this.GetType().Name); if (!this.session.IsValid()) { callback.TryError(ErrorCode.IsNotLoggedIn); return; } this.coroutineRunner.Run( this.api.QueryUserAchievements(this.@namespace, this.session.UserId, this.session.AuthorizationToken, sortBy, callback, offset, limit, PreferUnlocked)); }
/// <summary> /// Query all achievements in the related namespace. /// </summary> /// <param name="language">The language to display the appropiate achievement's name and description. If it is empty, it will use the its default language. /// If the achievement does not have the expected language, it will use its dafault languge.</param> /// <param name="sortBy">Sorting method for the achievements result.</param> /// <param name="callback">Returns a Result that contains PaginatedPublicAchievement via callback when completed.</param> /// <param name="offset">The offset of the achievement result. Default value is 0.</param> /// <param name="limit">The limit of the achievement result. Default value is 20.</param>/// public void QueryAchievements(string language, AchievementSortBy sortBy, ResultCallback <PaginatedPublicAchievement> callback, int offset = 0, int limit = 20) { Report.GetFunctionLog(this.GetType().Name); if (!this.session.IsValid()) { callback.TryError(ErrorCode.IsNotLoggedIn); return; } this.coroutineRunner.Run( this.api.QueryAchievements(this.@namespace, this.session.AuthorizationToken, language, sortBy, callback, offset, limit)); }
public IEnumerator QueryAchievements(string @namespace, string accessToken, string language, AchievementSortBy sortBy, ResultCallback <PaginatedPublicAchievement> callback, int offset, int limit) { Report.GetFunctionLog(this.GetType().Name); Assert.IsNotNull(@namespace, "Can't query achievements! Namespace parameter is null!"); Assert.IsNotNull(accessToken, "Can't query achievements! AccessToken parameter is null!"); var request = HttpRequestBuilder .CreateGet(this.baseUrl + "/v1/public/namespaces/{namespace}/achievements") .WithPathParam("namespace", @namespace) .WithQueryParam("language", language) .WithQueryParam("sortBy", ConvertAchievementSortByToString(sortBy)) .WithQueryParam("offset", offset.ToString()) .WithQueryParam("limit", limit.ToString()) .WithBearerAuth(accessToken) .Accepts(MediaType.ApplicationJson) .GetResult(); IHttpResponse response = null; yield return(this.httpClient.SendRequest(request, rsp => response = rsp)); var result = response.TryParseJson <PaginatedPublicAchievement>(); callback.Try(result); }