Exemplo n.º 1
0
        /// <summary>
        /// Gets the full and unfiltered leaderboard of a Strava segment asynchronously.
        /// </summary>
        /// <param name="segmentId">The Strava segment Id.</param>
        /// <returns>The full and unfiltered leaderboard></returns>
        public async Task<Leaderboard> GetFullSegmentLeaderboardAsync(String segmentId)
        {
            int page = 1;

            //Create one dummy request to get the number of entries.
            Leaderboard request = await GetSegmentLeaderboardAsync(segmentId, 1, 1);
            int totalAthletes = request.EntryCount;

            Leaderboard leaderboard = new Leaderboard
            {
                EffortCount = request.EffortCount,
                EntryCount = request.EntryCount
            };

            while ((page - 1) * 200 < totalAthletes)
            {
                Leaderboard l = await GetSegmentLeaderboardAsync(segmentId, page++, 200);
                
                foreach (LeaderboardEntry entry in l.Entries)
                {
                    leaderboard.Entries.Add(entry);
                }
            }

            return leaderboard;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the leaderboard of a segment. You can use various filters to filter the data.
        /// Some of the filters require a Strava Premium account!
        /// </summary>
        /// <param name="segmentId">The Strava segment Id.</param>
        /// <param name="weight">The weight class used to filter the leaderboard.</param>
        /// <param name="age">The age group used to filter the leaderboard.</param>
        /// <param name="time">The time used to filter the leaderboard.</param> 
        /// <param name="gender">The gender used to filter the leaderboard.</param>
        /// <returns>The leaderboard filtered by gender.</returns>
        public async Task<Leaderboard> GetSegmentLeaderboardAsync(String segmentId, WeightFilter weight, AgeFilter age, TimeFilter time, GenderFilter gender)
        {
            int page = 1;

            //Create one dummy request to get the number of entries.
            Leaderboard request = await GetSegmentLeaderboardAsync(segmentId, weight, age, time, gender, 1, 1);
            int totalAthletes = request.EntryCount;

            Leaderboard leaderboard = new Leaderboard
            {
                EffortCount = request.EffortCount,
                EntryCount = request.EntryCount
            };

            while ((page - 1) * 200 < totalAthletes)
            {
                Leaderboard l = await GetSegmentLeaderboardAsync(segmentId, weight, age, time, gender, page++, 200);

                foreach (LeaderboardEntry entry in l.Entries)
                {
                    leaderboard.Entries.Add(entry);
                }
            }

            return leaderboard;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the gender-filtered leaderboard of a segment. This method requires the currently authenticated 
        /// athlete to have a Strava premium account.
        /// </summary>
        /// <param name="segmentId">The Strava segment Id.</param>
        /// <param name="gender">The gender used to filter the leaderboard.</param>
        /// <returns>The leaderboard filtered by gender.</returns>
        public Leaderboard GetSegmentLeaderboard(String segmentId, Gender gender)
        {
            int page = 1;

            //Create one dummy request to get the number of entries.
            Leaderboard request = GetSegmentLeaderboard(segmentId, gender, 1, 1);
            int totalAthletes = request.EntryCount;

            Leaderboard leaderboard = new Leaderboard
            {
                EffortCount = request.EffortCount,
                EntryCount = request.EntryCount
            };

            while ((page - 1) * 200 < totalAthletes)
            {
                Leaderboard l = GetSegmentLeaderboard(segmentId, gender, page++, 200);

                foreach (LeaderboardEntry entry in l.Entries)
                {
                    leaderboard.Entries.Add(entry);
                }
            }

            return leaderboard;
        }