public void GetActivityLogsListAsync_Errors() { Func <HttpResponseMessage> responseMessage = Helper.CreateErrorResponse(HttpStatusCode.BadRequest); Action <HttpRequestMessage, CancellationToken> verification = new Action <HttpRequestMessage, CancellationToken>((message, token) => { Assert.AreEqual(HttpMethod.Get, message.Method); }); FitbitClient fitbitClient = Helper.CreateFitbitClient(responseMessage, verification); Func <Task <ActivityLogsList> > result = () => fitbitClient.GetActivityLogsListAsync(null, new DateTime(2017, 1, 1)); result.ShouldThrow <FitbitRequestException>().Which.ApiErrors.Count.Should().Be(1); }
private async Task <ActivityLogsList> GetActivityLogsList2(DateTime date) { string content = SampleDataHelper.GetContent("GetActivityLogsList2.json"); Func <HttpResponseMessage> responseMessage = new Func <HttpResponseMessage>(() => new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(content) }); Action <HttpRequestMessage, CancellationToken> verification = new Action <HttpRequestMessage, CancellationToken>((message, token) => { Assert.AreEqual(HttpMethod.Get, message.Method); Assert.AreEqual("https://api.fitbit.com/1/user/-/activities/list.json?afterDate=2017-09-04&sort=asc&limit=20&offset=0", message.RequestUri.AbsoluteUri); }); FitbitClient fitbitClient = Helper.CreateFitbitClient(responseMessage, verification); ActivityLogsList response = await fitbitClient.GetActivityLogsListAsync(date); return(response); }
public async Task GetActivityLogsListAsync_Success() { string content = SampleDataHelper.GetContent("GetActivityLogsList.json"); Func <HttpResponseMessage> responseMessage = new Func <HttpResponseMessage>(() => new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(content) }); Action <HttpRequestMessage, CancellationToken> verification = new Action <HttpRequestMessage, CancellationToken>((message, token) => { Assert.AreEqual(HttpMethod.Get, message.Method); Assert.AreEqual("https://api.fitbit.com/1/user/-/activities/list.json?afterDate=2017-01-01&sort=asc&limit=20&offset=0", message.RequestUri.AbsoluteUri); }); FitbitClient fitbitClient = Helper.CreateFitbitClient(responseMessage, verification); ActivityLogsList response = await fitbitClient.GetActivityLogsListAsync(null, new DateTime(2017, 1, 1)); ValidateActivity(response.Activities); }
/// <inheritdoc/> public async Task <JsonResult> GetFitBitActivityHistory(FitBitAuthenticationToken authToken) { await Task.Delay(0); FitbitAppCredentials credentials = new FitbitAppCredentials() { ClientId = "22CCZ8", ClientSecret = "d73f338b7121d347da36be95000c959b" }; Fitbit.Api.Portable.OAuth2.OAuth2AccessToken accessToken = new Fitbit.Api.Portable.OAuth2.OAuth2AccessToken() { Token = authToken.AccessToken, ExpiresIn = authToken.ExpiresIn, RefreshToken = authToken.RefreshToken, TokenType = authToken.TokenType, UserId = authToken.UserId, }; var client = new FitbitClient(credentials, accessToken); var lastMonth = DateTime.UtcNow; lastMonth.AddMonths(-7); var retrievedActivities = await client.GetActivityLogsListAsync(null, lastMonth); List <Activities> listOfRuns = new List <Activities>(); foreach (var activity in retrievedActivities.Activities) { // 90009 is a run. if (activity.ActivityTypeId == 90009) { listOfRuns.Add(activity); } } return(new JsonResult(new ActivityLogsList { Activities = listOfRuns })); }