Skip to content

Commit ad02cc5

Browse files
Erik Bylundkirre-bylund
authored andcommitted
feat: Add support for listing metadata
1 parent 0626f61 commit ad02cc5

File tree

5 files changed

+430
-20
lines changed

5 files changed

+430
-20
lines changed

Runtime/Client/LootLockerEndPoints.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,5 +292,9 @@ public class LootLockerEndPoints
292292
public static EndPointClass listEntitlementHistory = new EndPointClass("entitlements", LootLockerHTTPMethod.GET);
293293
public static EndPointClass getSingleEntitlement = new EndPointClass("entitlements/{0}", LootLockerHTTPMethod.GET);
294294

295+
// Metadata
296+
[Header("Metadata")]
297+
public static EndPointClass listMetadata = new EndPointClass("metadata/source/{0}/id/{1}", LootLockerHTTPMethod.GET);
298+
295299
}
296300
}

Runtime/Client/LootLockerServerRequest.cs

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using LootLocker.LootLockerEnums;
55
#if LOOTLOCKER_USE_NEWTONSOFTJSON
66
using Newtonsoft.Json;
7-
using Newtonsoft.Json.Serialization;
7+
using Newtonsoft.Json.Serialization;
88
#else
99
using LLlibs.ZeroDepJson;
1010
#endif
@@ -58,16 +58,16 @@ public static bool TryDeserializeObject<T>(string json, out T output)
5858
}
5959

6060
public static bool TryDeserializeObject<T>(string json, JsonSerializerSettings options, out T output)
61-
{
62-
try
63-
{
64-
output = JsonConvert.DeserializeObject<T>(json, options ?? LootLockerJsonSettings.Default);
65-
return true;
66-
}
67-
catch (Exception)
68-
{
69-
output = default(T);
70-
return false;
61+
{
62+
try
63+
{
64+
output = JsonConvert.DeserializeObject<T>(json, options ?? LootLockerJsonSettings.Default);
65+
return true;
66+
}
67+
catch (Exception)
68+
{
69+
output = default(T);
70+
return false;
7171
}
7272
}
7373
#else //LOOTLOCKER_USE_NEWTONSOFTJSON
@@ -97,15 +97,15 @@ public static bool TryDeserializeObject<T>(string json, out T output)
9797
}
9898

9999
public static bool TryDeserializeObject<T>(string json, JsonOptions options, out T output)
100-
{
101-
try
102-
{
103-
output = Json.Deserialize<T>(json, options ?? LootLockerJsonSettings.Default);
104-
return true;
105-
} catch (Exception)
106-
{
107-
output = default(T);
108-
return false;
100+
{
101+
try
102+
{
103+
output = Json.Deserialize<T>(json, options ?? LootLockerJsonSettings.Default);
104+
return true;
105+
} catch (Exception)
106+
{
107+
output = default(T);
108+
return false;
109109
}
110110
}
111111
#endif //LOOTLOCKER_USE_NEWTONSOFTJSON
@@ -307,6 +307,54 @@ public class LootLockerPaginationResponse<TKey>
307307
public TKey previous_cursor { get; set; }
308308
}
309309

310+
public class LootLockerExtendedPaginationError
311+
{
312+
/// <summary>
313+
/// Which field in the pagination that this error relates to
314+
/// </summary>
315+
public string field { get; set; }
316+
/// <summary>
317+
/// The error message in question
318+
/// </summary>
319+
public string message { get; set; }
320+
}
321+
322+
public class LootLockerExtendedPagination
323+
{
324+
/// <summary>
325+
/// How many entries in total exists in the paginated list
326+
/// </summary>
327+
public int total { get; set; }
328+
/// <summary>
329+
/// How many entries (counting from the beginning of the paginated list) from the first entry that the current page starts at
330+
/// </summary>
331+
public int offset { get; set; }
332+
/// <summary>
333+
/// Number of entries on each page
334+
/// </summary>
335+
public int per_page { get; set; }
336+
/// <summary>
337+
/// The page index to use for fetching the last page of entries
338+
/// </summary>
339+
public int last_page { get; set; }
340+
/// <summary>
341+
/// The page index used for fetching this page of entries
342+
/// </summary>
343+
public int current_page { get; set; }
344+
/// <summary>
345+
/// The page index to use for fetching the page of entries immediately succeeding this page of entries
346+
/// </summary>
347+
public int? next_page { get; set; }
348+
/// <summary>
349+
/// The page index to use for fetching the page of entries immediately preceding this page of entries
350+
/// </summary>
351+
public int? prev_page { get; set; }
352+
/// <summary>
353+
/// List of pagination errors (if any). These are errors specifically related to the pagination of the entry set.
354+
/// </summary>
355+
public LootLockerExtendedPaginationError[] errors { get; set; }
356+
}
357+
310358
/// <summary>
311359
/// Convenience factory class for creating some responses that we use often.
312360
/// </summary>

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5769,6 +5769,94 @@ public static void GetEntitlement(string entitlementId, Action<LootLockerSingleE
57695769

57705770
#endregion
57715771

5772+
#region Metadata
5773+
5774+
/// <summary>
5775+
/// List Metadata for the specified source with default pagination
5776+
/// </summary>
5777+
/// <param name="Source> The source type for which to request metadata</param>
5778+
/// <param name="SourceID> The specific source id for which to request metadata</param>
5779+
/// <param name="OnComplete> delegate for handling the server response</param>
5780+
/// <param name="IgnoreFiles> Base64 values will be set to content_type "application/x-redacted" and the content will be an empty String. Use this to avoid accidentally fetching large data files.</param>
5781+
public static void ListMetadata(LootLockerMetadataSources Source, string SourceID, Action<LootLockerListMetadataResponse> onComplete, bool IgnoreFiles = false)
5782+
{
5783+
ListMetadata(Source, SourceID, 0, 0, onComplete, IgnoreFiles);
5784+
}
5785+
5786+
/// <summary>
5787+
/// List the requested page of Metadata for the specified source with the specified pagination
5788+
/// </summary>
5789+
/// <param name="Source> The source type for which to request metadata</param>
5790+
/// <param name="SourceID> The specific source id for which to request metadata</param>
5791+
/// <param name="Page> Used together with PerPage to apply pagination to this request. Page designates which "page" of items to fetch</param>
5792+
/// <param name="PerPage> Used together with Page to apply pagination to this request.PerPage designates how many items are considered a "page"</param>
5793+
/// <param name="OnComplete> delegate for handling the server response</param>
5794+
/// <param name="IgnoreFiles> Base64 values will be set to content_type "application/x-redacted" and the content will be an empty String. Use this to avoid accidentally fetching large data files.</param>
5795+
public static void ListMetadata(LootLockerMetadataSources Source, string SourceID, int Page, int PerPage, Action<LootLockerListMetadataResponse> onComplete, bool IgnoreFiles = false)
5796+
{
5797+
ListMetadataWithTags(Source, SourceID, null, Page, PerPage, onComplete, IgnoreFiles);
5798+
}
5799+
5800+
/// <summary>
5801+
/// List Metadata for the specified source that has all of the provided tags, use default pagination
5802+
/// </summary>
5803+
/// <param name="Source> The source type for which to request metadata</param>
5804+
/// <param name="SourceID> The specific source id for which to request metadata</param>
5805+
/// <param name="Tags"> The tags that the requested metadata should have, only metadata matching *all of* the given tags will be returned </param>
5806+
/// <param name="OnComplete> delegate for handling the server response</param>
5807+
/// <param name="IgnoreFiles> Base64 values will be set to content_type "application/x-redacted" and the content will be an empty String. Use this to avoid accidentally fetching large data files.</param>
5808+
public static void ListMetadataWithTags(LootLockerMetadataSources Source, string SourceID, string[] Tags, Action<LootLockerListMetadataResponse> onComplete, bool IgnoreFiles = false)
5809+
{
5810+
ListMetadataWithTags(Source, SourceID, Tags, 0, 0, onComplete, IgnoreFiles);
5811+
}
5812+
5813+
/// <summary>
5814+
/// List the requested page of Metadata for the specified source that has all of the provided tags and paginate according to the supplied pagination settings
5815+
/// </summary>
5816+
/// <param name="Source> The source type for which to request metadata</param>
5817+
/// <param name="SourceID> The specific source id for which to request metadata</param>
5818+
/// <param name="Tags"> The tags that the requested metadata should have, only metadata matching *all of* the given tags will be returned </param>
5819+
/// <param name="Page> Used together with PerPage to apply pagination to this request.Page designates which "page" of items to fetch</param>
5820+
/// <param name="PerPage> Used together with Page to apply pagination to this request.PerPage designates how many items are considered a "page"</param>
5821+
/// <param name="OnComplete> delegate for handling the server response</param>
5822+
/// <param name="IgnoreFiles> Base64 values will be set to content_type "application/x-redacted" and the content will be an empty String. Use this to avoid accidentally fetching large data files.</param>
5823+
public static void ListMetadataWithTags(LootLockerMetadataSources Source, string SourceID, string[] Tags, int Page, int PerPage, Action<LootLockerListMetadataResponse> onComplete, bool IgnoreFiles = false)
5824+
{
5825+
if (!CheckInitialized())
5826+
{
5827+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerListMetadataResponse>());
5828+
return;
5829+
}
5830+
5831+
LootLockerAPIManager.ListMetadata(Source, SourceID, Page, PerPage, null, Tags, IgnoreFiles, onComplete);
5832+
}
5833+
5834+
/// <summary>
5835+
/// Get Metadata for the specified source with the given key
5836+
/// </summary>
5837+
/// <param name="Source> The source type for which to request metadata</param>
5838+
/// <param name="SourceID> The specific source id for which to request metadata</param>
5839+
/// <param name="Key> The key of the metadata to fetch, use this to fetch a specific key for the specified source.This takes precedence over pagination and tags</param>
5840+
/// <param name="OnComplete> delegate for handling the server response</param>
5841+
/// <param name="IgnoreFiles> Optional: Base64 values will be set to content_type "application/x-redacted" and the content will be an empty String. Use this to avoid accidentally fetching large data files.</param>
5842+
public static void GetMetadata(LootLockerMetadataSources Source, string SourceID, string Key, Action<LootLockerGetMetadataResponse> onComplete, bool IgnoreFiles=false)
5843+
{
5844+
LootLockerAPIManager.ListMetadata(Source, SourceID, 0, 0, Key, null, IgnoreFiles, (ListResponse) =>
5845+
{
5846+
onComplete(new()
5847+
{
5848+
success = ListResponse.success,
5849+
statusCode = ListResponse.statusCode,
5850+
text = ListResponse.text,
5851+
EventId = ListResponse.EventId,
5852+
errorData = ListResponse.errorData,
5853+
entry = ListResponse.entries != null ? ListResponse.entries.Length > 0 ? ListResponse.entries[0] : null : null
5854+
});
5855+
});
5856+
}
5857+
5858+
#endregion
5859+
57725860
#region Misc
57735861

57745862
/// <summary>

0 commit comments

Comments
 (0)