com.amanotes.gdk 0.1.21 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/CHANGELOG.md +5 -5
  2. package/Editor/AmaGDKEditor.cs +91 -46
  3. package/Editor/AmaGDKManager.cs +26 -27
  4. package/Editor/Utils/AmaGDKEditor.ExtractVersion.cs +133 -103
  5. package/Editor/Utils/AmaGDKEditor.GUI.cs +54 -51
  6. package/Editor/Utils/AmaGDKEditor.Utils.cs +2 -3
  7. package/Packages/AmaGDKConfig.unitypackage +0 -0
  8. package/Packages/AmaGDKExample.unitypackage +0 -0
  9. package/Packages/AmaGDKTest.unitypackage +0 -0
  10. package/Packages/AmaPassport.ATTSupport.unitypackage +0 -0
  11. package/Packages/AmaPassport.ATTSupport.unitypackage.meta +7 -0
  12. package/Packages/AmaPassport.AdvertisingID.unitypackage +0 -0
  13. package/Packages/AmaPassport.AdvertisingID.unitypackage.meta +7 -0
  14. package/Packages/AppsFlyerAdapter_v6.5.4.unitypackage +0 -0
  15. package/Packages/FirebaseAnalyticsAdapter_v9.1.0.unitypackage +0 -0
  16. package/Packages/FirebaseRemoteConfigAdapter_v9.1.0.unitypackage +0 -0
  17. package/Packages/FirebaseRemoteConfigAdapter_v9.1.0.unitypackage.meta +1 -1
  18. package/Packages/IronsourceAdapter_v7.2.6.unitypackage +0 -0
  19. package/Runtime/AmaGDK.Adapters.cs +13 -14
  20. package/Runtime/AmaGDK.Ads.cs +523 -151
  21. package/Runtime/AmaGDK.AmaPassport.cs +433 -0
  22. package/Runtime/AmaGDK.AmaPassport.cs.meta +11 -0
  23. package/Runtime/AmaGDK.Analytics.cs +78 -89
  24. package/Runtime/AmaGDK.Config.cs +23 -19
  25. package/Runtime/AmaGDK.Internal.SemVer.cs +11 -29
  26. package/Runtime/AmaGDK.Internal.cs +16 -11
  27. package/Runtime/AmaGDK.RemoteConfig.cs +32 -23
  28. package/Runtime/AmaGDK.UserProfile.cs +5 -8
  29. package/Runtime/AmaGDK.Utils.cs +40 -50
  30. package/Runtime/AmaGDK.WebUtils.cs +42 -42
  31. package/Runtime/AmaGDK.cs +70 -20
  32. package/Runtime/AssemblyInfo.cs +0 -1
  33. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
- using System.Text;
1
+ using System;
2
2
  using System.Collections.Generic;
3
-
3
+ using System.Text;
4
4
  using UnityEngine;
5
5
  using UnityObject = UnityEngine.Object;
6
6
  using static Amanotes.Core.AmaGDK.Analytics;
@@ -39,11 +39,11 @@ namespace Amanotes.Core.Internal
39
39
  public const string AMAGDK_PREFAB = BASE_PATH + "Runtime/AmaGDK.prefab";
40
40
  public const string AMAGDK_CONFIG_PACKAGE = PACKAGE_PATH + "AmaGDKConfig.unitypackage";
41
41
 
42
- public static readonly string[] AMAGDK_ADAPTERS = new string[]
42
+ public static readonly string[] AMAGDK_ADAPTERS =
43
43
  {
44
44
  "FirebaseAnalyticsAdapter_v9.1.0",
45
45
  "AppsFlyerAdapter_v6.5.4",
46
- // "IronsourceAdapter_v7.2.6",
46
+ "IronsourceAdapter_v7.2.6",
47
47
  "FirebaseRemoteConfigAdapter_v9.1.0"
48
48
  };
49
49
 
@@ -52,14 +52,14 @@ namespace Amanotes.Core.Internal
52
52
  [MenuItem("GameObject/AmaGDK/Add AmaGDK Prefab", false, 10)]
53
53
  private static void AddAmaGDKPrefab()
54
54
  {
55
- GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>(AMAGDK_PREFAB);
55
+ var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(AMAGDK_PREFAB);
56
56
  if (prefab == null)
57
57
  {
58
58
  Debug.LogWarning($"Prefab [AmaGDK] not found at: {AMAGDK_PREFAB}");
59
59
  return;
60
60
  }
61
61
 
62
- GameObject newPrefab = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
62
+ var newPrefab = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
63
63
  newPrefab.name = "AmaGDK";
64
64
  newPrefab.transform.SetAsLastSibling();
65
65
  Selection.activeObject = null;
@@ -104,14 +104,14 @@ namespace Amanotes.Core.Internal
104
104
  AmaGDK._instance = null;
105
105
  }
106
106
 
107
- var result = Resources.FindObjectsOfTypeAll<AmaGDK>();
107
+ AmaGDK[] result = Resources.FindObjectsOfTypeAll<AmaGDK>();
108
108
  for (var i = 0; i < result.Length; i++)
109
109
  {
110
110
  if (result[i] == null) continue;
111
111
 
112
112
  #if UNITY_EDITOR // Ignore loaded prefabs assets
113
113
  {
114
- var path = UnityEditor.AssetDatabase.GetAssetPath(result[i]);
114
+ string path = AssetDatabase.GetAssetPath(result[i]);
115
115
  if (!string.IsNullOrEmpty(path)) continue;
116
116
  }
117
117
  #endif
@@ -129,10 +129,15 @@ namespace Amanotes.Core.Internal
129
129
 
130
130
  public static void ClearAnalyticsData()
131
131
  {
132
- AnalyticsData analyticsData = AmaGDK.Analytics.localData;
132
+ AnalyticsData analyticsData = localData;
133
133
  analyticsData.funnelSignatures.Clear();
134
134
  analyticsData.eventDetails.Clear();
135
- analyticsData.migrationLog = new AmaGDK.Analytics.MigrationLog();
135
+ analyticsData.migrationLog = new MigrationLog();
136
136
  }
137
137
  }
138
- }
138
+
139
+ public interface IOnApplicationPause { void OnApplicationPause(bool pauseStatus); }
140
+ public interface IOnApplicationQuit { void OnApplicationQuit(); }
141
+ public interface IOnApplicationFocus { void OnApplicationFocus(bool hasFocus); }
142
+ public interface IOnFrameUpdate { void OnFrameUpdate(); }
143
+ }
@@ -8,7 +8,7 @@ using Amanotes.Core.Internal;
8
8
  using static Amanotes.Core.Internal.Logging;
9
9
 
10
10
  namespace Amanotes.Core
11
- {
11
+ {
12
12
  public partial class AmaGDK //Remote Config
13
13
  {
14
14
  public enum RemoteConfigSource
@@ -22,24 +22,26 @@ namespace Amanotes.Core
22
22
  [Serializable]
23
23
  public partial class RemoteConfig //Public
24
24
  {
25
+ public static Action<bool> onFetchCompleted;
25
26
  public static Dictionary<string, string> DictConfig { get { return dictConfig; } }
26
27
  public static RemoteConfigSource Source { private set; get; }
27
28
  static bool? _cacheExisted = null;
28
- public static bool HasCache {
29
+ public static bool HasCache
30
+ {
29
31
  get
30
32
  {
31
33
  if (_cacheExisted == null)
32
34
  _cacheExisted = FileUtils.Exist(fileName);
33
35
  return _cacheExisted.GetValueOrDefault();
34
36
  }
35
- }
37
+ }
36
38
 
37
- public static T ParseConfig<T>(T config = null) where T : class, new()
39
+ internal static T ParseConfig<T>(T config = null) where T : class, new()
38
40
  {
39
41
  if (config == null)
40
42
  config = new T();
41
43
 
42
- var configInJson = GetConfigAsJson();
44
+ var configInJson = GetConfigAsJsonString();
43
45
  if (string.IsNullOrEmpty(configInJson))
44
46
  {
45
47
  LogWarning("[RemoteConfig] The config is empty");
@@ -47,7 +49,7 @@ namespace Amanotes.Core
47
49
  }
48
50
 
49
51
  try
50
- {
52
+ {
51
53
  return config = JsonUtility.FromJson<T>(configInJson);
52
54
  }
53
55
  catch (Exception e)
@@ -64,11 +66,16 @@ namespace Amanotes.Core
64
66
  return defaultValue;
65
67
  }
66
68
 
67
- public static string GetConfigAsJson()
69
+ public static T WriteConfigTo<T>(T config = null) where T : class, new ()
70
+ {
71
+ return ParseConfig<T>(config);
72
+ }
73
+
74
+ public static string GetConfigAsJsonString()
68
75
  {
69
76
  return JsonUtils.DictionaryToJson(dictConfig);
70
- }
71
- }
77
+ }
78
+ }
72
79
 
73
80
  public partial class RemoteConfig //Internal
74
81
  {
@@ -98,8 +105,8 @@ namespace Amanotes.Core
98
105
  {
99
106
  { FetchState.None, new Action[]{ ResolveDependency }},
100
107
  { FetchState.ResolveDependencies, new Action[]{ LoadCache, CheckInternet}},
101
- { FetchState.CheckInternet, new Action[]{ LoadCache, Fetch}},
102
- { FetchState.Fetch, new Action[]{ LoadCache, SaveCache}},
108
+ { FetchState.CheckInternet, new Action[]{ LoadCache, Fetch}},
109
+ { FetchState.Fetch, new Action[]{ LoadCache, SaveCache}},
103
110
  { FetchState.SaveCache, new Action[]{ SetDone }},
104
111
  { FetchState.LoadCache, new Action[]{ LoadDefaultFile, SetDone}},
105
112
  { FetchState.LoadDefaultFile, new Action[]{ LoadDefaultAsset, SetDone}},
@@ -124,7 +131,7 @@ namespace Amanotes.Core
124
131
  }
125
132
 
126
133
  actions[result ? 1 : 0]();
127
- }
134
+ }
128
135
 
129
136
  static void ResolveDependency()
130
137
  {
@@ -142,7 +149,7 @@ namespace Amanotes.Core
142
149
  {
143
150
  _state = FetchState.CheckInternet;
144
151
  NextState(Application.internetReachability != NetworkReachability.NotReachable);
145
- }
152
+ }
146
153
 
147
154
  static void Fetch()
148
155
  {
@@ -153,14 +160,14 @@ namespace Amanotes.Core
153
160
  {
154
161
  NextState(false);
155
162
  return;
156
- }
163
+ }
157
164
 
158
165
  dictConfig = result;
159
166
  Source = RemoteConfigSource.Internet;
160
167
  Log("[RemoteConfig] Load from the internet");
161
168
  NextState(true);
162
169
  });
163
- }
170
+ }
164
171
 
165
172
  static void SaveCache()
166
173
  {
@@ -175,7 +182,7 @@ namespace Amanotes.Core
175
182
  FileUtils.Save(filePath, sb.ToString());
176
183
  Log($"[RemoteConfig] Saved remote config to {filePath}");
177
184
  NextState();
178
- }
185
+ }
179
186
 
180
187
  static void LoadCache()
181
188
  {
@@ -224,15 +231,15 @@ namespace Amanotes.Core
224
231
 
225
232
  static void LoadDefaultFile()
226
233
  {
227
- _state = FetchState.LoadDefaultFile;
234
+ _state = FetchState.LoadDefaultFile;
228
235
 
229
- var defaultConfigFile = Resources.Load<TextAsset>(defaultConfigFileName);
236
+ var defaultConfigFile = Resources.Load<TextAsset>(defaultConfigFileName);
230
237
  if (defaultConfigFile == null)
231
238
  {
232
239
  NextState(false);
233
240
  return;
234
241
  }
235
-
242
+
236
243
  dictConfig = JsonToDictionary(defaultConfigFile.text);
237
244
 
238
245
  Source = RemoteConfigSource.DefaultFile;
@@ -265,12 +272,14 @@ namespace Amanotes.Core
265
272
  {
266
273
  _state = FetchState.Success;
267
274
  onAdapterInitCompleteCallback(true);
275
+ onFetchCompleted?.Invoke(true);
268
276
  }
269
277
 
270
278
  static void SetFail()
271
279
  {
272
280
  _state = FetchState.Fail;
273
281
  onAdapterInitCompleteCallback(false);
282
+ onFetchCompleted?.Invoke(false);
274
283
  }
275
284
 
276
285
  static Dictionary<string, string> JsonToDictionary(string json)
@@ -294,12 +303,12 @@ namespace Amanotes.Core
294
303
  {
295
304
  value = lines[i].Substring(idx + 1).Trim();
296
305
  value = value.Substring(1, value.Length - 3);
297
- }
306
+ }
298
307
  dictResult[key] = value;
299
308
  }
300
309
  return dictResult;
301
310
  }
302
- }
311
+ }
303
312
  }
304
313
 
305
314
  public static class RemoteConfigExtension
@@ -325,7 +334,7 @@ namespace Amanotes.Core.Internal
325
334
  {
326
335
  public KeyValue[] defaultValue;
327
336
  public float firstFetchTimeOutInSeconds = 10;
328
- public float defaultTimeOutInSeconds = 3;
337
+ public float defaultTimeOutInSeconds = 3;
329
338
  }
330
339
 
331
340
  [Serializable]
@@ -336,7 +345,7 @@ namespace Amanotes.Core.Internal
336
345
  }
337
346
 
338
347
  public interface IRemoteConfig
339
- {
348
+ {
340
349
  void ResolveDependencies(Action<bool> onComplete);
341
350
  void FetchConfig(bool isFirstTime, Action<bool, Dictionary<string, string>> onComplete);
342
351
  }
@@ -1,8 +1,6 @@
1
1
  using System;
2
2
  using Amanotes.Core.Internal;
3
3
  using UnityEngine;
4
- using FileUtils = Amanotes.Core.Internal.FileUtils;
5
-
6
4
  namespace Amanotes.Core
7
5
  {
8
6
  public partial class AmaGDK //User profile
@@ -10,10 +8,10 @@ namespace Amanotes.Core
10
8
  public static readonly UserProfile User = new UserProfile().Load();
11
9
 
12
10
  [Serializable]
13
- public partial class UserProfile: IJsonFile
11
+ public partial class UserProfile : IJsonFile
14
12
  {
15
- [NonSerialized] internal bool _dirty = false;
16
- const string FILE_NAME = nameof(UserProfile);
13
+ private const string FILE_NAME = nameof(UserProfile);
14
+ [NonSerialized] internal bool _dirty;
17
15
 
18
16
  public void Save()
19
17
  {
@@ -22,9 +20,8 @@ namespace Amanotes.Core
22
20
 
23
21
  public UserProfile Load()
24
22
  {
25
- var json = FileUtils.Load(FILE_NAME);
26
- if (string.IsNullOrEmpty(json))
27
- return this;
23
+ string json = FileUtils.Load(FILE_NAME);
24
+ if (string.IsNullOrEmpty(json)) return this;
28
25
  JsonUtility.FromJsonOverwrite(json, this);
29
26
  return this;
30
27
  }
@@ -4,13 +4,27 @@ using System.Collections.Generic;
4
4
  using System.IO;
5
5
  using System.Text;
6
6
  using UnityEngine;
7
-
8
7
  using static Amanotes.Core.Internal.Logging;
9
8
 
10
9
  namespace Amanotes.Core.Internal
11
10
  {
12
11
  internal class FileUtils
13
12
  {
13
+
14
+ private static string _basePath;
15
+ private static string basePath
16
+ {
17
+ get
18
+ {
19
+ if (!string.IsNullOrEmpty(_basePath)) return _basePath;
20
+ _basePath = Application.isEditor
21
+ ? Path.Combine(Directory.GetCurrentDirectory(), "Library", "AmaGDK")
22
+ : Path.Combine(Application.persistentDataPath, "AmaGDK");
23
+
24
+ if (!Directory.Exists(_basePath)) Directory.CreateDirectory(_basePath);
25
+ return _basePath;
26
+ }
27
+ }
14
28
  internal static string GetPath(string fileName)
15
29
  {
16
30
  return Path.Combine(basePath, fileName);
@@ -25,7 +39,7 @@ namespace Amanotes.Core.Internal
25
39
  {
26
40
  if (string.IsNullOrWhiteSpace(fileName))
27
41
  {
28
- LogWarningOnce($"File name must be not null or empty");
42
+ LogWarningOnce("File name must be not null or empty");
29
43
  return;
30
44
  }
31
45
 
@@ -50,7 +64,7 @@ namespace Amanotes.Core.Internal
50
64
  {
51
65
  if (string.IsNullOrWhiteSpace(fileName))
52
66
  {
53
- LogWarningOnce($"File name must be not null or empty");
67
+ LogWarningOnce("File name must be not null or empty");
54
68
  return;
55
69
  }
56
70
 
@@ -67,14 +81,14 @@ namespace Amanotes.Core.Internal
67
81
  catch (Exception ex)
68
82
  {
69
83
  LogWarningOnce(path + "\n" + ex);
70
- }
84
+ }
71
85
  }
72
86
 
73
87
  internal static void SaveAppend(string fileName, string content)
74
88
  {
75
89
  if (string.IsNullOrWhiteSpace(fileName))
76
90
  {
77
- LogWarningOnce($"File name must be not null or empty");
91
+ LogWarningOnce("File name must be not null or empty");
78
92
  return;
79
93
  }
80
94
 
@@ -92,15 +106,15 @@ namespace Amanotes.Core.Internal
92
106
  {
93
107
  LogWarningOnce(path + "\n" + ex);
94
108
  }
95
- }
109
+ }
96
110
 
97
111
  internal static string Load(string fileName)
98
112
  {
99
- string content = "";
113
+ var content = "";
100
114
 
101
115
  if (string.IsNullOrWhiteSpace(fileName))
102
116
  {
103
- LogWarningOnce($"File name must be not null or empty");
117
+ LogWarningOnce("File name must be not null or empty");
104
118
  return content;
105
119
  }
106
120
 
@@ -132,29 +146,14 @@ namespace Amanotes.Core.Internal
132
146
  {
133
147
  LogWarningOnce(path + "\n" + ex);
134
148
  }
135
- }
136
-
137
- private static string _basePath;
138
- private static string basePath
139
- {
140
- get
141
- {
142
- if (!string.IsNullOrEmpty(_basePath)) return _basePath;
143
- _basePath = Application.isEditor
144
- ? Path.Combine(Directory.GetCurrentDirectory(), "Library", "AmaGDK")
145
- : Path.Combine(Application.persistentDataPath, "AmaGDK");
146
-
147
- if (!Directory.Exists(_basePath)) Directory.CreateDirectory(_basePath);
148
- return _basePath;
149
- }
150
149
  }
151
150
  }
152
151
 
153
152
  public class ActionQueue
154
153
  {
155
- private Queue<Action<Action>> queue;
156
- private bool isProcessing = false;
157
- private Action onComplete;
154
+ private bool isProcessing;
155
+ private readonly Action onComplete;
156
+ private readonly Queue<Action<Action>> queue;
158
157
 
159
158
  public ActionQueue(Action onComplete)
160
159
  {
@@ -170,7 +169,7 @@ namespace Amanotes.Core.Internal
170
169
  return;
171
170
  }
172
171
 
173
- foreach (var action in actions)
172
+ foreach (Action<Action> action in actions)
174
173
  {
175
174
  if (action == null) continue;
176
175
  queue.Enqueue(action);
@@ -179,8 +178,7 @@ namespace Amanotes.Core.Internal
179
178
 
180
179
  private void ProcessQueue()
181
180
  {
182
- if (isProcessing)
183
- return;
181
+ if (isProcessing) return;
184
182
  if (queue.Count == 0)
185
183
  {
186
184
  onComplete?.Invoke();
@@ -199,8 +197,7 @@ namespace Amanotes.Core.Internal
199
197
  }
200
198
  }
201
199
 
202
- if(nextAction == null)
203
- onComplete?.Invoke();
200
+ if (nextAction == null) onComplete?.Invoke();
204
201
  }
205
202
 
206
203
  public void StartQueue()
@@ -227,7 +224,7 @@ namespace Amanotes.Core.Internal
227
224
  instance = result;
228
225
  }
229
226
  string fileName = instance.GetType().Name;
230
- var json = FileUtils.Load(fileName);
227
+ string json = FileUtils.Load(fileName);
231
228
  JsonUtility.FromJsonOverwrite(json, instance);
232
229
  return instance;
233
230
  }
@@ -235,7 +232,7 @@ namespace Amanotes.Core.Internal
235
232
  public static void SaveJsonToFile<T>(this T instance) where T : IJsonFile
236
233
  {
237
234
  string fileName = instance.GetType().Name;
238
- var json = JsonUtility.ToJson(instance);
235
+ string json = JsonUtility.ToJson(instance);
239
236
  FileUtils.Save(fileName, json);
240
237
  }
241
238
  }
@@ -244,7 +241,7 @@ namespace Amanotes.Core.Internal
244
241
  {
245
242
  public static string TupleToJson(params (string key, object value)[] parameters)
246
243
  {
247
- Dictionary<string, object> tupleToDict = new Dictionary<string, object>();
244
+ var tupleToDict = new Dictionary<string, object>();
248
245
  foreach (var item in parameters)
249
246
  {
250
247
  tupleToDict.Add(item.key, item.value);
@@ -254,24 +251,21 @@ namespace Amanotes.Core.Internal
254
251
 
255
252
  public static string KeyValueToJson(string key, object value)
256
253
  {
257
- return DictionaryToJson(new Dictionary<string, object>() { { key, value } });
254
+ return DictionaryToJson(new Dictionary<string, object>
255
+ { { key, value } });
258
256
  }
259
257
 
260
258
  public static string DictionaryToJson(IDictionary inputDict, bool format = false, bool checkJsonInString = true)
261
259
  {
262
- if (inputDict == null)
263
- return "{}";
260
+ if (inputDict == null) return "{}";
264
261
 
265
- StringBuilder jsonSb = new StringBuilder();
262
+ var jsonSb = new StringBuilder();
266
263
  jsonSb.Append("{");
267
264
  var isFirstElement = true;
268
265
 
269
266
  foreach (DictionaryEntry entry in inputDict)
270
267
  {
271
- if (entry.Key == null || string.IsNullOrEmpty(entry.Key.ToString()))
272
- {
273
- continue;
274
- }
268
+ if (entry.Key == null || string.IsNullOrEmpty(entry.Key.ToString())) continue;
275
269
  var key = entry.Key.ToString();
276
270
  var value = entry.Value;
277
271
 
@@ -302,15 +296,11 @@ namespace Amanotes.Core.Internal
302
296
  else
303
297
  jsonSb.Append(",");
304
298
 
305
- if (format)
306
- jsonSb.AppendLine();
299
+ if (format) jsonSb.AppendLine();
307
300
  AppendJsonValue(ref jsonSb, key, item, format, false);
308
301
  }
309
302
 
310
- if (format)
311
- {
312
- jsonSb.AppendLine();
313
- }
303
+ if (format) jsonSb.AppendLine();
314
304
  jsonSb.Append("]");
315
305
  }
316
306
 
@@ -324,7 +314,7 @@ namespace Amanotes.Core.Internal
324
314
 
325
315
  if (value is string)
326
316
  {
327
- string s = value.ToString();
317
+ var s = value.ToString();
328
318
  if (checkJsonInString)
329
319
  {
330
320
  if (s.StartsWith("{") && s.EndsWith("}"))
@@ -336,7 +326,7 @@ namespace Amanotes.Core.Internal
336
326
  {
337
327
  jsonSb.Append(s);
338
328
  return;
339
- }
329
+ }
340
330
  }
341
331
 
342
332
  jsonSb.Append($"\"{value}\"");
@@ -1,34 +1,20 @@
1
- using System.Collections;
2
- using UnityEngine.Networking;
3
- using System;
1
+ using System;
2
+ using System.Collections;
4
3
  using System.Collections.Generic;
4
+ using System.Text;
5
5
  using UnityEngine;
6
+ using UnityEngine.Networking;
6
7
  using static Amanotes.Core.Internal.Logging;
7
8
 
8
9
  namespace Amanotes.Core.Internal
9
10
  {
10
11
  public class JsonWebRequest<T> : UnityWebRequest where T : class
11
12
  {
12
-
13
- [Serializable]
14
- internal class ResponseError
15
- {
16
- public string error;
17
- public string message;
18
- public string statusCode;
19
- }
20
-
21
- [Serializable]
22
- internal class ResponseT
23
- {
24
- public T data;
25
- public ResponseError error = null;
26
- }
27
-
28
- private string requestJson;
29
- private string requestHeader;
30
13
  public T data;
31
14
  public bool isResponseError;
15
+ private readonly string requestHeader;
16
+
17
+ private readonly string requestJson;
32
18
 
33
19
  public JsonWebRequest(string url, string json, string header = "") : base(url, "POST")
34
20
  {
@@ -47,14 +33,14 @@ namespace Amanotes.Core.Internal
47
33
 
48
34
  public new IEnumerator Send()
49
35
  {
50
- byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(requestJson);
36
+ byte[] bodyRaw = Encoding.UTF8.GetBytes(requestJson);
51
37
  uploadHandler = new UploadHandlerRaw(bodyRaw);
52
38
  downloadHandler = new DownloadHandlerBuffer();
53
39
  SetRequestHeader(new Dictionary<string, string>
54
40
  {
55
- {"Authorization", $"bearer {requestHeader}"},
56
- {"Content-Type", "application/json"},
57
- {"api-token", requestHeader}
41
+ { "Authorization", $"bearer {requestHeader}" },
42
+ { "Content-Type", "application/json" },
43
+ { "api-token", requestHeader }
58
44
  });
59
45
  yield return SendWebRequest();
60
46
 
@@ -63,7 +49,7 @@ namespace Amanotes.Core.Internal
63
49
  LogWarning($"{url} returned {responseCode}: {error}");
64
50
  yield break;
65
51
  }
66
-
52
+
67
53
  try
68
54
  {
69
55
  string result = downloadHandler.text;
@@ -87,22 +73,36 @@ namespace Amanotes.Core.Internal
87
73
  {
88
74
  LogWarning($"Error parsing {typeof(T)}: {ex.Message}\n");
89
75
  isResponseError = true;
90
- yield break;
91
76
  }
92
77
  }
78
+
79
+ [Serializable]
80
+ internal class ResponseError
81
+ {
82
+ public string error;
83
+ public string message;
84
+ public string statusCode;
85
+ }
86
+
87
+ [Serializable]
88
+ internal class ResponseT
89
+ {
90
+ public T data;
91
+ public ResponseError error;
92
+ }
93
93
  }
94
94
 
95
95
 
96
96
  internal class WebUtils
97
97
  {
98
- public static Coroutine PostJson(string url, string jsonData, Action<bool, string> onComplete = null, Dictionary<string, string> headers = null)
99
- {
100
- return AmaGDK._instance.StartCoroutine(PostJsonCoroutine(url, jsonData, onComplete, headers));
101
- }
98
+ public static Coroutine PostJson(string url, string jsonData, Action<bool, string> onComplete = null, Dictionary<string, string> headers = null)
99
+ {
100
+ return AmaGDK._instance.StartCoroutine(PostJsonCoroutine(url, jsonData, onComplete, headers));
101
+ }
102
102
 
103
- static IEnumerator PostJsonCoroutine(string url, string jsonData, Action<bool, string> onComplete = null, Dictionary<string, string> headers = null)
103
+ private static IEnumerator PostJsonCoroutine(string url, string jsonData, Action<bool, string> onComplete = null, Dictionary<string, string> headers = null)
104
104
  {
105
- UnityWebRequest webRequest = new UnityWebRequest(url, "POST");
105
+ var webRequest = new UnityWebRequest(url, "POST");
106
106
  if (headers != null)
107
107
  {
108
108
  foreach (KeyValuePair<string, string> kvp in headers)
@@ -111,19 +111,19 @@ namespace Amanotes.Core.Internal
111
111
  }
112
112
  }
113
113
 
114
- byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(jsonData);
114
+ byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonData);
115
115
  webRequest.uploadHandler = new UploadHandlerRaw(bodyRaw);
116
116
  webRequest.downloadHandler = new DownloadHandlerBuffer();
117
117
  yield return webRequest.SendWebRequest();
118
118
 
119
- if (!string.IsNullOrEmpty(webRequest.error))
120
- {
121
- onComplete?.Invoke(false, webRequest.error);
122
- }
123
- else
124
- {
119
+ if (!string.IsNullOrEmpty(webRequest.error))
120
+ {
121
+ onComplete?.Invoke(false, webRequest.error);
122
+ }
123
+ else
124
+ {
125
125
  onComplete?.Invoke(true, webRequest.downloadHandler.text);
126
- }
126
+ }
127
127
  }
128
128
  }
129
- }
129
+ }