/// <summary> /// Get Weight 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 <Weight> GetWeightAsync(DateTime startDate, DateTime?endDate = null) { string apiCall; if (endDate == null) { apiCall = FitbitClientHelperExtensions.ToFullUrl("/1/user/{0}/body/log/weight/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-Weight"); } apiCall = FitbitClientHelperExtensions.ToFullUrl("/1/user/{0}/body/log/weight/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.GetWeight(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 <Weight> GetWeightAsync(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 ArgumentOutOfRangeException("This API endpoint only supports range up to 31 days. See https://wiki.fitbit.com/display/API/API-Get-Body-Weight"); } string apiCall = FitbitClientHelperExtensions.ToFullUrl("/1/user/{0}/body/log/weight/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.GetWeight(responseBody)); }