Smakolykytl2Epub/Utils/Ranobe.cs

36 lines
1.3 KiB
C#
Raw Normal View History

2023-08-13 06:59:16 -04:00
using Smakolykytl2Epub.Models;
using Newtonsoft.Json;
using JsonSerializer = System.Text.Json.JsonSerializer;
namespace Smakolykytl2Epub.Utils;
public class Ranobe
{
private static readonly HttpClient Client = new HttpClient();
private const string ApiUrl = "https://api.smakolykytl.site/api/user/";
private const string SiteUrl = "https://smakolykytl.site/";
public static async Task<Projects?> GetById(int id)
{
var response = await Client.GetAsync(ApiUrl + "projects/" + id.ToString());
var content = await response.Content.ReadAsStringAsync();
// Console.WriteLine(content);
return JsonConvert.DeserializeObject<Projects>(content);
}
public static async Task<Books?> GetChaptersById(int id)
{
var response = await Client.GetAsync(ApiUrl + "projects/" + id.ToString() + "/books");
var content = await response.Content.ReadAsStringAsync();
// Console.WriteLine(content);
return JsonConvert.DeserializeObject<Books>(content);
}
public static async Task<Chapters?> GetChapterById(int id)
{
var response = await Client.GetAsync(ApiUrl + "chapters/" + id.ToString());
var content = await response.Content.ReadAsStringAsync();
// Console.WriteLine(content);
return JsonConvert.DeserializeObject<Chapters>(content);
}
}