From 34a51fb617bf4e5af5ba9352876dd1df4a28bb4e Mon Sep 17 00:00:00 2001 From: Ben Verbeken Date: Fri, 4 Oct 2024 09:30:38 +0200 Subject: [PATCH] Instead of passing in FREE as a status, we now use RELEASE as statusChangeCommand type. (#138) --- SeatsioDotNet/Events/Events.cs | 55 ++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/SeatsioDotNet/Events/Events.cs b/SeatsioDotNet/Events/Events.cs index 9371fb3..1d089b4 100644 --- a/SeatsioDotNet/Events/Events.cs +++ b/SeatsioDotNet/Events/Events.cs @@ -254,8 +254,9 @@ public async Task BookAsync(string eventKey, BestAvailable public async Task ReleaseAsync(string eventKey, IEnumerable objects, string holdToken = null, string orderId = null, bool? keepExtraData = null, bool? ignoreChannels = null, string[] channelKeys = null, CancellationToken cancellationToken = default) { - return await ChangeObjectStatusAsync(eventKey, objects, EventObjectInfo.Free, holdToken, orderId, keepExtraData, - ignoreChannels, channelKeys, cancellationToken: cancellationToken); + var requestBody = ReleaseObjectsRequest(new[] {eventKey}, objects.Select(o => new ObjectProperties(o)), holdToken, orderId, keepExtraData, + ignoreChannels, channelKeys); + return await DoChangeObjectStatusAsync(requestBody, cancellationToken); } public async Task ReleaseAsync(string[] eventKeys, IEnumerable objects, @@ -352,6 +353,11 @@ public async Task ChangeObjectStatusAsync(IEnumerable< { var requestBody = ChangeObjectStatusRequest(events, objects, status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, allowedPreviousStatuses, rejectedPreviousStatuses); + return await DoChangeObjectStatusAsync(requestBody, cancellationToken); + } + + private async Task DoChangeObjectStatusAsync(Dictionary requestBody, CancellationToken cancellationToken) + { var restRequest = new RestRequest("/events/groups/actions/change-object-status", Method.Post) .AddQueryParameter("expand", "objects") .AddJsonBody(requestBody); @@ -379,6 +385,15 @@ private Dictionary ChangeObjectStatusRequest(string evnt, IEnume request.Add("event", evnt); return request; } + + private Dictionary ReleaseObjectsRequest(IEnumerable events, + IEnumerable objects, string holdToken, string orderId, bool? keepExtraData, + bool? ignoreChannels = null, string[] channelKeys = null) + { + var request = ReleaseObjectsRequest(objects, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys); + request.Add("events", events); + return request; + } private Dictionary ChangeObjectStatusRequest(IEnumerable events, IEnumerable objects, string status, string holdToken, string orderId, bool? keepExtraData, @@ -398,6 +413,7 @@ private Dictionary ChangeObjectStatusRequest(IEnumerable() { + {"type", "CHANGE_STATUS_TO"}, {"status", status}, {"objects", objects.Select(o => o.AsDictionary())}, }; @@ -439,6 +455,41 @@ private Dictionary ChangeObjectStatusRequest(IEnumerable ReleaseObjectsRequest(IEnumerable objects, string holdToken, string orderId, bool? keepExtraData, bool? ignoreChannels = null, string[] channelKeys = null) + { + var requestBody = new Dictionary() + { + {"type", "RELEASE"}, + {"objects", objects.Select(o => o.AsDictionary())}, + }; + + if (holdToken != null) + { + requestBody.Add("holdToken", holdToken); + } + + if (orderId != null) + { + requestBody.Add("orderId", orderId); + } + + if (keepExtraData != null) + { + requestBody.Add("keepExtraData", keepExtraData); + } + + if (ignoreChannels != null) + { + requestBody.Add("ignoreChannels", ignoreChannels); + } + + if (channelKeys != null) + { + requestBody.Add("channelKeys", channelKeys); + } + return requestBody; + } public async Task ChangeObjectStatusAsync(string eventKey, BestAvailable bestAvailable, string status, string holdToken = null, string orderId = null, bool? keepExtraData = null, bool? ignoreChannels = null,