Globanet.cs
3.19 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.IO;
namespace Globanet
{
public enum RequestMethod
{
GET,
POST,
PUT,
DELETE
};
[System.Serializable]
public class RequestData
{
public string endpoint { get; set; }
public string url { get; set; }
public string authentication { get; set; }
public RequestMethod method { get; set; }
public object data { get; set; }
public Dictionary<string, string> headers { get; set; }
public System.Action<ResponseData> callback { get; set; }
}
public class ResponseData
{
public RequestData request { get; set; }
public string text { get; set; }
public int errorCode { get; set; }
public string error { get; set; }
public object data { get; set; }
public ResponseData()
{
errorCode = -1;
}
}
/*public class CmsSettings
{
private const string _path = "/cmsSettings.json";
private static IDictionary _json;
public static string url
{
get
{
Initialize();
string url = GetValue("url").ToString();
if (url[url.Length - 1] == '/')
url = url.Substring(0, url.Length - 1);
return url;
}
}
public static IDictionary endpoints
{
get
{
Initialize();
IDictionary dict = JsonConvert.DeserializeObject<IDictionary>(GetValue("endpoints").ToString());
return dict;
}
}
public static string GetEndpointValue(string key)
{
IDictionary dict = endpoints;
if (!dict.Contains(key))
{
Debug.Log("Key " + key + " does not exist in CMS settings file");
return string.Empty;
}
return dict[key].ToString();
}
private static void Initialize()
{
if (_json != null) return;
InitializeFile();
_json = JsonConvert.DeserializeObject<IDictionary>(
File.ReadAllText(Application.streamingAssetsPath + _path)
);
}
private static void InitializeFile()
{
if (!Directory.Exists(Application.streamingAssetsPath))
Directory.CreateDirectory(Application.streamingAssetsPath);
if (!File.Exists(Application.streamingAssetsPath + _path))
{
var newDict = new Dictionary<string, object>()
{
{ "url", "replaceThisUrl.com" },
{ "authorization", string.Empty },
{ "endpoints", new Dictionary<string, string>() }
};
File.WriteAllText((Application.streamingAssetsPath + _path),
JsonConvert.SerializeObject(newDict, Formatting.Indented ));
}
}
private static object GetValue(string key)
{
return _json[key];
}
}*/
}