/// <summary> /// Gets all the starred segments of an Athlete. /// </summary> /// <returns>A list of segments that are starred by the athlete.</returns> private async Task <List <SegmentSummary> > GetStarredSegmentsFromServiceAsync(string athleteId) { try { var accessToken = await _settingsService.GetStoredStravaAccessTokenAsync(); var defaultDistanceUnitType = await _settingsService.GetStoredDistanceUnitTypeAsync(); string getUrl = $"{Endpoints.Athletes}/{athleteId}/segments/starred?access_token={accessToken}"; string json = await _stravaWebClient.GetAsync(new Uri(getUrl)); var segments = Unmarshaller <List <SegmentSummary> > .Unmarshal(json); foreach (SegmentSummary segment in segments) { StravaService.SetMetricUnits(segment, defaultDistanceUnitType); } return(segments); } catch (Exception ex) { string title = $"StravaSegmentService.GetStarredSegmentsFromServiceAsync - athleteId {athleteId}"; _logService.LogException(title, ex); } return(null); }
public async Task <Activity> CreateActivityAsync(string name, ActivityType type, string timeString, int elapsedSeconds, string description, float distance = 0f) { string t = type.ToString().ToLower(); string postUrl = $"https://www.strava.com/api/v3/activities?name={name}&type={t}&start_date_local={timeString}&elapsed_time={elapsedSeconds}&description={description}&distance={distance.ToString(CultureInfo.InvariantCulture)}&access_token={Authentication.AccessToken}"; return(Unmarshaller <Activity> .Unmarshal(await WebRequest.SendPostAsync(new Uri(postUrl)))); }
public List <ActivityZone> GetActivityZones(string activityId) { string uriString = string.Format("{0}/{1}/zones?access_token={2}", "https://www.strava.com/api/v3/activities", activityId, Authentication.AccessToken); string json = WebRequest.SendGet(new Uri(uriString)); return(Unmarshaller <List <ActivityZone> > .Unmarshal(json)); }
private async Task <IList <ActivitySummary> > GetRelatedActivitiesFromServiceAsync(string activityId) { try { _perflog.GetRelatedActivitiesFromService(false, activityId); var accessToken = await _settingsService.GetStoredStravaAccessTokenAsync(); var defaultDistanceUnitType = await _settingsService.GetStoredDistanceUnitTypeAsync(); string getUrl = $"{Endpoints.Activity}/{activityId}/related?access_token={accessToken}"; string json = await _stravaWebClient.GetAsync(new Uri(getUrl)); var results = Unmarshaller <List <ActivitySummary> > .Unmarshal(json).Select(activity => { StravaService.SetMetricUnits(activity, defaultDistanceUnitType); return(activity); }).ToList(); _perflog.GetRelatedActivitiesFromService(true, activityId); return(results); } catch (Exception ex) { #if !DEBUG _errorMessage.Clear(); _errorMessage.AppendLine($"StravaActivityService.GetRelatedActivitiesFromServiceAsync - activityId {activityId}"); _errorMessage.AppendLine(ex.Message); ServiceLocator.Current.GetInstance <IGoogleAnalyticsService>().Tracker.SendException(_errorMessage.ToString(), false); #endif } return(null); }
public async Task <List <ActivitySummary> > GetActivitiesAfterAsync(DateTime after, int page, int perPage) { long secondsAfter = DateConverter.GetSecondsSinceUnixEpoch(after); string getUrl = string.Format("{0}?after={1}&page={2}&per_page={3}&access_token={4}", "https://www.strava.com/api/v3/athlete/activities", secondsAfter, page, perPage, Authentication.AccessToken); return(Unmarshaller <List <ActivitySummary> > .Unmarshal(await WebRequest.SendGetAsync(new Uri(getUrl)))); }
/// <summary> /// Retrieves gear with the specified id from the Strava servers. /// </summary> /// <param name="gearId">The Strava id of the gear.</param> /// <returns>The gear object.</returns> public Gear.Bike GetGear(string gearId) { string getUrl = string.Format("{0}/{1}?access_token={2}", Endpoints.Gear, gearId, Authentication.AccessToken); string json = WebRequest.SendGet(new Uri(getUrl)); return(Unmarshaller <Gear.Bike> .Unmarshal(json)); }
private async Task <List <Photo> > GetPhotosFromServiceAsync(string activityId) { try { _perflog.GetPhotosFromService(false, activityId); var accessToken = await _settingsService.GetStoredStravaAccessTokenAsync(); string getUrl = $"{Endpoints.Activity}/{activityId}/photos?photo_sources=true&size=600&access_token={accessToken}"; string json = await _stravaWebClient.GetAsync(new Uri(getUrl)); var results = Unmarshaller <List <Photo> > .Unmarshal(json); _perflog.GetPhotosFromService(true, activityId); return(results); } catch (Exception ex) { #if !DEBUG _errorMessage.Clear(); _errorMessage.AppendLine($"StravaActivityService.GetPhotosFromServiceAsync - activityId {activityId}"); _errorMessage.AppendLine(ex.Message); ServiceLocator.Current.GetInstance <IGoogleAnalyticsService>().Tracker.SendException(_errorMessage.ToString(), false); #endif } return(null); }
/// <summary> /// Receives a Strava athlete. /// </summary> /// <param name="athleteId">The Strava Id of the athlete.</param> /// <returns>The AthleteSummary object of the athlete.</returns> public AthleteSummary GetAthlete(String athleteId) { String getUrl = String.Format("{0}/{1}?access_token={2}", Endpoints.Athletes, athleteId, Authentication.AccessToken); String json = WebRequest.SendGet(new Uri(getUrl)); return(Unmarshaller <AthleteSummary> .Unmarshal(json)); }
/// <summary> /// Gets all the followers of the currently authenticated athlete. /// </summary> /// <returns>A list of athletes that follow the currently authenticated athlete.</returns> public List <AthleteSummary> GetFollowers() { String getUrl = String.Format("{0}?access_token={1}", Endpoints.Follower, Authentication.AccessToken); String json = WebRequest.SendGet(new Uri(getUrl)); return(Unmarshaller <List <AthleteSummary> > .Unmarshal(json)); }
/// <summary> /// Gets an activity stream asynchronously. /// </summary> /// <param name="activityId">The Strava activity id.</param> /// <param name="typeFlags">Specifies the type of stream.</param> /// <param name="resolution">Specifies the resolution of the stream.</param> /// <returns>The stream data.</returns> public async Task <List <ActivityStream> > GetActivityStreamAsync(string activityId, StreamType typeFlags, StreamResolution resolution = StreamResolution.All) { StringBuilder types = new StringBuilder(); foreach (StreamType type in (StreamType[])Enum.GetValues(typeof(StreamType))) { if (typeFlags.HasFlag(type)) { types.Append(type.ToString().ToLower()); types.Append(","); } } types.Remove(types.ToString().Length - 1, 1); string getUrl = string.Format("{0}/{1}/streams/{2}?{3}&access_token={4}", Endpoints.Activity, activityId, types, resolution != StreamResolution.All ? "resolution=" + resolution.ToString().ToLower() : "", Authentication.AccessToken ); string json = await WebRequest.SendGetAsync(new Uri(getUrl)); return(Unmarshaller <List <ActivityStream> > .Unmarshal(json)); }
/// <summary> /// Gets a segment stream asynchronously. /// </summary> /// <param name="segmentId">The Strava segment id.</param> /// <param name="typeFlags">Specifies the type of stream.</param> /// <param name="resolution">Specifies the resolution of the stream.</param> /// <returns>The stream data.</returns> public async Task <List <SegmentStream> > GetSegmentStreamAsync(string segmentId, SegmentStreamType typeFlags, StreamResolution resolution = StreamResolution.All) { // Only distance, altitude and latlng stream types are available. StringBuilder types = new StringBuilder(); foreach (SegmentStreamType type in (StreamType[])Enum.GetValues(typeof(SegmentStreamType))) { if (typeFlags.HasFlag(type)) { types.Append(type.ToString().ToLower()); types.Append(","); } } types.Remove(types.ToString().Length - 1, 1); string getUrl = string.Format("{0}/{1}/streams/{2}?{3}&access_token={4}", Endpoints.Leaderboard, segmentId, types, resolution != StreamResolution.All ? "resolution=" + resolution.ToString().ToLower() : "", Authentication.AccessToken ); string json = await WebRequest.SendGetAsync(new Uri(getUrl)); return(Unmarshaller <List <SegmentStream> > .Unmarshal(json)); }
/// <summary> /// Gets a segment effort stream. /// </summary> /// <param name="effortId">The Strava segment effort id.</param> /// <param name="typeFlags">Specifies the type of stream.</param> /// <param name="resolution">Specifies the resolution of the stream.</param> /// <returns>The stream data.</returns> public List <SegmentEffortStream> GetSegmentEffortStream(string effortId, SegmentStreamType typeFlags, StreamResolution resolution = StreamResolution.All) { StringBuilder types = new StringBuilder(); foreach (SegmentStreamType type in (StreamType[])Enum.GetValues(typeof(SegmentStreamType))) { if (typeFlags.HasFlag(type)) { types.Append(type.ToString().ToLower()); types.Append(","); } } types.Remove(types.ToString().Length - 1, 1); string getUrl = string.Format("https://www.strava.com/api/v3/segment_efforts/{0}/streams/{1}?{2}&access_token={3}", effortId, types, resolution != StreamResolution.All ? "resolution=" + resolution.ToString().ToLower() : "", Authentication.AccessToken ); string json = WebRequest.SendGet(new Uri(getUrl)); return(Unmarshaller <List <SegmentEffortStream> > .Unmarshal(json)); }
private async Task <Segment> GetSegmentFromServiceAsync(string segmentId) { try { var accessToken = await _settingsService.GetStoredStravaAccessTokenAsync(); var defaultDistanceUnitType = await _settingsService.GetStoredDistanceUnitTypeAsync(); string getUrl = $"{Endpoints.Segment}/{segmentId}?access_token={accessToken}"; string json = await _stravaWebClient.GetAsync(new Uri(getUrl)); var segment = Unmarshaller <Segment> .Unmarshal(json); StravaService.SetMetricUnits(segment, defaultDistanceUnitType); return(segment); } catch (Exception ex) { string title = $"StravaSegmentService.GetSegmentFromServiceAsync - segmentId {segmentId}"; _logService.LogException(title, ex); } return(null); }
public async Task <List <SegmentSummary> > GetStarredSegmentsAsync() { //TODO: Glenn - Caching? try { var accessToken = await _settingsService.GetStoredStravaAccessTokenAsync(); var defaultDistanceUnitType = await _settingsService.GetStoredDistanceUnitTypeAsync(); string getUrl = $"{Endpoints.Starred}?access_token={accessToken}"; string json = await _stravaWebClient.GetAsync(new Uri(getUrl)); var segments = Unmarshaller <List <SegmentSummary> > .Unmarshal(json); foreach (SegmentSummary segment in segments) { StravaService.SetMetricUnits(segment, defaultDistanceUnitType); } return(segments); } catch (Exception ex) { string title = "StravaSegmentService.GetStarredSegmentsAsync"; _logService.LogException(title, ex); } return(null); }
/// <summary> /// Asynchronously receives the currently authenticated athlete. /// </summary> /// <param name="athleteId">The Strava Id of the athlete.</param> /// <returns>The AthleteSummary object of the athlete.</returns> public async Task <AthleteSummary> GetAthleteAsync(string athleteId) { string getUrl = string.Format("{0}/{1}?access_token={2}", Endpoints.Athletes, athleteId, Authentication.AccessToken); string json = await WebRequest.SendGetAsync(new Uri(getUrl)); return(Unmarshaller <AthleteSummary> .Unmarshal(json)); }
/// <summary> /// Asynchronously receives the currently authenticated athlete. /// </summary> /// <returns>The currently authenticated athlete.</returns> public async Task <Athlete> GetAthleteAsync() { String getUrl = String.Format("{0}?access_token={1}", Endpoints.Athlete, Authentication.AccessToken); String json = await WebRequest.SendGetAsync(new Uri(getUrl)); return(Unmarshaller <Athlete> .Unmarshal(json)); }
/// <summary> /// Gets all the followers of the currently authenticated athlete. /// </summary> /// <returns>A list of athletes that follow the currently authenticated athlete.</returns> public async Task <List <AthleteSummary> > GetFollowersAsync() { string getUrl = string.Format("{0}?access_token={1}", Endpoints.Follower, Authentication.AccessToken); string json = await WebRequest.SendGetAsync(new Uri(getUrl)); return(Unmarshaller <List <AthleteSummary> > .Unmarshal(json)); }
/// <summary> /// Gets a list of friends of an athlete. /// </summary> /// <param name="athleteId">The Strava athlete id.</param> /// <returns>The list of friends of the athlete.</returns> public async Task <List <AthleteSummary> > GetFriendsAsync(String athleteId) { String getUrl = String.Format("{0}/{1}/friends?access_token={2}", Endpoints.Athletes, athleteId, Authentication.AccessToken); String json = await WebRequest.SendGetAsync(new Uri(getUrl)); return(Unmarshaller <List <AthleteSummary> > .Unmarshal(json)); }
/// <summary> /// Gets the latest activities of the currently authenticated athletes followers asynchronously. /// </summary> /// <param name="page">The page of activities.</param> /// <param name="perPage">The amount of activities per page.</param> /// <returns>A list of activities from your followers.</returns> public async Task <IList <ActivitySummary> > GetFollowersActivitiesAsync(int page, int perPage) { try { _perflog.GetFollowersActivitiesAsync(false, page, perPage); var accessToken = await _settingsService.GetStoredStravaAccessTokenAsync(); var defaultDistanceUnitType = await _settingsService.GetStoredDistanceUnitTypeAsync(); //TODO: Glenn - Optional parameters should be treated as such! string getUrl = $"{Endpoints.ActivitiesFollowers}?page={page}&per_page={perPage}&access_token={accessToken}"; string json = await _stravaWebClient.GetAsync(new Uri(getUrl)); var results = Unmarshaller <List <ActivitySummary> > .Unmarshal(json).Select(activity => { StravaService.SetMetricUnits(activity, defaultDistanceUnitType); return(activity); }).ToList(); _perflog.GetFollowersActivitiesAsync(true, page, perPage); return(results); } catch (Exception ex) { #if !DEBUG _errorMessage.Clear(); _errorMessage.AppendLine($"StravaActivityService.GetFollowersActivitiesAsync - page {page} - perPage {perPage}"); _errorMessage.AppendLine(ex.Message); ServiceLocator.Current.GetInstance <IGoogleAnalyticsService>().Tracker.SendException(_errorMessage.ToString(), false); #endif } return(null); }
/// <summary> /// Updates the sex of the currently authenticated athlete. /// </summary> /// <param name="gender">The gender to update to.</param> /// <returns>The currently authenticated athlete.</returns> public async Task <Athlete> UpdateAthleteSex(Gender gender) { string putUrl = string.Format("{0}?sex={1}&access_token={2}", Endpoints.Athlete, gender.ToString().Substring(0, 1), Authentication.AccessToken); string json = await WebRequest.SendPutAsync(new Uri(putUrl)); return(Unmarshaller <Athlete> .Unmarshal(json)); }
public async Task <List <ActivitySummary> > HydrateActivityData(string data) { var defaultDistanceUnitType = await _settingsService.GetStoredDistanceUnitTypeAsync(); List <ActivitySummary> results; if (data != null) { results = Unmarshaller <List <ActivitySummary> > .Unmarshal(data).Select(activity => { StravaService.SetMetricUnits(activity, defaultDistanceUnitType); if (!string.IsNullOrEmpty(activity.Map.SummaryPolyline)) { activity.Map.GoogleImageApiUrl = $"http://maps.googleapis.com/maps/api/staticmap?sensor=false&maptype={"roadmap"}&size={480}x{220}&scale=2&path=weight:4|color:0xff0000ff|enc:{activity.Map.SummaryPolyline}&key={StravaIdentityConstants.GOOGLE_MAP_API}"; } return(activity); }).ToList(); } else { results = new List <ActivitySummary>(); } return(results); }
/// <summary> /// Receives the currently authenticated athlete. /// </summary> /// <returns>The currently authenticated athlete.</returns> public Athlete GetAthlete() { string getUrl = string.Format("{0}?access_token={1}", Endpoints.Athlete, Authentication.AccessToken); string json = WebRequest.SendGet(new Uri(getUrl)); return(Unmarshaller <Athlete> .Unmarshal(json)); }
/// <summary> /// Checks the status of an upload. /// </summary> /// <param name="uploadId">The id of the upload.</param> /// <returns>The status of the upload.</returns> public UploadStatus CheckUploadStatus(string uploadId) { string checkUrl = string.Format("{0}/{1}?access_token={2}", Endpoints.Uploads, uploadId, Authentication.AccessToken); string json = WebRequest.SendGet(new Uri(checkUrl)); return(Unmarshaller <UploadStatus> .Unmarshal(json)); }
/// <summary> /// Gets a list of friends of an athlete. /// </summary> /// <param name="athleteId">The Strava athlete id.</param> /// <returns>The list of friends of the athlete.</returns> public List <AthleteSummary> GetFriends(string athleteId) { string getUrl = string.Format("{0}/friends?access_token={1}", Endpoints.Athlete, Authentication.AccessToken); string json = WebRequest.SendGet(new Uri(getUrl)); return(Unmarshaller <List <AthleteSummary> > .Unmarshal(json)); }
public async Task <Activity> UpdateActivityAsync(string activityId, ActivityParameter parameter, string value) { string param = string.Empty; switch (parameter) { case ActivityParameter.Commute: param = "name"; break; case ActivityParameter.Description: param = "description"; break; case ActivityParameter.GearId: param = "gear_id"; break; case ActivityParameter.Name: param = "name"; break; case ActivityParameter.Private: param = "private"; break; case ActivityParameter.Trainer: param = "trainer"; break; } string putUrl = string.Format("{0}/{1}?{2}={3}&access_token={4}", "https://www.strava.com/api/v3/activities", activityId, param, value, Authentication.AccessToken); return(Unmarshaller <Activity> .Unmarshal(await WebRequest.SendPutAsync(new Uri(putUrl)))); }
/// <summary> /// Get a list of athletes that both you and the specified athlete are following. /// </summary> /// <param name="athleteId">The Strava athlete id.</param> /// <returns>A list of athletes that both you and the specified athlete are following.</returns> public List <AthleteSummary> GetBothFollowing(string athleteId) { string getUrl = string.Format("{0}/{1}/both-following?access_token={2}", Endpoints.Followers, athleteId, Authentication.AccessToken); string json = WebRequest.SendGet(new Uri(getUrl)); return(Unmarshaller <List <AthleteSummary> > .Unmarshal(json)); }
public Activity GetActivity(string id, bool includeEfforts) { string uriString = string.Format("{0}/{1}?include_all_efforts={2}&access_token={3}", "https://www.strava.com/api/v3/activities", id, includeEfforts, Authentication.AccessToken); string json = WebRequest.SendGet(new Uri(uriString)); return(Unmarshaller <Activity> .Unmarshal(json)); }
/// <summary> /// Updates the specified parameter of an athlete. /// </summary> /// <param name="parameter">The parameter that is being updated.</param> /// <param name="value">The value to update to.</param> /// <returns>Athlete object of the currently authenticated athlete with the updated parameter.</returns> public Athlete UpdateAthlete(AthleteParameter parameter, string value) { string putUrl = string.Empty; switch (parameter) { case AthleteParameter.City: putUrl = string.Format("{0}?city={1}&access_token={2}", Endpoints.Athlete, value, Authentication.AccessToken); break; case AthleteParameter.Country: putUrl = string.Format("{0}?country={1}&access_token={2}", Endpoints.Athlete, value, Authentication.AccessToken); break; case AthleteParameter.State: putUrl = string.Format("{0}?state={1}&access_token={2}", Endpoints.Athlete, value, Authentication.AccessToken); break; case AthleteParameter.Weight: putUrl = string.Format("{0}?weight={1}&access_token={2}", Endpoints.Athlete, value, Authentication.AccessToken); break; } string json = WebRequest.SendPut(new Uri(putUrl)); return(Unmarshaller <Athlete> .Unmarshal(json)); }
public List <ActivitySummary> GetActivities(int page, int perPage) { string uriString = string.Format("{0}?page={1}&per_page={2}&access_token={3}", "https://www.strava.com/api/v3/athlete/activities", page, perPage, Authentication.AccessToken); string json = WebRequest.SendGet(new Uri(uriString)); return(Unmarshaller <List <ActivitySummary> > .Unmarshal(json)); }
public List <ActivitySummary> GetLatestClubActivities(string clubId, int page, int perPage) { string uriString = string.Format("{0}/{1}/activities?page={2}&per_page={3}&access_token={4}", "https://www.strava.com/api/v3/clubs", clubId, page, perPage, Authentication.AccessToken); string json = WebRequest.SendGet(new Uri(uriString)); return(Unmarshaller <List <ActivitySummary> > .Unmarshal(json)); }