39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using System.Collections.Generic;
|
|
using System;
|
|
using System.Diagnostics;
|
|
using Http;
|
|
// using Newtonsoft.Json;
|
|
|
|
public class FunctionRequest
|
|
{
|
|
private static FunctionRequest _instance;
|
|
public static FunctionRequest Instance => _instance ??= new FunctionRequest();
|
|
|
|
public void Invoke(string method, string body, Action<string> complete)
|
|
{
|
|
HttpDebug.Log($"function name:{method}");
|
|
var http = HttpManager.Instance.Post($"functions/{method}", info => OnResult(info, complete));
|
|
http.AddToken();
|
|
http.AddParameter(body);
|
|
http.Send();
|
|
}
|
|
|
|
private void OnResult(ResultInfo info, Action<string> complete)
|
|
{
|
|
if (info.State != RequestState.Success)
|
|
{
|
|
complete?.Invoke("");
|
|
return;
|
|
}
|
|
|
|
// var data = JsonConvert.DeserializeObject<RequestData>(info.Response.DataAsText);
|
|
// Debug.Assert(data != null, nameof(data) + " != null");
|
|
// if (data.code == 0)
|
|
// {
|
|
// complete?.Invoke("");
|
|
// return;
|
|
// }
|
|
complete?.Invoke(info.Response.DataAsText);
|
|
}
|
|
}
|