add additional overloads for script plugin web request helper

This commit is contained in:
RaidMax 2023-04-13 21:36:21 -05:00
parent e8ab56cd9b
commit 520a76a15e
2 changed files with 17 additions and 5 deletions

View File

@ -28,16 +28,29 @@ public class ScriptPluginHelper
RequestUrl(new ScriptPluginWebRequest(url), callback); RequestUrl(new ScriptPluginWebRequest(url), callback);
} }
public void GetUrl(string url, string bearerToken, Delegate callback)
{
var headers = new Dictionary<string, string> { { "Authorization", $"Bearer {bearerToken}" } };
RequestUrl(new ScriptPluginWebRequest(url, Headers: headers), callback);
}
public void GetUrl(string url, Dictionary<string, string> headers, Delegate callback) public void GetUrl(string url, Dictionary<string, string> headers, Delegate callback)
{ {
RequestUrl(new ScriptPluginWebRequest(url, Headers: headers), callback); RequestUrl(new ScriptPluginWebRequest(url, Headers: headers), callback);
} }
public void PostUrl(string url, Dictionary<string, string> headers, Delegate callback) public void PostUrl(string url, string body, string bearerToken, Delegate callback)
{ {
RequestUrl(new ScriptPluginWebRequest(url, null, "POST", Headers: headers), callback); var headers = new Dictionary<string, string> { { "Authorization", $"Bearer {bearerToken}" } };
RequestUrl(
new ScriptPluginWebRequest(url, body, "POST", Headers: headers), callback);
} }
public void PostUrl(string url, string body, Dictionary<string, string> headers, Delegate callback)
{
RequestUrl(new ScriptPluginWebRequest(url, body, "POST", Headers: headers), callback);
}
public void RequestUrl(ScriptPluginWebRequest request, Delegate callback) public void RequestUrl(ScriptPluginWebRequest request, Delegate callback)
{ {
Task.Run(() => Task.Run(() =>
@ -77,7 +90,6 @@ public class ScriptPluginHelper
{ {
var entered = false; var entered = false;
using var tokenSource = new CancellationTokenSource(RequestTimeout); using var tokenSource = new CancellationTokenSource(RequestTimeout);
using var client = new HttpClient(); using var client = new HttpClient();
try try

View File

@ -278,7 +278,7 @@ public class ScriptPluginV2 : IPluginV2
typeof(ScriptPluginExtensions), typeof(LoggerExtensions)) typeof(ScriptPluginExtensions), typeof(LoggerExtensions))
.AllowClr(typeof(System.Net.Http.HttpClient).Assembly, typeof(EFClient).Assembly, .AllowClr(typeof(System.Net.Http.HttpClient).Assembly, typeof(EFClient).Assembly,
typeof(Utilities).Assembly, typeof(Encoding).Assembly, typeof(CancellationTokenSource).Assembly, typeof(Utilities).Assembly, typeof(Encoding).Assembly, typeof(CancellationTokenSource).Assembly,
typeof(Data.Models.Client.EFClient).Assembly, typeof(IW4MAdmin.Plugins.Stats.Plugin).Assembly) typeof(Data.Models.Client.EFClient).Assembly, typeof(IW4MAdmin.Plugins.Stats.Plugin).Assembly, typeof(ScriptPluginWebRequest).Assembly)
.CatchClrExceptions() .CatchClrExceptions()
.AddObjectConverter(new EnumsToStringConverter())); .AddObjectConverter(new EnumsToStringConverter()));