public async void GetGameById(Authentication authentication, string id) { using (HttpClient httpClient = new HttpClient()) { UriBuilder builder = new UriBuilder(url); builder.Query = "id=" + id; httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authentication.access_token); httpClient.DefaultRequestHeaders.Add("Client-ID", authentication.client_id); var response = await httpClient.GetAsync(builder.Uri); Task <string> responseJson = response.Content.ReadAsStringAsync(); responseJson.Wait(); GamesModel games = JsonConvert.DeserializeObject <GamesModel>(responseJson.Result); foreach (var v in games.Data) { Data.Add(v); } } }
public void GetTopGames(Authentication authentication) { this.Data = new ObservableCollection <GameInfo>(); using (HttpClient httpClient = new HttpClient()) { UriBuilder builder = new UriBuilder(ConfigurationManager.AppSettings["urlTopGame"]); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authentication.access_token); httpClient.DefaultRequestHeaders.Add("Client-ID", authentication.client_id); HttpResponseMessage response = httpClient.GetAsync(builder.Uri).Result; Task <string> responseJson = response.Content.ReadAsStringAsync(); responseJson.Wait(); GamesModel games = JsonConvert.DeserializeObject <GamesModel>(responseJson.Result); foreach (var itens in games.Data) { Data.Add(itens); } } }