public async Task GetTrending_ReturnsTrendingBeers()
        {
            var client = new UntappdClient(AccessToken);

            TrendingResponse trendingResponse = await client.GetTrending();

            Assert.IsNotNull(trendingResponse);
        }
        public async Task AddToWishList_AddsBeerToWishList()
        {
            var client = new UntappdClient(AccessToken);

            AddOrRemoveFromWishListResponse wishListResponse = await client.AddToWishList(101);

            Assert.IsNotNull(wishListResponse);
        }
        public async Task GetNotifications_ReturnsListOfNotifications()
        {
            var client = new UntappdClient(AccessToken);

            NotificationsResponse notifications = await client.GetNotifications();

            Assert.IsNotNull(notifications);
        }
Esempio n. 4
0
        public CheckinResultViewModel()
        {
            Result = new CheckinResponse();

            if (!String.IsNullOrEmpty(App.ViewModel.UntappdUsername) && !String.IsNullOrEmpty(App.ViewModel.UntappdPassword)) {
                _client = new UntappdClient(App.ViewModel.UntappdUsername, App.ViewModel.UntappdPassword, App.ApiKey);
            } else {
                _client = new UntappdClient(App.ApiKey);
            }
        }
Esempio n. 5
0
        public BreweryViewModel()
        {
            Result = new BreweryInfoResult();

            if (!String.IsNullOrEmpty(App.ViewModel.UntappdUsername) && !String.IsNullOrEmpty(App.ViewModel.UntappdPassword)) {
                _client = new UntappdClient(App.ViewModel.UntappdUsername, App.ViewModel.UntappdPassword, App.ApiKey);
            } else {
                _client = new UntappdClient(App.ApiKey);
            }
        }
        public async Task RemoveFromWishList_RemovesItem()
        {
            var client = new UntappdClient(AccessToken);


            //Responds with 200 but doesnt seem to do anything??
            AddOrRemoveFromWishListResponse notifications = await client.RemovefromWishList(101);

            Assert.IsNotNull(notifications);
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
        public ActionResult LookUp(int beerId)
        {
            string clientId     = KeyVault.GetSecret("untappd-clientid").Result;
            string clientSecret = KeyVault.GetSecret("untappd-clientsecret").Result;

            UntappdClient client = UntappdClient.Create(clientId, clientSecret);

            ViewBag.Message = client.Lookup(beerId);

            return(View("Message"));
        }
Esempio n. 9
0
        public BeerViewModel()
        {
            Result = new BeerInfoResult();

            if (!String.IsNullOrEmpty(App.ViewModel.UntappdUsername) && !String.IsNullOrEmpty(App.ViewModel.UntappdPassword)) {
                _client = new UntappdClient(App.ViewModel.UntappdUsername, App.ViewModel.UntappdPassword, App.ApiKey);
                SignedIn = true;
            } else {
                _client = new UntappdClient(App.ApiKey);
            }
        }
Esempio n. 10
0
        public UserViewModel()
        {
            User = new User();
            Recent = new ObservableCollection<ItemViewModel>();

            if (!String.IsNullOrEmpty(App.ViewModel.UntappdUsername) && !String.IsNullOrEmpty(App.ViewModel.UntappdPassword)) {
                _client = new UntappdClient(App.ViewModel.UntappdUsername, App.ViewModel.UntappdPassword, App.ApiKey);
            } else {
                _client = new UntappdClient(App.ApiKey);
            }
        }
Esempio n. 11
0
        static async Task searchAsync(string query)
        {
            System.Console.WriteLine($"Searching Beers for \"{query}\"...");

            Task <List <BeerItem> > search  = UntappdClient.Search().Beer(query).GetAsync();
            List <BeerItem>         results = await search;

            foreach (BeerItem item in results)
            {
                Beer beer = item.Beer;
                System.Console.WriteLine($"{beer.Name} ({item.Brewery.Name}) [{item.Beer.Rating}]");
            }

            return;
        }
Esempio n. 12
0
        public JsonResult AddItem(BoxItem item, string userId, int exchangeId)
        {
            string id = BifSessionData.IsInRole("ADMIN") ? userId ?? BifSessionData.Id : BifSessionData.Id;

            Exchange exchange = DAL.Context.Exchanges.Find(BifSessionData.ExchangeId);

            if (exchange == null || exchange.CloseDate.AddDays(30) < DateTime.Today)
            {
                return(Json(new { Success = false, Message = "This Exchange is now closed. The box may no longer be edited" }));
            }

            if (item.UntappdId != null)
            {
                UntappdClient untappdClient = UntappdClient.Create();
                Beer          beer          = untappdClient.Lookup(item.UntappdId.Value);
                item.Name          = $"{beer.Name} ({beer.Brewery.Name})";
                item.UntappdRating = beer.Rating;
            }

            Item entity = new Item {
                UserId        = id,
                ExchangeId    = exchangeId,
                Format        = item.Format,
                Name          = item.Name,
                Type          = item.Type,
                UntappdId     = item.UntappdId,
                USOunces      = item.USOunces,
                Cost          = item.Cost,
                UntappdRating = item.UntappdRating
            };

            DAL.Context.Items.Add(entity);
            DAL.Context.SaveChanges();

            return(Json(new {
                Success = true,
                UserId = id,
                Id = entity.Id,
                ExchangeId = BifSessionData.ExchangeId,
                Format = item.Format,
                Name = item.Name,
                Type = item.Type,
                UntappdId = item.UntappdId,
                USOunces = item.USOunces,
                Cost = item.Cost,
                UntappdRating = item.UntappdRating == null ? null : Math.Round(item.UntappdRating ?? 0, 2).ToString("0.00")
            }));
        }
Esempio n. 13
0
        public JsonResult SearchAsync(string q)
        {
            string clientId     = KeyVault.GetSecret("untappd-clientid").Result;
            string clientSecret = KeyVault.GetSecret("untappd-clientsecret").Result;

            UntappdClient client = UntappdClient.Create(clientId, clientSecret);

            BeerSearchResult searchResult = client.Search(q);

            var results = searchResult.Beers.Items.Select(x => new {
                x.Beer.Id,
                Name = x.Beer.Name,
                x.Beer.Rating,
                Brewery = x.Brewery.Name
            });

            return(Json(results, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        ///     Invoked when a filter is selected using the ComboBox in snapped view state.
        /// </summary>
        /// <param name="sender">The ComboBox instance.</param>
        /// <param name="e">Event data describing how the selected filter was changed.</param>
        public async void Filter_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // Determine what filter was selected
            var selectedFilter = e.AddedItems.FirstOrDefault() as Filter;
            if (selectedFilter != null)
            {
                // Mirror the results into the corresponding Filter object to allow the
                // RadioButton representation used when not snapped to reflect the change
                selectedFilter.Active = true;

                // TODO: Respond to the change in active filter by setting this.DefaultViewModel["Results"]
                //       to a collection of items with bindable Image, Title, Subtitle, and Description properties

                var client = new UntappdClient(Configuration.AccessToken);

                BeerSearchResponse beers = await client.BeerSearch(DefaultViewModel["QueryText"].ToString());

                DefaultViewModel["Results"] = beers.Beers.Items.Select(b => new BeerSearchItem(b.Beer.BeerName, b.Brewery.BreweryName, b.Beer.BeerStyle, b.Beer.BeerLabel, b)).ToList();

                // Ensure results are found
                object results;
                ICollection resultsCollection;
                bool tryGetValue = DefaultViewModel.TryGetValue("Results", out results);
                ICollection collection = resultsCollection = results as ICollection;
                if (tryGetValue &&
                    collection != null &&
                    resultsCollection.Count != 0)
                {
                    VisualStateManager.GoToState(this, "ResultsFound", true);
                    return;
                }
            }

            // Display informational text when there are no search results.
            VisualStateManager.GoToState(this, "NoResultsFound", true);
        }
Esempio n. 15
0
        public void InitClient(StatusControl status)
        {
            _status = status;

            if (!String.IsNullOrEmpty(UntappdUsername) && !String.IsNullOrEmpty(UntappdPassword)) {
                _client = new UntappdClient(UntappdUsername, UntappdPassword, App.ApiKey);
            } else {
                _client = new UntappdClient(App.ApiKey);
            }

            _client.TrendingComplete += (sender, e) => {
                Trending.Clear();
                foreach (var result in e.Result.Results) {
                    Trending.Add(new ItemViewModel() {
                        LineOne = result.BeerName.ToLower(),
                        IdOne = result.BeerId.ToString(),
                        LineTwo = result.BreweryName.ToLower(),
                        IdTwo = result.BreweryId
                    });
                }
                _status.HideProgress();
            };
            _client.UserFeedComplete += (sender, e) => {
                if (e.Result.FeedType == "Friend") {
                    Friends.Clear();
                    foreach (var result in e.Result.Results.OrderByDescending(i => DateTime.Parse(i.CreatedAt))) {
                        if (result != null) {
                            Friends.Add(new ItemViewModel() {
                                LineOne = result.User.DisplayName.ToLower(),
                                IdOne = result.User.UserName,
                                LineTwo = result.BeerName.ToLower(),
                                IdTwo = result.BeerId.ToString(),
                                LineThree = result.BreweryName.ToLower(),
                                IdThree = result.BreweryId,
                                LineFour = result.DisplayCreatedTimeAgo,
                                Image = result.User.AvatarUrl,
                                LineFive = String.IsNullOrEmpty(result.CheckinComment) ? null : result.CheckinComment.ToLower()
                            });
                        }
                    }
                    _status.HideProgress();
                } else if (e.Result.FeedType == "User") {
                    if (e.Result.Results.Length > 0) {
                        // profile
                        Recent.Clear();
                        foreach (var result in e.Result.Results.OrderByDescending(i => DateTime.Parse(i.CreatedAt))) {
                            if (result != null) {
                                Recent.Add(new ItemViewModel() {
                                    LineOne = result.BeerName.ToLower(),
                                    IdOne = result.BeerId.ToString(),
                                    LineTwo = result.BreweryName.ToLower(),
                                    IdTwo = result.BreweryId,
                                    LineThree = result.DisplayCreatedTimeAgo,
                                    LineFour = String.IsNullOrEmpty(result.CheckinComment) ? null : result.CheckinComment.ToLower()
                                });
                            }
                        }
                    }
                    _status.HideProgress();
                }
            };
            _client.UserInfoComplete += (sender, e) => {
                var user = e.Result.Results.User;
                if (user.UserName == UntappdUsername) {
                    user.FirstName = user.FirstName.ToLower();
                    user.LastName = user.LastName.ToLower();
                    user.Location = user.Location.ToUpper();
                    User = user;
                }
                _status.HideProgress();
            };

            _client.BeerSearchResultsComplete += (sender, e) => {
                Results.Clear();
                foreach (var result in e.Result.Results) {
                    Results.Add(new ItemViewModel() {
                        LineOne = result.Name.ToLower(),
                        IdOne = result.BeerId.ToString(),
                        LineTwo = result.BreweryName.ToLower(),
                        IdTwo = result.BreweryId
                    });
                }
                _searchComplete = true;
                NotifyPropertyChanged("NoResults");
                _status.HideProgress();
            };

            _client.RemoteError += (sender, e) => {
                _status.HideProgress();
                _status.ShowError(e.Result.Error != null ? e.Result.Error.Message : e.Result.ErrorMessage);
            };
        }
Esempio n. 16
0
        private void SignIn_Click(object sender, RoutedEventArgs e)
        {
            _status.ShowProgress();
            var client = new UntappdClient(_loginUsername.Text, _loginPassword.Password, App.ApiKey);
            client.CheckinComplete += (s, ea) => {
                _status.HideProgress();
                if (ea.Result.HttpCode != 200) {
                    _loginFailure.Text = ea.Result.ErrorMessage;
                    _loginFailure.Visibility = Visibility.Visible;
                } else {
                    _loginFailure.Visibility = Visibility.Collapsed;
                    _loginFailure.Text = "";

                    App.ViewModel.UntappdUsername = _loginUsername.Text;
                    App.ViewModel.UntappdPassword = _loginPassword.Password;

                    CredentialUtility.StoreCredentials();

                    _loginGrid.Visibility = Visibility.Collapsed;
                    _needLoginBlock.Visibility = Visibility.Collapsed;
                    _profileGrid.Visibility = Visibility.Visible;
                    _friendsList.Visibility = Visibility.Visible;

                    App.ViewModel.InitClient(_status);

                    App.ViewModel.LoadUserInfo();
                    App.ViewModel.LoadPersonalFeeds();
                }
            };
            client.RemoteError += (s, ea) => {
                _status.HideProgress();
                _loginFailure.Text = ea.Result.ErrorMessage;
                _loginFailure.Visibility = Visibility.Visible;
            };

            client.CheckInBeer(1, -5, null, null, null, null, null, false, false, false, true);
        }