Skip to content

Commit 84a3f38

Browse files
committed
Add ping endpoint
1 parent cc278b3 commit 84a3f38

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

Runtime/Client/LootLockerEndPoints.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,9 @@ public class LootLockerEndPoints
158158
[Header("Drop Tables")]
159159
public static EndPointClass ComputeAndLockDropTable = new EndPointClass("v1/player/droptables/{0}/compute?asset_details={1}", LootLockerHTTPMethod.POST);
160160
public static EndPointClass PickDropsFromDropTable = new EndPointClass("v1/player/droptables/{0}/pick", LootLockerHTTPMethod.POST);
161+
162+
// Misc
163+
[Header("Misc")]
164+
public static EndPointClass ping = new EndPointClass("ping", LootLockerHTTPMethod.GET);
161165
}
162166
}

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,22 @@ public static void PickDropsFromDropTable(int[] picks, int tableInstanceId, Acti
17061706
LootLockerAPIManager.PickDropsFromDropTable(data, tableInstanceId, onComplete);
17071707
}
17081708
#endregion
1709+
1710+
#region Misc
1711+
1712+
public static void Ping(Action<LootLockerPingResponse> onComplete)
1713+
{
1714+
if (!CheckInitialized())
1715+
{
1716+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerPingResponse>());
1717+
return;
1718+
}
1719+
1720+
LootLockerAPIManager.Ping(onComplete);
1721+
}
1722+
1723+
1724+
#endregion
17091725
}
17101726

17111727
public class ResponseError

Runtime/Game/Requests/MiscRequests.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
using LootLocker.Requests;
4+
using Newtonsoft.Json.Serialization;
5+
6+
namespace LootLocker.Requests
7+
{
8+
public class LootLockerPingResponse : LootLockerResponse
9+
{
10+
public string date { get; set; }
11+
}
12+
13+
}
14+
15+
namespace LootLocker
16+
{
17+
public partial class LootLockerAPIManager
18+
{
19+
public static void Ping(Action<LootLockerPingResponse> onComplete)
20+
{
21+
EndPointClass endPoint = LootLockerEndPoints.ping;
22+
23+
LootLockerServerRequest.CallAPI(endPoint.endPoint, endPoint.httpMethod, null, ((serverResponse) =>
24+
{
25+
LootLockerPingResponse response = new LootLockerPingResponse();
26+
if (string.IsNullOrEmpty(serverResponse.Error) && serverResponse.text != null)
27+
{
28+
DefaultContractResolver contractResolver = new DefaultContractResolver
29+
{
30+
NamingStrategy = new SnakeCaseNamingStrategy()
31+
};
32+
33+
response = JsonConvert.DeserializeObject<LootLockerPingResponse>(serverResponse.text, new JsonSerializerSettings
34+
{
35+
ContractResolver = contractResolver,
36+
Formatting = Formatting.Indented
37+
});
38+
39+
if (response == null)
40+
{
41+
response = LootLockerResponseFactory.Error<LootLockerPingResponse>("error deserializing server response");
42+
onComplete?.Invoke(response);
43+
return;
44+
}
45+
}
46+
47+
response.text = serverResponse.text;
48+
response.success = serverResponse.success;
49+
response.Error = serverResponse.Error; response.statusCode = serverResponse.statusCode;
50+
onComplete?.Invoke(response);
51+
}));
52+
}
53+
}
54+
}

Runtime/Game/Requests/MiscRequests.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)