コード例 #1
0
        internal static LCLeaderboardArchive Parse(IDictionary <string, object> data)
        {
            LCLeaderboardArchive archive = new LCLeaderboardArchive();

            if (data.TryGetValue("statisticName", out object statisticName))
            {
                archive.StatisticName = statisticName as string;
            }
            if (data.TryGetValue("version", out object version))
            {
                archive.Version = Convert.ToInt32(version);
            }
            if (data.TryGetValue("status", out object status))
            {
                archive.Status = status as string;
            }
            if (data.TryGetValue("url", out object url))
            {
                archive.Url = url as string;
            }
            if (data.TryGetValue("activatedAt", out object activatedAt) &&
                activatedAt is System.Collections.IDictionary actDt)
            {
                archive.ActivatedAt = LCDecoder.DecodeDate(actDt);
            }
            if (data.TryGetValue("deactivatedAt", out object deactivatedAt) &&
                deactivatedAt is System.Collections.IDictionary deactDt)
            {
                archive.DeactivatedAt = LCDecoder.DecodeDate(deactDt);
            }
            return(archive);
        }
コード例 #2
0
        /// <summary>
        /// Gets historical data of this leaderboard.
        /// </summary>
        /// <param name="skip"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public async Task <ReadOnlyCollection <LCLeaderboardArchive> > GetArchives(int skip  = 0,
                                                                                   int limit = 10)
        {
            if (skip < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(skip));
            }
            if (limit <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(limit));
            }
            string path = $"leaderboard/leaderboards/{StatisticName}/archives?skip={skip}&limit={limit}";
            Dictionary <string, object> result = await LCCore.HttpClient.Get <Dictionary <string, object> >(path);

            if (result.TryGetValue("results", out object results) &&
                results is List <object> list)
            {
                List <LCLeaderboardArchive> archives = new List <LCLeaderboardArchive>();
                foreach (object item in list)
                {
                    if (item is IDictionary <string, object> dict)
                    {
                        LCLeaderboardArchive archive = LCLeaderboardArchive.Parse(dict);
                        archives.Add(archive);
                    }
                }
                return(archives.AsReadOnly());
            }
            return(null);
        }