-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpHandler.cs
More file actions
59 lines (50 loc) · 1.55 KB
/
HttpHandler.cs
File metadata and controls
59 lines (50 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System.Collections.Specialized;
using UnityEngine;
namespace HttpHandler
{
internal abstract class Controller
{
public abstract string requestPath { get; }
public abstract APIType type { get; }
public abstract JsonResult Get(NameValueCollection parameters, ShowOffWebAPI showOffWebApi);
}
class JsonResult
{
public int status_code;
public string message;
public object data;
public static JsonResult OK(string message, object data = null)
{
return CreateResult(200, message, data);
}
public static JsonResult Failed(string message, object data = null)
{
return CreateResult(403, message, data);
}
public static JsonResult NotFound(string message, object data = null)
{
return CreateResult(404, message, data);
}
private static JsonResult CreateResult(int statusCode, string message, object data = null)
{
JsonResult result = new JsonResult
{
status_code = statusCode,
message = message,
data = data
};
return result;
}
public string ToJson()
{
string noDataJson = JsonUtility.ToJson(this);
string dataJson = (data != null) ? JsonUtility.ToJson(data) : "\"\"";
return $"{noDataJson.Substring(0, noDataJson.Length - 1)},\"data\":{dataJson}}}";
}
}
enum APIType
{
Public,
Private
}
}