Skip to content

Commit d17526e

Browse files
authored
Merge pull request #21 from LootLocker/feature/reports
Add initial code for reports
2 parents 6efb197 + 1476cc7 commit d17526e

File tree

4 files changed

+296
-0
lines changed

4 files changed

+296
-0
lines changed

Runtime/Client/LootLockerEndPoints.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,5 +164,12 @@ public class LootLockerEndPoints
164164
// Misc
165165
[Header("Misc")]
166166
public static EndPointClass ping = new EndPointClass("ping", LootLockerHTTPMethod.GET);
167+
168+
// Reports
169+
[Header("Reports")]
170+
public static EndPointClass reportsGetTypes = new EndPointClass("reports/types", LootLockerHTTPMethod.GET);
171+
public static EndPointClass reportsGetRemovedUGCForPlayer = new EndPointClass("player/ugc/removed", LootLockerHTTPMethod.GET);
172+
public static EndPointClass reportsCreatePlayer = new EndPointClass("reports/player", LootLockerHTTPMethod.POST);
173+
public static EndPointClass reportsCreateAsset = new EndPointClass("reports/asset", LootLockerHTTPMethod.POST);
167174
}
168175
}

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,6 +1739,70 @@ public static void PickDropsFromDropTable(int[] picks, int tableInstanceId, Acti
17391739
}
17401740
#endregion
17411741

1742+
#region Reports
1743+
1744+
/// <summary>
1745+
/// Retrieves the different types of report possible.
1746+
///
1747+
/// These can be changed in the web interface or through the Admin API.
1748+
/// </summary>
1749+
public static void GetReportTypes(Action<LootLockerReportsGetTypesResponse> onComplete)
1750+
{
1751+
if (!CheckInitialized())
1752+
{
1753+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerReportsGetTypesResponse>());
1754+
return;
1755+
}
1756+
1757+
LootLockerAPIManager.GetReportTypes(onComplete);
1758+
}
1759+
1760+
/// <summary>
1761+
/// Create a report of a player
1762+
/// </summary>
1763+
public static void CreatePlayerReport(ReportsCreatePlayerRequest input, Action<LootLockerReportsCreatePlayerResponse> onComplete)
1764+
{
1765+
if (!CheckInitialized())
1766+
{
1767+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerReportsCreatePlayerResponse>());
1768+
return;
1769+
}
1770+
1771+
LootLockerAPIManager.CreatePlayerReport(input, onComplete);
1772+
}
1773+
1774+
/// <summary>
1775+
/// Create a report of an asset
1776+
/// </summary>
1777+
public static void CreateAssetReport(ReportsCreateAssetRequest input, Action<LootLockerReportsCreateAssetResponse> onComplete)
1778+
{
1779+
if (!CheckInitialized())
1780+
{
1781+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerReportsCreateAssetResponse>());
1782+
return;
1783+
}
1784+
1785+
LootLockerAPIManager.CreateAssetReport(input, onComplete);
1786+
}
1787+
1788+
/// <summary>
1789+
/// Get removed UGC for the current player.
1790+
///
1791+
/// If any of their UGC has been removed as a result of reports they will be returned in this method
1792+
/// </summary>
1793+
public static void GetRemovedUGCForPlayer(GetRemovedUGCForPlayerInput input, Action<LootLockerReportsGetRemovedAssetsResponse> onComplete)
1794+
{
1795+
if (!CheckInitialized())
1796+
{
1797+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerReportsGetRemovedAssetsResponse>());
1798+
return;
1799+
}
1800+
1801+
LootLockerAPIManager.GetRemovedUGCForPlayer(input, onComplete);
1802+
}
1803+
1804+
#endregion
1805+
17421806
#region Misc
17431807

17441808
public static void Ping(Action<LootLockerPingResponse> onComplete)
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Collections;
4+
using System.Collections.Generic;
5+
using UnityEngine;
6+
using LootLocker;
7+
using LootLocker.Requests;
8+
using LootLocker.LootLockerEnums;
9+
10+
11+
namespace LootLocker.Requests
12+
{
13+
public class ReportType
14+
{
15+
public int ID { get; set; }
16+
public string Text { get; set; }
17+
}
18+
19+
public class LootLockerReportsGetTypesResponse : LootLockerResponse
20+
{
21+
public ReportType[] Types { get; set; }
22+
}
23+
24+
public class LootLockerReportsCreatePlayerResponse : LootLockerResponse
25+
{
26+
public int ID { get; set; }
27+
public int PlayerID { get; set; }
28+
public string Text { get; set; }
29+
public int[] ReportTypes { get; set; }
30+
public string ReportDate { get; set; }
31+
}
32+
33+
public class LootLockerReportsCreateAssetResponse : LootLockerResponse
34+
{
35+
public int ID { get; set; }
36+
public int AssetID { get; set; }
37+
public string Text { get; set; }
38+
public int[] ReportTypes { get; set; }
39+
public string ReportDate { get; set; }
40+
}
41+
42+
public class RemovedAsset
43+
{
44+
public int ID { get; set; }
45+
public int AssetID { get; set; }
46+
public string Name { get; set; }
47+
public int[] ReportTypes { get; set; }
48+
public string RemovedAt { get; set; }
49+
}
50+
public class LootLockerReportsGetRemovedAssetsResponse : LootLockerResponse
51+
{
52+
public RemovedAsset[] Assets { get; set; }
53+
}
54+
55+
public class GetRemovedUGCForPlayerInput
56+
{
57+
/// <summary>
58+
/// Only get UGC removed after this date.
59+
///
60+
/// Should follow RFC3339 format
61+
/// </summary>
62+
public string Since { get; set; }
63+
64+
/// <summary>
65+
/// Used for pagination.
66+
///
67+
/// Set this to the ID of the last retrieved report to get the next ones after.
68+
/// </summary>
69+
public string After { get; set; }
70+
71+
/// <summary>
72+
/// Number of report you want to retrieve
73+
/// </summary>
74+
public int Count { get; set; }
75+
}
76+
77+
public class ReportsCreatePlayerRequest
78+
{
79+
public int[] report_types { get; set; }
80+
public string text { get; set; }
81+
public int player_id { get; set; }
82+
}
83+
84+
public class ReportsCreateAssetRequest
85+
{
86+
public int[] report_types { get; set; }
87+
public string text { get; set; }
88+
public int asset_id { get; set; }
89+
}
90+
}
91+
92+
namespace LootLocker
93+
{
94+
public partial class LootLockerAPIManager
95+
{
96+
public static void GetReportTypes(Action<LootLockerReportsGetTypesResponse> onComplete)
97+
{
98+
EndPointClass endPoint = LootLockerEndPoints.reportsGetTypes;
99+
LootLockerServerRequest.CallAPI(endPoint.endPoint, endPoint.httpMethod, null, ((serverResponse) =>
100+
{
101+
LootLockerReportsGetTypesResponse response = new LootLockerReportsGetTypesResponse();
102+
if (string.IsNullOrEmpty(serverResponse.Error))
103+
{
104+
response = JsonConvert.DeserializeObject<LootLockerReportsGetTypesResponse>(serverResponse.text);
105+
}
106+
107+
response.text = serverResponse.text;
108+
response.success = serverResponse.success;
109+
response.Error = serverResponse.Error; response.statusCode = serverResponse.statusCode;
110+
onComplete?.Invoke(response);
111+
}), true, LootLockerCallerRole.User);
112+
}
113+
114+
public static void GetRemovedUGCForPlayer(GetRemovedUGCForPlayerInput input, Action<LootLockerReportsGetRemovedAssetsResponse> onComplete)
115+
{
116+
EndPointClass endPoint = LootLockerEndPoints.reportsGetRemovedUGCForPlayer;
117+
string tempEndpoint = endPoint.endPoint;
118+
119+
if (!string.IsNullOrEmpty(input.After))
120+
{
121+
tempEndpoint = tempEndpoint + "?after={0}";
122+
tempEndpoint = string.Format(tempEndpoint, input.After);
123+
}
124+
125+
if (input.Count > 0)
126+
{
127+
if (tempEndpoint.IndexOf("?") > -1)
128+
{
129+
tempEndpoint = tempEndpoint + "&";
130+
} else
131+
{
132+
tempEndpoint = tempEndpoint + "?";
133+
}
134+
135+
tempEndpoint = tempEndpoint + "count={0}";
136+
tempEndpoint = string.Format(tempEndpoint, input.Count);
137+
}
138+
139+
if (!string.IsNullOrEmpty(input.Since))
140+
{
141+
if (tempEndpoint.IndexOf("?") > -1)
142+
{
143+
tempEndpoint = tempEndpoint + "&";
144+
}
145+
else
146+
{
147+
tempEndpoint = tempEndpoint + "?";
148+
}
149+
150+
tempEndpoint = tempEndpoint + "since={0}";
151+
tempEndpoint = string.Format(tempEndpoint, input.Since);
152+
}
153+
154+
LootLockerServerRequest.CallAPI(tempEndpoint, endPoint.httpMethod, null, ((serverResponse) =>
155+
{
156+
LootLockerReportsGetRemovedAssetsResponse response = new LootLockerReportsGetRemovedAssetsResponse();
157+
if (string.IsNullOrEmpty(serverResponse.Error))
158+
{
159+
response = JsonConvert.DeserializeObject<LootLockerReportsGetRemovedAssetsResponse>(serverResponse.text);
160+
}
161+
162+
response.text = serverResponse.text;
163+
response.success = serverResponse.success;
164+
response.Error = serverResponse.Error; response.statusCode = serverResponse.statusCode;
165+
onComplete?.Invoke(response);
166+
}), true, LootLockerCallerRole.User);
167+
}
168+
169+
public static void CreatePlayerReport(ReportsCreatePlayerRequest data, Action<LootLockerReportsCreatePlayerResponse> onComplete)
170+
{
171+
EndPointClass requestEndPoint = LootLockerEndPoints.reportsCreatePlayer;
172+
string json = "";
173+
if (data == null) return;
174+
else json = JsonConvert.SerializeObject(data);
175+
176+
LootLockerServerRequest.CallAPI(requestEndPoint.endPoint, requestEndPoint.httpMethod, json, ((serverResponse) =>
177+
{
178+
LootLockerReportsCreatePlayerResponse response = new LootLockerReportsCreatePlayerResponse();
179+
if (string.IsNullOrEmpty(serverResponse.Error)) {
180+
response = JsonConvert.DeserializeObject<LootLockerReportsCreatePlayerResponse>(serverResponse.text);
181+
}
182+
183+
response.text = serverResponse.text;
184+
response.success = serverResponse.success;
185+
response.Error = serverResponse.Error; response.statusCode = serverResponse.statusCode;
186+
187+
onComplete?.Invoke(response);
188+
}), true, LootLockerCallerRole.User);
189+
}
190+
191+
public static void CreateAssetReport(ReportsCreateAssetRequest data, Action<LootLockerReportsCreateAssetResponse> onComplete)
192+
{
193+
EndPointClass requestEndPoint = LootLockerEndPoints.reportsCreateAsset;
194+
string json = "";
195+
if (data == null) return;
196+
else json = JsonConvert.SerializeObject(data);
197+
198+
LootLockerServerRequest.CallAPI(requestEndPoint.endPoint, requestEndPoint.httpMethod, json, ((serverResponse) =>
199+
{
200+
LootLockerReportsCreateAssetResponse response = new LootLockerReportsCreateAssetResponse();
201+
if (string.IsNullOrEmpty(serverResponse.Error))
202+
{
203+
response = JsonConvert.DeserializeObject<LootLockerReportsCreateAssetResponse>(serverResponse.text);
204+
}
205+
206+
response.text = serverResponse.text;
207+
response.success = serverResponse.success;
208+
response.Error = serverResponse.Error; response.statusCode = serverResponse.statusCode;
209+
210+
onComplete?.Invoke(response);
211+
}), true, LootLockerCallerRole.User);
212+
}
213+
}
214+
}

Runtime/Game/Requests/ReportRequets.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)