public async Task <LeagueTable> GetTable(int competitionID) { var URI = $"league.json?comp={ competitionID }"; using (var response = await APIClient.Client.GetAsync(URI)) { if (response.IsSuccessStatusCode) { string responseJson = await response.Content.ReadAsStringAsync(); LeagueTableRoot root = JsonConvert.DeserializeObject <LeagueTableRoot>(responseJson); return(root.LeagueTable); } else { throw new Exception(response.ReasonPhrase); } } }
public async Task <LeagueTableRoot> GetTable(int competitionID) { string responseJson = ""; LeagueTableRoot root = null; using (var client = new HttpClient()) { var URI = string.Format("http://www.footballwebpages.co.uk/league.json?comp={0}", competitionID); client.BaseAddress = new Uri(URI); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = await client.GetAsync(URI); if (response.IsSuccessStatusCode) { responseJson = await response.Content.ReadAsStringAsync(); root = JsonConvert.DeserializeObject <LeagueTableRoot>(responseJson); } } return(root); }