/// <summary> /// Get latest related to a specific country based on the country code. /// </summary> /// <param name="countryCode">The country code.</param> /// <returns>Total confirmed cases and deaths in the country.</returns> public static async Task <Latest> GetLatestAboutCountryByCodeAsync(string countryCode) { var request = new RestRequest( $"{COUNTRYCODE_QUERY_PARAMS}{countryCode.ToUpper()}", Method.GET, DataFormat.Json); IRestResponse response = await client.ExecuteGetAsync(request).ConfigureAwait(false); if (response.IsSuccessful && response.StatusCode.HasFlag(HttpStatusCode.OK)) { JObject jsonObject = JObject.Parse(response.Content); CoronavirusOutbreakData data = jsonObject.ToObject <CoronavirusOutbreakData>(); if (data.Locations.Count > 0) { return(data.Latest); } } throw new Exception("No data found. Please, provide the correct country code !"); }
/// <summary> /// Gets the Coordinates(Longitude and Latitude), the latest data about the /// country and the last updated date based on the country name. /// </summary> /// <param name="countryName">The country name.</param> /// <returns>The Location of the country, his latest covid-19 data and the last updated date.</returns> public static async Task <Location> GetLocationWithDataByNameAsync(string countryName) { var request = new RestRequest( $"{LOCATIONS_ENDPOINT}", Method.GET, DataFormat.Json); IRestResponse response = await client.ExecuteGetAsync(request).ConfigureAwait(false); if (response.IsSuccessful && response.StatusCode.HasFlag(HttpStatusCode.OK)) { JObject jsonObject = JObject.Parse(response.Content); CoronavirusOutbreakData data = jsonObject.ToObject <CoronavirusOutbreakData>(); //Get the location object using the country name var location = data.Locations.Where(l => l.Country.ToLower().Equals(countryName.ToLower()) && l.Province == "") .FirstOrDefault(); if (location != null) { return(location); } } throw new Exception("No data found. Please, provide the correct country name in English language !"); }