Updated to Levi's cat fact API
This commit is contained in:
parent
a5f94715c3
commit
ed7e22cfed
|
@ -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>();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue