1
1
mirror of https://github.com/CyberL1/MyMcRealms.git synced 2024-12-23 21:08:22 -05:00

Start implementing my-mc api

This commit is contained in:
CyberL1 2024-04-20 10:42:23 +02:00
parent 01fb04f34e
commit 31bc0663a6
3 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,22 @@
using Minecraft_Realms_Emulator.MyMcAPIResponses;
namespace Minecraft_Realms_Emulator.Helpers
{
public class MyMcAPI
{
private readonly string ApiUrl = "https://api.my-mc.link";
private readonly HttpClient httpClient = new();
public MyMcAPI(string apiKey)
{
httpClient.DefaultRequestHeaders.Add("x-my-mc-auth", apiKey);
httpClient.BaseAddress = new Uri(ApiUrl);
}
public async void GetHello()
{
var response = await httpClient.GetFromJsonAsync<MyMcHelloResponse>("hello");
Console.WriteLine(response.Message);
}
}
}

View File

@ -0,0 +1,7 @@
namespace Minecraft_Realms_Emulator.MyMcAPIResponses
{
public class MyMcHelloResponse
{
public string Message { get; set; } = string.Empty;
}
}

View File

@ -13,6 +13,12 @@ if (Environment.GetEnvironmentVariable("CONNECTION_STRING") == null)
return;
}
if (Environment.GetEnvironmentVariable("MYMC_API_KEY") == null)
{
Console.WriteLine("MYMC_API_KEY environment variable missing");
return;
}
// Add services to the container.
builder.Services.AddControllers().AddJsonOptions(x => x.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles);
@ -45,4 +51,7 @@ app.UseMiddleware<MinecraftCookieMiddleware>();
app.MapControllers();
var mymc = new MyMcAPI(Environment.GetEnvironmentVariable("MYMC_API_KEY"));
mymc.GetHello();
app.Run();