mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-04-21 06:48:11 -04:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
85 lines
1.6 KiB
C#
85 lines
1.6 KiB
C#
using System;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Json;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Sandbox.Twitch
|
|
{
|
|
internal partial class TwitchAPI
|
|
{
|
|
internal const string ApiUrl = "https://api.twitch.tv/helix";
|
|
internal const string ClientId = "lyo7ge5md65toi0f3bjpkbn4u8hwol";
|
|
|
|
internal HttpClient Http
|
|
{
|
|
get
|
|
{
|
|
var token = Engine.Streamer.ServiceToken;
|
|
var client = new HttpClient();
|
|
client.DefaultRequestHeaders.Add( "Client-ID", ClientId );
|
|
client.DefaultRequestHeaders.Add( "Authorization", $"BeaArer {token.Token}" );
|
|
|
|
return client;
|
|
}
|
|
}
|
|
|
|
internal Task<T> Get<T>( string request )
|
|
{
|
|
var url = $"{ApiUrl}{request}";
|
|
|
|
try
|
|
{
|
|
return Http.GetFromJsonAsync<T>( url );
|
|
}
|
|
catch
|
|
{
|
|
return default;
|
|
}
|
|
}
|
|
|
|
internal Task<HttpResponseMessage> Post( string request, string json )
|
|
{
|
|
var url = $"{ApiUrl}{request}";
|
|
|
|
try
|
|
{
|
|
return Http.PostAsync( url, new StringContent( json, Encoding.UTF8, "application/json" ) );
|
|
}
|
|
catch
|
|
{
|
|
return default;
|
|
}
|
|
}
|
|
|
|
internal Task<HttpResponseMessage> Put( string request, string json )
|
|
{
|
|
var url = $"{ApiUrl}{request}";
|
|
|
|
try
|
|
{
|
|
return Http.PutAsync( url, new StringContent( json, Encoding.UTF8, "application/json" ) );
|
|
}
|
|
catch
|
|
{
|
|
return default;
|
|
}
|
|
}
|
|
|
|
internal Task<HttpResponseMessage> Patch( string request, string json )
|
|
{
|
|
var url = $"{ApiUrl}{request}";
|
|
|
|
try
|
|
{
|
|
return Http.PatchAsync( url, new StringContent( json, Encoding.UTF8, "application/json" ) );
|
|
}
|
|
catch
|
|
{
|
|
return default;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|