Example #1
0
        public TestBase()
        {
            var token = Token.GetToken();

            token.Should().NotBeNull("because token should be in directory {0} or environment variable {1}",
                                     Token.SearchPath, Token.EnvironmentVariable);

            _client = new GiantBombRestClient(token);
        }
Example #2
0
        public IActionResult ViewInventoryItems(string searchString)
        {
            // Get API key:
            string apikey    = config.GetConnectionString("GiantBombAPI");
            var    giantBomb = new GiantBombRestClient(apikey);

            if (!String.IsNullOrEmpty(searchString))
            {
                var results = giantBomb.SearchForAllGames(searchString);
                Log.Information("Successfully got inventory items");
                return(View(results));
            }
            return(View(new List <GiantBomb.Api.Model.Game>()));
        }
Example #3
0
        public static List <Game> Search(string q, int page)
        {
            lock (Lock)
            {
                var client = new GiantBombRestClient(ApiKey);

                WaitToProceed();

                var retval = client.SearchForGames(q, page, 10).ToList();

                _lastRequest = DateTime.UtcNow;

                return(retval);
            }
        }
Example #4
0
        public static Game GetGame(int id)
        {
            lock (Lock)
            {
                var client = new GiantBombRestClient(ApiKey);

                WaitToProceed();

                var retval = client.GetGame(id);

                _lastRequest = DateTime.UtcNow;

                return(retval);
            }
        }
        /// <summary>
        /// Gets a video game's details
        /// </summary>
        /// <param name="id">ID of the video game you wish to get</param>
        /// <returns>DetailsView</returns>
        public IActionResult Details(int id)
        {
            List <SelectListItem> options = Enumerable.Range(1, 10)
                                            .Select(n => new SelectListItem
            {
                Value = n.ToString(),
                Text  = n.ToString()
            }).ToList();

            ViewBag.QuantityOptions = options;

            //user = HttpContext.Session.GetObject<User>("User");
            //if (user == null)
            //{
            //    Log.Error("User session was not found");
            //    return RedirectToAction("Login", "Home");
            //}
            if (ModelState.IsValid)
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(url);
                    var response = client.GetAsync($"videogame/get?id={id}");
                    response.Wait();

                    var result = response.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        var jsonString = result.Content.ReadAsStringAsync();
                        jsonString.Wait();

                        Log.Information($"Successfully got videogame: {id}");

                        var    model     = JsonConvert.DeserializeObject <VideoGame>(jsonString.Result);
                        string apikey    = config.GetConnectionString("GiantBombAPI");
                        var    giantBomb = new GiantBombRestClient(apikey);
                        var    game      = giantBomb.GetGame(model.apiId);

                        return(View(model));
                    }
                }
            }
            Log.Error($"Unsuccessfully got videogame: {id}");
            return(View());
        }
Example #6
0
        public IActionResult AddInventoryItem(string name, int id)
        {
            if (ModelState.IsValid)
            {
                InventoryItemViewModel model = new InventoryItemViewModel();
                model.name  = name;
                model.apiId = id;

                // Get API key:
                string apikey    = config.GetConnectionString("GiantBombAPI");
                var    giantBomb = new GiantBombRestClient(apikey);
                var    game      = giantBomb.GetGame(id);
                model.imageURL    = game.Image.SmallUrl;
                model.description = game.Description;
                model.description = game.Description;

                // Get Locations
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(url);
                    var response = client.GetAsync("location/getAll");
                    response.Wait();
                    var result = response.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        var jsonString = result.Content.ReadAsStringAsync();
                        jsonString.Wait();
                        var locations       = JsonConvert.DeserializeObject <List <Location> >(jsonString.Result);
                        var locationOptions = new List <SelectListItem>();
                        foreach (var l in locations)
                        {
                            locationOptions.Add(new SelectListItem {
                                Selected = false, Text = $"{l.street}, {l.city}, {l.state}, {l.zipCode}", Value = l.id.ToString()
                            });
                        }
                        ViewBag.locationOptions = locationOptions;
                    }
                }
                return(View(model));
            }
            return(View());
        }
 public ViewGameModel()
 {
     _client = new GiantBombRestClient("e5b38cec2a076c4dba1022ca4f95b41a8662d638");
 }
Example #8
0
 public void Setup()
 {
     var token = Token.GetToken();
     _client = new GiantBombRestClient(token);
 }
Example #9
0
 public void Setup()
 {
     var token = Token.GetToken();
     _client = new GiantBombRestClient(token, new Uri("http://www.giantbomb.com/api/"));
 }
Example #10
0
        public void Setup()
        {
            var token = Token.GetToken();

            _client = new GiantBombRestClient(token);
        }
 public IndexModel(giantbombTest.Models.dbContext context)
 {
     _context = context;
     _client  = new GiantBombRestClient("e5b38cec2a076c4dba1022ca4f95b41a8662d638");
 }