Skip to content

Commit e1d12d7

Browse files
Erik Bylundkirre-bylund
authored andcommitted
Add an SDK-Version header to each request
1 parent 9cf41be commit e1d12d7

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

Runtime/Client/LootLockerBaseServerAPI.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,11 @@ UnityWebRequest CreateWebRequest(string url, LootLockerServerRequest request)
350350
}
351351
}
352352

353+
if (!string.IsNullOrEmpty(LootLockerConfig.current?.sdk_version))
354+
{
355+
webRequest.SetRequestHeader("SDK-Version", LootLockerConfig.current.sdk_version);
356+
}
357+
353358
if (request.extraHeaders != null)
354359
{
355360
foreach (KeyValuePair<string, string> pair in request.extraHeaders)

Runtime/Game/Resources/LootLockerConfig.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using System;
22
using System.IO;
3+
using UnityEditor.PackageManager.Requests;
34
#if UNITY_EDITOR
45
using UnityEditor;
6+
using UnityEditor.PackageManager.UI;
7+
using UnityEditor.PackageManager;
58
#endif
69
using UnityEngine;
710

@@ -78,8 +81,32 @@ static void CreateConfigFile()
7881
EditorPrefs.SetBool(configFileEditorPref, true);
7982
}
8083
}
84+
85+
protected static ListRequest ListInstalledPackagesRequest;
86+
87+
[InitializeOnLoadMethod]
88+
static void StoreSDKVersion()
89+
{
90+
ListInstalledPackagesRequest = Client.List();
91+
EditorApplication.update += ListRequestProgress;
92+
}
93+
94+
static void ListRequestProgress()
95+
{
96+
if (ListInstalledPackagesRequest.IsCompleted)
97+
{
98+
EditorApplication.update -= ListRequestProgress;
99+
foreach (var package in ListInstalledPackagesRequest.Result)
100+
{
101+
if (package.name.Equals("com.lootlocker.lootlockersdk"))
102+
{
103+
LootLockerConfig.current.sdk_version = package.version;
104+
}
105+
}
106+
}
107+
}
81108
#endif
82-
public static bool CreateNewSettings(string apiKey, string gameVersion, string domainKey, DebugLevel debugLevel = DebugLevel.All, bool allowTokenRefresh = false)
109+
public static bool CreateNewSettings(string apiKey, string gameVersion, string domainKey, LootLockerConfig.DebugLevel debugLevel = DebugLevel.All, bool allowTokenRefresh = false)
83110
{
84111
_current = Get();
85112

@@ -135,6 +162,7 @@ public static LootLockerConfig current
135162
[HideInInspector]
136163
public int gameID;
137164
public string game_version = "1.0.0.0";
165+
[HideInInspector] public string sdk_version = "";
138166
[HideInInspector]
139167
public string deviceID = "defaultPlayerId";
140168

0 commit comments

Comments
 (0)