public IEnumerator GetRankings(string @namespace, string leaderboardCode, LeaderboardTimeFrame timeFrame, int offset, int limit,
                                       ResultCallback <LeaderboardRankingResult> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(@namespace, "Can't get ranking! Namespace parameter is null!");
            Assert.IsNotNull(leaderboardCode, "Can't get ranking! Leaderboard Code parameter is null!");

            string timeFrameString = "";

            switch (timeFrame)
            {
            case LeaderboardTimeFrame.ALL_TIME:
                timeFrameString = "alltime";
                break;

            case LeaderboardTimeFrame.CURRENT_SEASON:
                timeFrameString = "season";
                break;

            case LeaderboardTimeFrame.CURRENT_MONTH:
                timeFrameString = "month";
                break;

            case LeaderboardTimeFrame.CURRENT_WEEK:
                timeFrameString = "week";
                break;

            case LeaderboardTimeFrame.TODAY:
                timeFrameString = "today";
                break;

            default:
                break;
            }

            var builder = HttpRequestBuilder
                          .CreateGet(this.baseUrl + "/v1/public/namespaces/{namespace}/leaderboards/{leaderboardCode}/{timeFrame}")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("leaderboardCode", leaderboardCode)
                          .WithPathParam("timeFrame", timeFrameString)
                          .WithQueryParam("offset", (offset >= 0) ? offset.ToString() : "")
                          .WithQueryParam("limit", (limit >= 0) ? limit.ToString() : "")
                          .Accepts(MediaType.ApplicationJson);

            var request = builder.GetResult();

            IHttpResponse response = null;

            yield return(this.httpClient.SendRequest(request, rsp => response = rsp));

            var result = response.TryParseJson <LeaderboardRankingResult>();

            callback.Try(result);
        }
예제 #2
0
        /// <summary>
        /// Get leaderboard ranking data from the beginning.
        /// </summary>
        /// <param name="leaderboardCode"> The id of the leaderboard </param>
        /// <param name="timeFrame"> The time frame of leaderboard </param>
        /// <param name="offset"> Offset of the list that has been sliced based on Limit parameter (optional, default = 0) </param>
        /// <param name="limit"> The limit of item on page (optional) </param>
        /// <param name="callback"> Returns a Result that contains LeaderboardRankingResult via callback when completed </param>
        public void GetRankings(string leaderboardCode, LeaderboardTimeFrame timeFrame, int offset, int limit, ResultCallback <LeaderboardRankingResult> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(leaderboardCode, "Can't query all time leaderboard ranking data! leaderboardCode parameter is null!");

            if (!this.session.IsValid())
            {
                callback.TryError(ErrorCode.IsNotLoggedIn);

                return;
            }

            this.coroutineRunner.Run(
                this.api.GetRankings(
                    this.@namespace,
                    leaderboardCode,
                    timeFrame,
                    offset,
                    limit,
                    callback));
        }