-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYandereClient.cs
34 lines (32 loc) · 1 KB
/
YandereClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace Yande.re
{
public class YandereClient
{
private string BaseUrl = "https://yande.re/post.json?";
public async Task<List<YandereImage>> GetImagesAsync(YandereTag Tag)
{
string URL = $"{BaseUrl}{Tag.GenerateTags()}";
return await GetJsonData<YandereImage>(URL);
}
private async Task<List<T>> GetJsonData<T>(string URL) where T : new()
{
HttpClient Clinet = new HttpClient();
string JsonData = string.Empty;
try
{
JsonData = await Clinet.GetStringAsync(URL);
}
catch (Exception Ex)
{
throw Ex;
}
return !string.IsNullOrEmpty(JsonData) ? JsonConvert.DeserializeObject<List<T>>(JsonData) : new List<T>();
}
}
}