Beispiel #1
0
        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);
        }
Beispiel #2
0
        static async Task fetchCheckInsAsync(int untappdId, int?minId)
        {
            System.Console.Write($"Fetching Checkins for {untappdId}...");

            Info beer = await UntappdClient.Beer(untappdId).Info().Compact().GetDataAsync();

            if (beer == null)
            {
                System.Console.WriteLine("BID Not Found");
                return;
            }

            System.Console.WriteLine($"{beer.Name} ({beer.Brewery.Name})");

            if (minId == null)   //Find any existing CheckIn data for this beer and use that if within 10 days
            {
                DateTime minIdThreshhold = DateTime.Today.AddDays(-10);
                minId = _dal.CheckIns.Where(x => x.UntappdId == untappdId && x.Timestamp >= minIdThreshhold)
                        .Select(x => (int?)x.Id).DefaultIfEmpty().Max();
            }

            BeerCheckinsEndpoint checkins = UntappdClient.Beer(untappdId).Checkins();

            if (minId != null)
            {
                checkins = checkins.MinId((int)minId);
            }

            List <Checkin> c = await checkins.GetDataAsync();

            if (c == null)
            {
                System.Console.WriteLine("No Checkins Retrieved.");
                return;
            }

            IEnumerable <CheckIn> c2 = c.Select(x => new CheckIn {
                Id        = x.Id,
                UntappdId = untappdId,
                Rating    = x.Rating == 0 ? beer.Rating : x.Rating,
                Timestamp = x.CreatedAt
            });

            foreach (Checkin checkin in c)
            {
                System.Console.WriteLine($"{checkin.Rating} {checkin.CreatedAt}");
            }

            if (_checkins == null)
            {
                _checkins = new List <CheckIn>();
            }

            _checkins.AddRange(c2);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
 public static BeerCheckinsEndpoint MinDate(this BeerCheckinsEndpoint endpoint, DateTime date)
 {
     endpoint.MinDate = date;
     return(endpoint);
 }
Beispiel #5
0
 public static BeerCheckinsEndpoint MaxResults(this BeerCheckinsEndpoint endpoint, int count)
 {
     endpoint.MaxId = count;
     return(endpoint);
 }
Beispiel #6
0
 public static BeerCheckinsEndpoint MaxId(this BeerCheckinsEndpoint endpoint, int id)
 {
     endpoint.MaxId = id;
     return(endpoint);
 }