public async Task <Models.API.v3.Search.SearchGamesResponse> SearchGamesAsync(string query, GameSearchType type = GameSearchType.Suggest, bool live = false) { var getParams = new List <KeyValuePair <string, string> > { // Checks? new KeyValuePair <string, string>("query", query), new KeyValuePair <string, string>("live", live.ToString().ToLower()) }; switch (type) { case GameSearchType.Suggest: getParams.Add(new KeyValuePair <string, string>("type", "suggest")); break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } return(await Api.GetGenericAsync <Models.API.v3.Search.SearchGamesResponse>("https://api.twitch.tv/kraken/search/games", getParams, null, ApiVersion.v3).ConfigureAwait(false)); }
/// <summary> /// Fills game collection based on various search options /// </summary> private async void getGames() { try { if (String.IsNullOrEmpty(searchString)) { // Check if previous search way by name and sets page number and search type if (searchType == GameSearchType.ByName) { pageNumber = 1; searchType = GameSearchType.EmptySearch; } IEnumerable<Game> games = await gamesService.GetRangeAsync( new Utilities.GenericFilter(pageNumber, MAX_NUMBER_OF_ITEMS_ON_PAGE)); // Game should be set to null, before clearing game list , since it's selected item in games list Game = null; gamesCollection.Clear(); foreach (Game game in games) gamesCollection.Add(game); } else { // Checks if previous search way empty search and sets page number and search type if (searchType == GameSearchType.EmptySearch) { pageNumber = 1; searchType = GameSearchType.ByName; } IEnumerable<Game> games = await gamesService.GetRangeAsync(searchString, new Utilities.GenericFilter(pageNumber, MAX_NUMBER_OF_ITEMS_ON_PAGE)); // Game should be set to null, before clearing game list , since it's selected item in games list Game = null; gamesCollection.Clear(); foreach (Game game in games) gamesCollection.Add(game); } sizeAndPageNumberChecks(); } catch (Exception ex) { // TODO implement string so that UI can have alert box with exception throw ex; } }