|
| 1 | +using RestSharp; |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
| 4 | +using System.Linq; |
| 5 | +using System.Text; |
| 6 | +using System.Threading.Tasks; |
| 7 | + |
| 8 | +namespace Biyori.API.Kitsu |
| 9 | +{ |
| 10 | + |
| 11 | + public class Kitsu |
| 12 | + { |
| 13 | + private const string BaseURL = "https://kitsu.io/api/edge"; |
| 14 | + private RestClient getClient() |
| 15 | + { |
| 16 | + var client = new RestClient(BaseURL); |
| 17 | + client |
| 18 | + .AddDefaultHeader("Accept", "application/vnd.api+json") |
| 19 | + .AddDefaultHeader("Content-Type", "application/vnd.api+json"); |
| 20 | + return client; |
| 21 | + } |
| 22 | + |
| 23 | + public Kitsu() |
| 24 | + { |
| 25 | + |
| 26 | + } |
| 27 | + /// <summary> |
| 28 | + /// - |
| 29 | + /// </summary> |
| 30 | + /// <param name="loginUser">Email or Username</param> |
| 31 | + /// <param name="Password">Password or API Key</param> |
| 32 | + public void InitializeUserClient(string loginUser, string Password) |
| 33 | + { |
| 34 | + |
| 35 | + } |
| 36 | + public async Task<KitsuPaginationModel<KitsuDataModel>> GetAnimeByBulkId(params int[] animeId) |
| 37 | + { |
| 38 | + if (animeId.Length == 0) |
| 39 | + { |
| 40 | + return null; |
| 41 | + } |
| 42 | + var rr = new RestRequest("anime", Method.GET) |
| 43 | + .AddQueryParameter("page[limit]", "20") |
| 44 | + .AddQueryParameter("filter[id]", string.Join(",", animeId.Distinct().Select(x => x.ToString()))); |
| 45 | + var client = this.getClient(); |
| 46 | + var response = await client.ExecuteTaskAsync<KitsuPaginationModel<KitsuDataModel>>(rr); |
| 47 | + return response.Data; |
| 48 | + } |
| 49 | + public async Task<KitsuDataModel> GetAnimeById(int animeId) |
| 50 | + { |
| 51 | + var rr = new RestRequest("anime", Method.GET) |
| 52 | + .AddQueryParameter("page[limit]", "1") |
| 53 | + .AddQueryParameter("filter[id]", animeId.ToString()); |
| 54 | + var client = this.getClient(); |
| 55 | + var response = await client.ExecuteTaskAsync<KitsuPaginationModel<KitsuDataModel>>(rr); |
| 56 | + return response.Data?.Data?.FirstOrDefault(); |
| 57 | + } |
| 58 | + public async Task<KitsuPaginationModel<KitsuDataModel>> SearchByTitle(string searchQuery, int perPage = 10) |
| 59 | + { |
| 60 | + var rr = new RestRequest("anime", Method.GET) |
| 61 | + .AddQueryParameter("page[limit]", perPage.ToString()) |
| 62 | + .AddQueryParameter("filter[text]", searchQuery); |
| 63 | + var client = this.getClient(); |
| 64 | + var response = await client.ExecuteTaskAsync<KitsuPaginationModel<KitsuDataModel>>(rr); |
| 65 | + return response.Data; |
| 66 | + } |
| 67 | + } |
| 68 | +} |
0 commit comments