Exemplo n.º 1
0
        /// <summary>
        /// Retrieves a Ride by id.
        /// </summary>
        /// <param name="id"></param>
        /// <returns>The Ride.</returns>
        public static Ride ById(long id)
        {
            var stravaRideResponse = StravaApi.Call(string.Format("rides/{0}", id));

            if (stravaRideResponse == null)
            {
                return(null);
            }

            return(new Ride(stravaRideResponse.ride));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieves a Segment by id.
        /// </summary>
        /// <param name="id"></param>
        /// <returns>The Segment.</returns>
        public static Segment ById(long id)
        {
            var stravaSegmentResponse = StravaApi.Call(string.Format("segments/{0}", id));

            if (stravaSegmentResponse == null)
            {
                return(null);
            }

            return(new Segment(stravaSegmentResponse.segment));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Populate the Ride's efforts.
        /// </summary>
        private void GetEfforts()
        {
            var stravaRideEffortsResponse = StravaApi.Call(string.Format("rides/{0}/efforts", Id));

            if (stravaRideEffortsResponse == null)
            {
                return;
            }

            if ((stravaRideEffortsResponse.efforts != null) && (stravaRideEffortsResponse.efforts.Count > 0))
            {
                efforts = (from x in (IEnumerable <dynamic>)stravaRideEffortsResponse.efforts
                           select new RideEffort(x)).ToArray();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Searches for Rides based on criteria.
        /// </summary>
        /// <param name="offset">Offset in search results.</param>
        /// <param name="count">Number of results to retrieve.</param>
        /// <param name="athleteId">Athlete id restriction, null for no restriction.</param>
        /// <param name="athleteName">Athlete name restriction, null for no restriction.</param>
        /// <param name="startDate">Start date restriction, null for no restriction.</param>
        /// <param name="endDate">End date restriction, null for no restriction.</param>
        /// <param name="clubId">Club id restriction, null for no restriction.</param>
        /// <param name="startId">Only retrieve rides with an id greater or equal to the start id, null for no restriction.</param>
        /// <returns>A list of RideSearchResult objects.</returns>
        public static List <RideSearchResult> Search(long offset, long count, long?athleteId = null, string athleteName = null, DateTime?startDate = null, DateTime?endDate = null, long?clubId = null, long?startId = null)
        {
            // build the query
            var queryBuilder = new StringBuilder();

            if (athleteId.HasValue)
            {
                queryBuilder.AppendFormat("athleteId={0}&", athleteId.Value);
            }
            if (athleteName != null)
            {
                queryBuilder.AppendFormat("athleteName={0}&", HttpUtility.UrlEncode(athleteName));
            }
            if (startDate.HasValue)
            {
                queryBuilder.AppendFormat("startDate={0}&", startDate.Value.ToString("yyyy'-'MM'-'dd"));
            }
            if (endDate.HasValue)
            {
                queryBuilder.AppendFormat("endDate={0}&", endDate.Value.ToString("yyyy'-'MM'-'dd"));
            }
            if (clubId.HasValue)
            {
                queryBuilder.AppendFormat("clubId={0}&", clubId.Value);
            }
            if (startId.HasValue)
            {
                queryBuilder.AppendFormat("startId={0}&", startId.Value);
            }

            var restriction = queryBuilder.ToString();

            var results    = new List <RideSearchResult>();
            var tempOffset = offset;

            // keep searching until enough results have been retrieved
            while (count > 0)
            {
                var stravaRideSearchResponse = StravaApi.Call(string.Format("rides?{0}offset={1}", restriction, tempOffset));
                if (stravaRideSearchResponse == null)
                {
                    return(results);
                }

                foreach (var stravaRideSearchResult in stravaRideSearchResponse.rides)
                {
                    var segmentEffort = new RideSearchResult(stravaRideSearchResult);
                    results.Add(segmentEffort);
                    count--;
                    if (count == 0)
                    {
                        break;
                    }
                }

                if (stravaRideSearchResponse.rides.Count < ResultCount)
                {
                    break;
                }

                tempOffset += ResultCount;
            }
            return(results);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Retrieves SegmentEfforts based on search criteria.
        /// </summary>
        /// <param name="offset">Offset in search results.</param>
        /// <param name="count">Number of results to retrieve.</param>
        /// <param name="best">Request best efforts per athlete sorted by elapsed time ascending -- may not work as expected due to Strava bugs.</param>
        /// <param name="athleteId">Athlete id restriction, null for no restriction.</param>
        /// <param name="athleteName">Athlete name restriction, null for no restriction.</param>
        /// <param name="startDate">Start date restriction, null for no restriction.</param>
        /// <param name="endDate">End date restriction, null for no restriction.</param>
        /// <param name="clubId">Club id restriction, null for no restriction.</param>
        /// <param name="startId">Request efforts with an Id greater than or equal to the startId.</param>
        /// <returns>A list of SegmentEffort objects.</returns>
        public List <SegmentEffort> GetEfforts(long offset, long count, bool best = false, long?athleteId = null, string athleteName = null, DateTime?startDate = null, DateTime?endDate = null, long?clubId = null, long?startId = null)
        {
            // build the query
            var queryBuilder = new StringBuilder();

            if (best)
            {
                queryBuilder.Append("best=true&");
            }
            if (athleteId.HasValue)
            {
                queryBuilder.AppendFormat("athleteId={0}&", athleteId.Value);
            }
            if (athleteName != null)
            {
                queryBuilder.AppendFormat("athleteName={0}&", HttpUtility.UrlEncode(athleteName));
            }
            if (startDate.HasValue)
            {
                queryBuilder.AppendFormat("startDate={0}&", startDate.Value.ToString("yyyy'-'MM'-'dd"));
            }
            if (endDate.HasValue)
            {
                queryBuilder.AppendFormat("endDate={0}&", endDate.Value.ToString("yyyy'-'MM'-'dd"));
            }
            if (clubId.HasValue)
            {
                queryBuilder.AppendFormat("clubId={0}&", clubId.Value);
            }
            if (startId.HasValue)
            {
                queryBuilder.AppendFormat("startId={0}&", startId.Value);
            }
            var restriction = queryBuilder.ToString();

            var results    = new List <SegmentEffort>();
            var tempOffset = offset;

            while (count > 0)
            {
                var stravaSegmentEffortSearchResponse = StravaApi.Call(string.Format("segments/{0}/efforts?{1}offset={2}", Id, restriction, tempOffset));
                if (stravaSegmentEffortSearchResponse == null)
                {
                    return(results);
                }

                foreach (var stravaSegmentEffort in stravaSegmentEffortSearchResponse.efforts)
                {
                    var segmentEffort = new SegmentEffort(stravaSegmentEffort, Id);
                    results.Add(segmentEffort);
                    count--;
                    if (count == 0)
                    {
                        break;
                    }
                }

                if (stravaSegmentEffortSearchResponse.efforts.Count < ResultCount)
                {
                    break;
                }

                tempOffset += ResultCount;
            }
            return(results);
        }