public static async Task <List <Checkin> > GetDataAsync(this BeerCheckinsEndpoint endpoint) { string url = endpoint.GenerateUrl(); List <Checkin> checkins = new List <Checkin>(); DateTime minDate; do { HttpResponseMessage responseMesage = await endpoint.Service.Client.GetAsync(url); if (!responseMesage.IsSuccessStatusCode) { return(null); } string json = await responseMesage.Content.ReadAsStringAsync(); ResponseWrapper <CheckinsResponse> checkinsResponseWrapper = JsonConvert.DeserializeObject <ResponseWrapper <CheckinsResponse> >(json); checkins.AddRange(checkinsResponseWrapper.Response.Checkins.Items); minDate = checkinsResponseWrapper.Response.Checkins.Items.Min(x => x.CreatedAt); url = checkinsResponseWrapper.Response.Pagination.SinceUrl; } while (url != null && checkins.Count < endpoint.MaxResults && minDate > endpoint.MinDate); return(checkins); }
public static async Task <ResponseWrapper <CheckinsResponse> > GetAsync(this BeerCheckinsEndpoint endpoint) { string url = endpoint.GenerateUrl(); HttpResponseMessage responseMesage = await endpoint.Service.Client.GetAsync(url); if (!responseMesage.IsSuccessStatusCode) { return(null); } string json = await responseMesage.Content.ReadAsStringAsync(); ResponseWrapper <CheckinsResponse> checkinsResponseWrapper = JsonConvert.DeserializeObject <ResponseWrapper <CheckinsResponse> >(json); checkinsResponseWrapper.Response.Checkins.Items = checkinsResponseWrapper.Response.Checkins.Items .Where(x => x.CreatedAt >= endpoint.MinDate).ToList(); return(checkinsResponseWrapper); }