/// <summary>
        /// GetFat has to doe some custom manipulation with the returned representation
        /// </summary>
        /// <param name="serializer"></param>
        /// <param name="fatJson"></param>
        /// <returns></returns>
        internal static Fat GetFat(this JsonDotNetSerializer serializer, string fatJson)
        {
            if (string.IsNullOrWhiteSpace(fatJson))
            {
                throw new ArgumentNullException("fatJson", "fatJson can not be empty, null or whitespace");
            }

            var fatlogs = JToken.Parse(fatJson)["fat"];
            var fat = new Fat();
            fat.FatLogs = fatlogs.Children().Select(serializer.Deserialize<FatLog>).ToList();
            return fat;
        }
        /// <summary>
        /// GetFat has to doe some custom manipulation with the returned representation
        /// </summary>
        /// <param name="serializer"></param>
        /// <param name="fatJson"></param>
        /// <returns></returns>
        internal static Fat GetFat(this JsonDotNetSerializer serializer, string fatJson)
        {
            if (string.IsNullOrWhiteSpace(fatJson))
            {
                throw new ArgumentNullException("fatJson", "fatJson can not be empty, null or whitespace");
            }

            //Convert or parse to json query for "fat" collection
            var fatlogs = JToken.Parse(fatJson)["fat"];
            var fat = new Fat();

            //Deserialise into a list of FatLog objects
            fat.FatLogs = fatlogs.Children().Select(serializer.Deserialize<FatLog>).ToList();
            return fat;
        }
Пример #3
0
        //example using the direct API call getting all the individual logs
        public ActionResult MonthFat(string id)
        {
            DateTime dateStart = Convert.ToDateTime(id);

            FitbitClient client = GetFitbitClient();

            Fat fat = client.GetFat(dateStart, DateRangePeriod.OneMonth);

            if (fat == null || fat.FatLogs == null) //succeeded but no records
            {
                fat = new Fat();
                fat.FatLogs = new List<FatLog>();
            }
            return View(fat);

        }
Пример #4
0
        private void ValidateFat(Fat fat)
        {
            Assert.IsNotNull(fat);

            Assert.AreEqual(2, fat.FatLogs.Count);

            var log = fat.FatLogs.First();
            Assert.IsNotNull(log);

            Assert.AreEqual(new DateTime(2012, 3, 5), log.Date);
            Assert.AreEqual(1330991999000, log.LogId);
            Assert.AreEqual(14, log.Fat);
            Assert.AreEqual(new DateTime(2012, 3,5,23,59,59).TimeOfDay, log.Time.TimeOfDay);

            fat.FatLogs.Remove(log);
            log = fat.FatLogs.First();

            Assert.IsNotNull(log);

            Assert.AreEqual(new DateTime(2012, 3, 5), log.Date);
            Assert.AreEqual(1330991999000, log.LogId);
            Assert.AreEqual(13.5, log.Fat);
            Assert.AreEqual(new DateTime(2012, 3, 5, 21, 20, 59).TimeOfDay, log.Time.TimeOfDay);

        }