Skip to content

Commit a2393a6

Browse files
committed
feature: Add support for metadata operations
1 parent d473204 commit a2393a6

File tree

2 files changed

+126
-2
lines changed

2 files changed

+126
-2
lines changed

Runtime/Client/LootLockerEndPoints.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ public class LootLockerEndPoints
299299
[Header("Metadata")]
300300
public static EndPointClass listMetadata = new EndPointClass("metadata/source/{0}/id/{1}", LootLockerHTTPMethod.GET);
301301
public static EndPointClass getMultisourceMetadata = new EndPointClass("metadata/multisource", LootLockerHTTPMethod.POST);
302+
public static EndPointClass metadataOperations = new EndPointClass("metadata", LootLockerHTTPMethod.POST);
302303

303304
// Notifications
304305
[Header("Notifications")]

Runtime/Game/Requests/MetadataRequests.cs

Lines changed: 125 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ public enum LootLockerMetadataTypes
3838
Json = 3,
3939
Base64 = 4,
4040
};
41+
42+
/// <summary>
43+
/// Possible metadata actions
44+
/// </summary>
45+
public enum LootLockerMetadataActions
46+
{
47+
create = 0,
48+
update = 1,
49+
delete = 2
50+
};
4151
}
4252

4353
namespace LootLocker.Requests
@@ -80,7 +90,11 @@ public class LootLockerMetadataEntry
8090
/// List of tags applied to this metadata entry
8191
///</summary>
8292
public string[] tags { get; set; }
83-
93+
/// <summary>
94+
/// The access level set for this metadata entry. Valid values are game_api.read and game_api.write, though no values are required.
95+
/// Note that different sources can allow or disallow a subset of these values.
96+
/// </summary>
97+
public string[] access { get; set; }
8498
/// <summary>
8599
/// Get the value as a String. Returns true if value could be parsed in which case output contains the value in string format, returns false if parsing failed.
86100
///</summary>
@@ -231,6 +245,46 @@ public class LootLockerMetadataSourceAndEntries
231245
public LootLockerMetadataEntry[] entries { get; set; }
232246
}
233247

248+
public class LootLockerMetadataOperationErrorKeyTypePair
249+
{
250+
/// <summary>
251+
/// TODO: Document
252+
/// </summary>
253+
public string key { get; set; }
254+
/// <summary>
255+
/// TODO: Document
256+
/// </summary>
257+
public LootLockerMetadataTypes type { get; set; }
258+
}
259+
260+
/// <summary>
261+
/// </summary>
262+
public class LootLockerMetadataOperationError
263+
{
264+
/// <summary>
265+
/// TODO: Document
266+
/// </summary>
267+
public LootLockerMetadataActions action { get; set; }
268+
/// <summary>
269+
/// TODO: Document
270+
/// </summary>
271+
public string error { get; set; }
272+
/// <summary>
273+
/// TODO: Document
274+
/// </summary>
275+
public LootLockerMetadataOperationErrorKeyTypePair entry { get; set; }
276+
}
277+
278+
/// <summary>
279+
/// </summary>
280+
public class LootLockerMetadataOperation : LootLockerMetadataEntry
281+
{
282+
/// <summary>
283+
/// TODO: Document
284+
/// </summary>
285+
LootLockerMetadataActions action { get; set; }
286+
}
287+
234288
//==================================================
235289
// Request Definitions
236290
//==================================================
@@ -245,6 +299,27 @@ public class LootLockerGetMultisourceMetadataRequest
245299
public LootLockerMetadataSourceAndKeys[] sources { get; set; }
246300
}
247301

302+
public class LootLockerMetadataOperationRequest
303+
{
304+
/// <summary>
305+
/// TODO: Document
306+
/// </summary>
307+
public bool self { get; set; }
308+
/// <summary>
309+
/// TODO: Document
310+
/// </summary>
311+
public string source { get; set; }
312+
/// <summary>
313+
/// TODO: Document
314+
/// </summary>
315+
public string source_id { get; set; }
316+
/// <summary>
317+
/// TODO: Document
318+
/// </summary>
319+
public LootLockerMetadataOperation[] entries { get; set; }
320+
321+
}
322+
248323
//==================================================
249324
// Response Definitions
250325
//==================================================
@@ -281,6 +356,24 @@ public class LootLockerGetMultisourceMetadataResponse : LootLockerResponse
281356
/// </summary>
282357
public LootLockerMetadataSourceAndEntries[] Metadata { get; set; }
283358
};
359+
360+
/// <summary>
361+
/// </summary>
362+
public class LootLockerMetadataOperationsResponse : LootLockerResponse
363+
{
364+
/// <summary>
365+
/// TODO: Document
366+
/// </summary>
367+
public LootLockerMetadataSources source { get; set; }
368+
/// <summary>
369+
/// TODO: Document
370+
/// </summary>
371+
public string source_id { get; set; }
372+
/// <summary>
373+
/// TODO: Document
374+
/// </summary>
375+
public LootLockerMetadataOperationError[] errors { get; set; }
376+
}
284377
}
285378

286379
//==================================================
@@ -323,6 +416,7 @@ public static void ListMetadata(LootLockerMetadataSources Source, string SourceI
323416
LootLockerResponse.Deserialize<LootLockerListMetadataResponse>(onComplete, serverResponse);
324417
});
325418
}
419+
326420
public static void GetMultisourceMetadata(LootLockerMetadataSourceAndKeys[] SourcesAndKeysToGet, bool ignoreFiles, Action<LootLockerGetMultisourceMetadataResponse> onComplete)
327421
{
328422
if (SourcesAndKeysToGet == null)
@@ -341,7 +435,7 @@ public static void GetMultisourceMetadata(LootLockerMetadataSourceAndKeys[] Sour
341435
endpoint += queryParams;
342436
}
343437

344-
foreach ( var sourcePair in SourcesAndKeysToGet)
438+
foreach (LootLockerMetadataSourceAndKeys sourcePair in SourcesAndKeysToGet)
345439
{
346440
if(sourcePair.source == LootLockerMetadataSources.self)
347441
{
@@ -358,5 +452,34 @@ public static void GetMultisourceMetadata(LootLockerMetadataSourceAndKeys[] Sour
358452
LootLockerResponse.Deserialize<LootLockerGetMultisourceMetadataResponse>(onComplete, serverResponse);
359453
});
360454
}
455+
456+
public static void PerformMetadataOperations(LootLockerMetadataSources Source, string SourceID, List<LootLockerMetadataOperation> operationsToPerform, Action<LootLockerMetadataOperationsResponse> onComplete)
457+
{
458+
if (Source == LootLockerMetadataSources.self)
459+
{
460+
SourceID = "self";
461+
}
462+
if (string.IsNullOrEmpty(SourceID) || operationsToPerform.Count == 0)
463+
{
464+
onComplete?.Invoke(LootLockerResponseFactory.InputUnserializableError<LootLockerMetadataOperationsResponse>());
465+
return;
466+
}
467+
468+
LootLockerMetadataOperationRequest request = new LootLockerMetadataOperationRequest
469+
{
470+
self = Source == LootLockerMetadataSources.self,
471+
source = Source.ToString().ToLower(),
472+
source_id = SourceID,
473+
entries = operationsToPerform.ToArray()
474+
};
475+
476+
string json = LootLockerJson.SerializeObject(request);
477+
478+
LootLockerServerRequest.CallAPI(LootLockerEndPoints.metadataOperations.endPoint, LootLockerEndPoints.metadataOperations.httpMethod, json, onComplete:
479+
(serverResponse) =>
480+
{
481+
LootLockerResponse.Deserialize<LootLockerMetadataOperationsResponse>(onComplete, serverResponse);
482+
});
483+
}
361484
}
362485
}

0 commit comments

Comments
 (0)