예제 #1
0
        /// <summary>
        /// Returns a specific activity
        /// </summary>
        /// <param name="accessToken">Strava access token</param>
        /// <param name="id">Activity Id</param>
        /// <param name="throwExceptions">If true method will throw exceptions instead of return null when there is an error.</param>
        public async Task <DetailedActivity> GetActivity(string accessToken, long id, bool throwExceptions = false)
        {
            try
            {
                var activity = await _cachingService.GetOrAdd(
                    $"DetailedActivity:{id}",
                    TimeSpan.MaxValue,
                    () => Get <DetailedActivity>(accessToken, $"https://www.strava.com/api/v3/activities/{id}"));

                if (activity.TryTagIntervalLaps() | activity.TryParseLactatMeasurements() | activity.TryParseFeelingParameter())
                {
                    await _cachingService.AddOrUpdate($"DetailedActivity:{id}", TimeSpan.MaxValue, activity);
                }

                return(activity);
            }
            catch
            {
                if (throwExceptions)
                {
                    throw;
                }

                return(null);
            }
        }
예제 #2
0
 public Task <DetailedAthlete> GetAthlete(string accessToken)
 {
     return(_cachingService.GetOrAdd(
                $"GetAthlete:{accessToken}",
                TimeSpan.FromMinutes(10),
                () => Get <DetailedAthlete>(accessToken, $"https://www.strava.com/api/v3/athlete")));
 }