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:
parent
01fb04f34e
commit
31bc0663a6
22
MyMcRealms/Helpers/MyMcAPI.cs
Normal file
22
MyMcRealms/Helpers/MyMcAPI.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
7
MyMcRealms/MyMcAPIResponses/MyMcHelloResponse.cs
Normal file
7
MyMcRealms/MyMcAPIResponses/MyMcHelloResponse.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace Minecraft_Realms_Emulator.MyMcAPIResponses
|
||||
{
|
||||
public class MyMcHelloResponse
|
||||
{
|
||||
public string Message { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user