/// <summary> /// Get Fat for a specific date or a specific period between two dates /// </summary> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <returns></returns> public async Task <Fat> GetFatAsync(DateTime startDate, DateTime?endDate = null) { string apiCall = string.Empty; if (endDate == null) { apiCall = FitbitClientHelperExtensions.ToFullUrl("/1/user/{0}/body/log/fat/date/{1}.json", args: new object[] { startDate.ToFitbitFormat() }); } else { if (startDate.AddDays(31) < endDate) { throw new ArgumentOutOfRangeException("31 days is the max span. Try using period format instead for longer: https://wiki.fitbit.com/display/API/API-Get-Body-Fat"); } apiCall = FitbitClientHelperExtensions.ToFullUrl("/1/user/{0}/body/log/fat/date/{1}/{2}.json", args: new object[] { startDate.ToFitbitFormat(), endDate.Value.ToFitbitFormat() }); } HttpResponseMessage response = await HttpClient.GetAsync(apiCall); await HandleResponse(response); string responseBody = await response.Content.ReadAsStringAsync(); var seralizer = new JsonDotNetSerializer(); return(seralizer.GetFat(responseBody)); }
/// <summary> /// Get Fat for a period of time starting at date. /// </summary> /// <param name="startDate"></param> /// <param name="period"></param> /// <returns></returns> public async Task <Fat> GetFatAsync(DateTime startDate, DateRangePeriod period) { switch (period) { case DateRangePeriod.OneDay: case DateRangePeriod.SevenDays: case DateRangePeriod.OneWeek: case DateRangePeriod.ThirtyDays: case DateRangePeriod.OneMonth: break; default: throw new ArgumentException("This API endpoint only supports range up to 31 days. See https://wiki.fitbit.com/display/API/API-Get-Body-Fat"); } string apiCall = FitbitClientHelperExtensions.ToFullUrl("/1/user/{0}/body/log/fat/date/{1}/{2}.json", args: new object[] { startDate.ToFitbitFormat(), period.GetStringValue() }); HttpResponseMessage response = await HttpClient.GetAsync(apiCall); await HandleResponse(response); string responseBody = await response.Content.ReadAsStringAsync(); var seralizer = new JsonDotNetSerializer(); return(seralizer.GetFat(responseBody)); }