public static async Task <List <Country> > GetCountries() { List <Country> Contries = new List <Country>(); string URL = BASE_URL + GET_COUNTRIES_ENDPOINT; using (HttpClient client = new HttpClient()) { HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, URL); foreach (string[] customHeader in CUSTOM_HEADERS) { requestMessage.Headers.Add(customHeader[0].ToString(), customHeader[1].ToString()); } var response = await client.SendAsync(requestMessage); string jsonString = await response.Content.ReadAsStringAsync(); APICountry json = JsonConvert.DeserializeObject <APICountry>(jsonString); Contries = json.api.countries; } return(Contries); }
public async Task <CovidCountry> GetHistoryCountry(string country) { using (HttpClient client = new HttpClient()) { string requestUri = "https://disease.sh/v3/covid-19/historical/" + country + "?lastdays=all"; HttpResponseMessage apiResponse = await client.GetAsync(requestUri); string jsonResponse = await apiResponse.Content.ReadAsStringAsync(); APICountry aPICountry = JsonConvert.DeserializeObject <APICountry>(jsonResponse); List <string> dateTimes = new List <string>(); List <int> cases = new List <int>(); List <int> deaths = new List <int>(); List <int> casesperday = new List <int>(); foreach (KeyValuePair <string, int> date in aPICountry.Timeline.Cases) { //TODO A faire en revenant sur du DateTime! //dateTimes.Add(DateTime.ParseExact(date.Key, "M/d/yy", System.Globalization.CultureInfo.InvariantCulture)); dateTimes.Add(date.Key); cases.Add(date.Value); } for (var i = 0; i < cases.Count; i++) { if (i == 0) { casesperday.Add(0); } else { casesperday.Add(cases[i] - cases[i - 1]); } } foreach (KeyValuePair <string, int> date in aPICountry.Timeline.Deaths) { deaths.Add(date.Value); } return(new CovidCountry() { CountryName = aPICountry.Country, Dates = dateTimes, Cases = cases, Deaths = deaths, CasePerDay = casesperday }); } }