Ejemplo n.º 1
0
        /// <summary>
        /// Added new API query that will get all the information about current game
        /// </summary>
        public async Task <GameInformationModel> GetGame(GameSearchResult searchedGame)
        {
            // Request message that will be sent to API endpoint
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, GAME_URL);

            string jsonPost = $"fields *; where name = \"{searchedGame.Name}\";";

            // Adding Accept header to make sure that output will be json
            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            request.Headers.Add("user-key", API_KEY); // Add user-key to header

            // Added json body to request
            request.Content = new StringContent(jsonPost, Encoding.UTF8, "application/json");

            // Request message is asynchronously posted
            HttpResponseMessage response = await httpClient.SendAsync(request);

            // Read json body of the response
            string jsonResponse = await response.Content.ReadAsStringAsync();

            List <GameInformationModel> games = JsonConvert.DeserializeObject <List <GameInformationModel> >(jsonResponse);

            return(games[0]);
        }
        /// <summary>
        /// Gets all information about current game.
        /// And sets it to the ScrollViewer -> GameInformation
        /// </summary>
        /// <param name="game">Current game</param>
        private async void GetGameInformation(GameSearchResult game)
        {
            GameInformationModel gameInfo = await apiEngine.GetGame(game);

            mWindowModel.GameContent = new GameInformationPage(gameInfo);
        }