/// <summary> /// Update Activity Updates the given activity that is owned by the authenticated athlete. Requires activity:write. Also requires activity:read_all in order to update Only Me activities /// </summary> /// <param name="id">The identifier of the activity.</param> /// <param name="body"></param> /// <returns>DetailedActivity</returns> public DetailedActivity UpdateActivityById(long?id, UpdatableActivity body) { // verify the required parameter 'id' is set if (id == null) { throw new ApiException(400, "Missing required parameter 'id' when calling UpdateActivityById"); } var path = "/activities/{id}"; path = path.Replace("{format}", "json"); path = path.Replace("{" + "id" + "}", ApiClient.ParameterToString(id)); var queryParams = new Dictionary <String, String>(); var headerParams = new Dictionary <String, String>(); var formParams = new Dictionary <String, String>(); var fileParams = new Dictionary <String, FileParameter>(); String postBody = null; postBody = ApiClient.Serialize(body); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { "strava_oauth" }; // make the HTTP request IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings); if (((int)response.StatusCode) >= 400) { throw new ApiException((int)response.StatusCode, "Error calling UpdateActivityById: " + response.Content, response.Content); } else if (((int)response.StatusCode) == 0) { throw new ApiException((int)response.StatusCode, "Error calling UpdateActivityById: " + response.ErrorMessage, response.ErrorMessage); } return((DetailedActivity)ApiClient.Deserialize(response.Content, typeof(DetailedActivity), response.Headers)); }
// ReSharper disable once UnusedMember.Global public async Task FixActivityType() { var page = 1; var activities = await this.client.Activities.GetActivitiesAsync(page ++, 30); while (activities.Any()) { foreach (var activity in activities) { try { if (activity.Type == ActivityType.Workout) { if (Enum.TryParse(activity.Name, out ActivityIdEnum moveActivity)) { var newType = this.MovescountTypeToStravaType(moveActivity); if (newType == ActivityType.Workout) { this.logger.LogWarning( $"Type of activity {activity.Id} of name '{activity.Name}' must be resolved manually."); continue; } var activityData = this.client.Activities.GetActivity(activity.Id.ToString(), false); var update = new UpdatableActivity { Commute = activityData.IsCommute, Description = activityData.Description, Name = activityData.Name, Private = activityData.IsPrivate, Trainer = activityData.IsTrainer, Type = newType }; using (var wc = new WebClient()) { wc.Headers.Add("Authorization", $"Bearer {this.accessToken}"); wc.Headers.Add("Content-Type", "application/json"); wc.UploadString($"https://www.strava.com/api/v3/activities/{activity.Id}", "PUT", JsonConvert.SerializeObject(update)); } } else { this.logger.LogWarning( $"Type of activity {activity.Id} of name '{activity.Name}' must be resolved manually."); } } } catch (Exception ex) { this.logger.LogError($"Error while updating type of activity {activity.Id}"); this.logger.LogError(ex.Message); this.logger.LogError(ex.StackTrace); throw; } activities = await this.client.Activities.GetActivitiesAsync(page ++, 30); } } }
public virtual IActionResult UpdateActivityById([FromRoute][Required] long?id, [FromBody] UpdatableActivity body) { //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(200, default(DetailedActivity)); //TODO: Uncomment the next line to return response 0 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(0, default(Fault)); string exampleJson = null; exampleJson = "\"\""; var example = exampleJson != null ? JsonConvert.DeserializeObject <DetailedActivity>(exampleJson) : default(DetailedActivity); //TODO: Change the data returned return(new ObjectResult(example)); }