Updated to Levi's cat fact API

This commit is contained in:
Deukhoofd 2018-06-03 20:39:39 +02:00
parent a5f94715c3
commit ed7e22cfed
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
1 changed files with 3 additions and 4 deletions

View File

@ -10,20 +10,19 @@ namespace DeukBot4.APIHandlers
{
public static class CatFactsApi
{
private const string URL = "https://catfact.ninja/";
private const string URL = "http://api.levi506.net/";
public static async Task<string> GetRandomCatFact()
{
var client = new HttpClient {BaseAddress = new Uri(URL)};
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = await client.GetAsync("facts?limit=1"); // Blocking call!
var response = await client.GetAsync("fact/animal/cat"); // Blocking call!
if (!response.IsSuccessStatusCode)
return null;
var res = await response.Content.ReadAsStringAsync();
var json = JObject.Parse(res);
var a = json["data"].AsEnumerable();
return a.First()["fact"].Value<string>();
return json["fact"].Value<string>();
}
}