-
Notifications
You must be signed in to change notification settings - Fork 0
/
Class.cs
64 lines (58 loc) · 1.61 KB
/
Class.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.ComponentModel;
using System.Net;
using System.Net.Http;
using System.Numerics;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace RemAPIWrapper
{
public class RemAPI
{
private string Token;
private ulong ClientId;
private HttpClient Client = new HttpClient();
public RemAPI(string Token, ulong ClientId)
{
this.Token = Token;
this.ClientId = ClientId;
}
public enum ImageType
{
Rem = 0,
Emilia = 1,
Ram = 2,
Thighs = 3,
Neko = 4
}
/// <summary>Get an image with a certain type
/// <para>Returns <see cref="string"/></para>
/// </summary>
public async Task<string> GetImage(ImageType Type, bool IsNSFW)
{
if (Type == ImageType.Thighs && !IsNSFW)
{
throw new Exception("NSFW must be true for Thighs endpoint");
}
else if (Type == ImageType.Neko && !IsNSFW)
{
throw new Exception("NSFW must be true for Neko endpoint");
}
Client.DefaultRequestHeaders.Add("Authorization", Token);
Client.DefaultRequestHeaders.Add("ClientId", ClientId.ToString());
var request = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri("https://api.rembot.cc/api/v1/images"),
Content = new StringContent($@"{{
""ImageType"":""{Type}"",
""IsNsfw"":""{IsNSFW}""}}", Encoding.UTF8, "application/json"),
};
var response = await Client.SendAsync(request).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
var responseInfo = await response.Content.ReadAsStringAsync();
return responseInfo;
}
}
}