Exemple #1
0
        public async Task <WorkoutSessionMetrics> GetWorkoutMetricsAsync(RideDatum ride, ILogger logger, string SaveJsonPath = null)
        {
            using (var client = new WebClient())
            {
                client.Headers["accept"] = "application/json";
                string url = $"https://api.onepeloton.com/api/workout/{ride.id}/performance_graph?every_n=1";

                if (logger != null)
                {
                    logger.Log($"Downloading metrics for workout: {ride.ride.title} on {Util.DateTimeFromEpochSeconds(ride.device_time_created_at).ToShortDateString()}");
                }
                var response = await client.DownloadStringTaskAsync(url);

                Debug.WriteLine("  " + response.Substring(0, 50));
                Debug.WriteLine($"  Length: {response.Length}");
                if (logger != null)
                {
                    logger.Log($"Done downloading");
                }

                if (SaveJsonPath != null)
                {
                    var formattedJson = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(response, JSonSerializerSettings), Formatting.Indented, JSonSerializerSettings);
                    File.WriteAllText(SaveJsonPath, formattedJson);
                }
                WorkoutSessionMetrics session = JsonConvert.DeserializeObject <WorkoutSessionMetrics>(response, JSonSerializerSettings);
                return(session);
            }
        }
Exemple #2
0
        public async Task <UserWorkoutDetails> GetWorkoutUserDetails(RideDatum ride, ILogger logger, string SaveJsonPath = null)
        {
            //https://api.onepeloton.com/api/workout/887f8325e5a14ba0be00705aaa6f2db1
            using (var client = new WebClient())
            {
                string url = $"https://api.onepeloton.com/api/workout/{ride.id}";
                if (logger != null)
                {
                    logger.Log($"Downloading user ride details for workout: {ride.ride.title} on {Util.DateTimeFromEpochSeconds(ride.device_time_created_at).ToShortDateString()}");
                }
                var response = await client.DownloadStringTaskAsync(url);

                Debug.WriteLine("  " + response.Substring(0, 50));
                Debug.WriteLine($"  Length: {response.Length}");
                if (logger != null)
                {
                    logger.Log($"Done downloading");
                }

                if (SaveJsonPath != null)
                {
                    var formattedJson = JToken.Parse(response).ToString(Formatting.Indented);
                    File.WriteAllText(SaveJsonPath, formattedJson);
                }
                UserWorkoutDetails userDetails = JsonConvert.DeserializeObject <UserWorkoutDetails>(response, JSonSerializerSettings);
                return(userDetails);
            }
        }
Exemple #3
0
        public async Task <EventDetails> GetWorkoutEventDetails(RideDatum ride, ILogger logger, string SaveJsonPath = null)
        {
            using (var client = new WebClient())
            {
                client.Headers["accept"] = "application/json";
                string url = $"https://api.onepeloton.com/api/ride/{ride.ride.id}/details";

                if (logger != null)
                {
                    logger.Log($"Downloading details for workout: {ride.ride.title} on {Util.DateTimeFromEpochSeconds(ride.device_time_created_at).ToShortDateString()}");
                }
                var response = await client.DownloadStringTaskAsync(url);

                Debug.WriteLine("  " + response.Substring(0, 50));
                Debug.WriteLine($"  Length: {response.Length}");
                if (logger != null)
                {
                    logger.Log($"Done downloading");
                }

                if (SaveJsonPath != null)
                {
                    var formattedJson = JToken.Parse(response).ToString(Formatting.Indented);
                    File.WriteAllText(SaveJsonPath, formattedJson);
                }
                EventDetails details = JsonConvert.DeserializeObject <EventDetails>(response, JSonSerializerSettings);
                return(details);
            }
        }
Exemple #4
0
        public string GetFileNameBaseFromRideDatum(RideDatum ride)
        {
            Regex  rgx      = new Regex("[^a-zA-Z0-9]");
            string str      = rgx.Replace(ride.ride.title, "_");
            string filename = Util.DateTimeFromEpochSeconds(ride.device_time_created_at).ToString("yyy-dd-MM_HH-mm") + "_" + str;

            return(filename);
        }