示例#1
0
        public IPagedList<ITrack> GetRecentTracks(string username, int? limit, int? page, Timestamp start, Timestamp end)
        {
            IApiMethod method = this.CreateApiMethod("user.getRecentTracks");

            method.AddParameter("user", username);

            if (page.HasValue)
            {
                method.AddParameter("page", page.ToString());
            }
            if (start != null)
            {
                method.AddParameter("from", start.GetUnixTimestamp());
            }
            if (start != null)
            {
                method.AddParameter("to", end.GetUnixTimestamp());
            }

            var response = method.Execute();

            var tracks = (JArray)response["recenttracks"]["track"];
            var attributes = response["recenttracks"]["@attr"];

            IPagedList<ITrack> result = new PagedList<ITrack>();
            result.Page = attributes.Value<int>("page");
            result.PerPage = attributes.Value<int>("perPage");
            result.TotalPages = attributes.Value<int>("totalPages");
            result.Total = attributes.Value<int>("total");

            foreach (var track in tracks)
            {
                result.Add(new Track { Url = track.Value<string>("url"), Name = track.Value<string>("name") });
            }

            return result;
        }