Ejemplo n.º 1
0
        /// <summary>
        /// Gets the latest activities of the currently authenticated athletes followers.
        /// </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 List <ActivitySummary> GetFollowersActivities(int page, int perPage)
        {
            String getUrl = String.Format("{0}?page={1}&per_page={2}&access_token={3}", Endpoints.ActivitiesFollowers, page, perPage, Authentication.AccessToken);
            String json   = WebRequest.SendGet(new Uri(getUrl));

            return(Unmarshaller <List <ActivitySummary> > .Unmarshal(json));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets a list of athletes that kudoed the specified activity asynchronously.
        /// </summary>
        /// <param name="activityId">The Strava Id of the activity.</param>
        /// <returns>A list of athletes that kudoed the specified activity.</returns>
        public async Task <List <Athlete> > GetKudosAsync(String activityId)
        {
            String getUrl = String.Format("{0}/{1}/kudos?access_token={2}", Endpoints.Activity, activityId, Authentication.AccessToken);
            String json   = await WebRequest.SendGetAsync(new Uri(getUrl));

            return(Unmarshaller <List <Athlete> > .Unmarshal(json));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Retrieves the zones of an activity.
        /// </summary>
        /// <param name="activityId">The Strava activity Id.</param>
        /// <returns>A list of activity zones of an activity.</returns>
        public List <ActivityZone> GetActivityZones(String activityId)
        {
            String getUrl = String.Format("{0}/{1}/zones?access_token={2}", Endpoints.Activity, activityId, Authentication.AccessToken);
            String json   = WebRequest.SendGet(new Uri(getUrl));

            return(Unmarshaller <List <ActivityZone> > .Unmarshal(json));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets a single activity from Strava.
        /// </summary>
        /// <param name="id">The Strava activity id.</param>
        /// <param name="includeEfforts">Indicates whether efforts are included in the result or not.</param>
        /// <returns>The activity with the specified id.</returns>
        public Activity GetActivity(String id, bool includeEfforts)
        {
            String getUrl = String.Format("{0}/{1}?include_all_efforts={2}&access_token={3}", Endpoints.Activity, id, includeEfforts, Authentication.AccessToken);
            String json   = WebRequest.SendGet(new Uri(getUrl));

            return(Unmarshaller <Activity> .Unmarshal(json));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Processes a request.
        /// </summary>
        public async void ProcessRequest()
        {
            _context = _httpListener.GetContext();
            NameValueCollection queries = _context.Request.QueryString;

            // Access Token laden
            // 0 = state
            // 1 = code
            String code = queries.GetValues(1)[0];

            if (!String.IsNullOrEmpty(code))
            {
                if (AuthCodeReceived != null)
                {
                    AuthCodeReceived(this, new AuthCodeReceivedEventArgs(code));
                }
            }

            // Save token to hard disk
            String path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StravaApi");
            String file = Path.Combine(path, "AccessToken.auth");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            FileStream stream = new FileStream(file, FileMode.OpenOrCreate);

            stream.Write(Encoding.UTF8.GetBytes(code), 0, Encoding.UTF8.GetBytes(code).Length);
            stream.Close();

            // Antwort liefen und anzeigen
            byte[] b = Encoding.UTF8.GetBytes("Access token was loaded - You can close your browser window.");
            _context.Response.ContentLength64 = b.Length;
            _context.Response.OutputStream.Write(b, 0, b.Length);
            _context.Response.OutputStream.Close();


            // Getting the Access Token
            String url  = String.Format("https://www.strava.com/oauth/token?client_id={0}&client_secret={1}&code={2}", ClientId, ClientSecret, code);
            String json = await WebRequest.SendPostAsync(new Uri(url));

            AccessToken auth = Unmarshaller <AccessToken> .Unmarshal(json);

            if (!String.IsNullOrEmpty(auth.Token))
            {
                if (AccessTokenReceived != null)
                {
                    AccessTokenReceived(this, new TokenReceivedEventArgs(auth.Token));
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets a list of all laps of an activity.
        /// </summary>
        /// <param name="activityId">The Strava id of the activity.</param>
        /// <returns>A list of laps of the activity.</returns>
        public async Task <List <ActivityLap> > GetActivityLapsAsync(String activityId)
        {
            // https://www.strava.com/api/v3/activities/:id/laps
            String getUrl = String.Format("{0}/{1}/laps?access_token={2}",
                                          Endpoints.Activity,
                                          activityId,
                                          Authentication.AccessToken);

            String json = await WebRequest.SendGetAsync(new Uri(getUrl));

            return(Unmarshaller <List <ActivityLap> > .Unmarshal(json));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Updates the type of an activity. Requires write permissions.
        /// </summary>
        /// <param name="activityId">The Strava id of the activity.</param>
        /// <param name="type">The type you want to change the activity to.</param>
        /// <returns>A detailed object of the activity that was updated. Remember that the changed type won't be updated immediately.</returns>
        public async Task <Activity> UpdateActivityTypeAsync(String activityId, ActivityType type)
        {
            String putUrl = String.Format("{0}/{1}?type={2}&access_token={3}",
                                          Endpoints.Activity,
                                          activityId,
                                          type,
                                          Authentication.AccessToken);

            String json = await WebRequest.SendPutAsync(new Uri(putUrl));

            return(Unmarshaller <Activity> .Unmarshal(json));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Returns a list of photos linked to the specified activity.
        /// </summary>
        /// <param name="activityId">The activity</param>
        /// <returns>A list of photos.</returns>
        public List <Photo> GetPhotos(String activityId)
        {
            // https://www.strava.com/api/v3/activities/:id/photos
            String getUrl = String.Format("{0}/{1}/photos?access_token={2}",
                                          Endpoints.Activity,
                                          activityId,
                                          Authentication.AccessToken);

            String json = WebRequest.SendGet(new Uri(getUrl));

            return(Unmarshaller <List <Photo> > .Unmarshal(json));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets all the activities recorded in a specified period of time.
        /// </summary>
        /// <param name="after">Date after the activity was recorded.</param>
        /// <param name="before">Date before the activity was recorded.</param>
        /// <param name="page">Page of activities. Default value is 30.</param>
        /// <param name="perPage">Number of activities per page.</param>
        /// <returns>A list of activities that was recorded between 'after' and 'before'.</returns>
        public List <ActivitySummary> GetActivities(DateTime after, DateTime before, int page, int perPage)
        {
            String getUrl = String.Format("{0}?after={1}&before={2}&page={3}&per_page={4}&access_token={5}",
                                          Endpoints.Activities,
                                          DateConverter.GetSecondsSinceUnixEpoch(after),
                                          DateConverter.GetSecondsSinceUnixEpoch(before),
                                          page,
                                          perPage,
                                          Authentication.AccessToken);
            String json = WebRequest.SendGet(new Uri(getUrl));

            return(Unmarshaller <List <ActivitySummary> > .Unmarshal(json));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Gets all the activities recorded before the specified date from Strava asynchronously.
        /// </summary>
        /// <param name="before">The date.</param>
        /// <param name="page">The page of the list of activities.</param>
        /// <param name="perPage">The amount of activities per page.</param>
        /// <returns>A list of activities recorded before the specified date.</returns>
        public async Task <List <ActivitySummary> > GetActivitiesBeforeAsync(DateTime before, int page, int perPage)
        {
            //Calculate the UNIX epoch
            long secondsBefore = DateConverter.GetSecondsSinceUnixEpoch(before);

            String getUrl = String.Format("{0}?before={1}&page={2}&per_page={3}&access_token={4}",
                                          Endpoints.Activities,
                                          secondsBefore,
                                          page,
                                          perPage,
                                          Authentication.AccessToken
                                          );

            String json = await WebRequest.SendGetAsync(new Uri(getUrl));

            return(Unmarshaller <List <ActivitySummary> > .Unmarshal(json));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets all the activities recorded after the specified date from Strava.
        /// </summary>
        /// <param name="after">The date.</param>
        /// <param name="page">The page of the list of activities.</param>
        /// <param name="perPage">The amount of activities per page.</param>
        /// <returns>A list of activities recorded after the specified date.</returns>
        public List <ActivitySummary> GetActivitiesAfter(DateTime after, int page, int perPage)
        {
            //Calculate the UNIX epoch
            long secondsAfter = DateConverter.GetSecondsSinceUnixEpoch(after);

            String getUrl = String.Format("{0}?after={1}&page={2}&per_page={3}&access_token={4}",
                                          Endpoints.Activities,
                                          secondsAfter,
                                          page,
                                          perPage,
                                          Authentication.AccessToken
                                          );

            String json = WebRequest.SendGet(new Uri(getUrl));

            return(Unmarshaller <List <ActivitySummary> > .Unmarshal(json));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Updates an activity. Requires write permissions.
        /// </summary>
        /// <param name="activityId">The Strava id of the activity that will be updated.</param>
        /// <param name="parameter">The parameter that will be updated.</param>
        /// <param name="value">The value the parameter is updated to.</param>
        /// <returns>A detailed representation of the updated activity.</returns>
        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}",
                                          Endpoints.Activity,
                                          activityId,
                                          param,
                                          value,
                                          Authentication.AccessToken);

            String json = await WebRequest.SendPutAsync(new Uri(putUrl));

            return(Unmarshaller <Activity> .Unmarshal(json));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Deletes an activity on Strava.
        /// </summary>
        /// <param name="activityId">The Strava Id of the activity to delete.</param>
        public async void DeleteActivity(String activityId)
        {
            String deleteUrl = String.Format("{0}/{1}?access_token={2}", Endpoints.Activities, activityId, Authentication.AccessToken);

            await WebRequest.SendDeleteAsync(new Uri(deleteUrl));
        }