Skip to content

Commit

Permalink
Instead of passing in FREE as a status, we now use RELEASE as statusC…
Browse files Browse the repository at this point in the history
…hangeCommand type. (#138)
  • Loading branch information
bverbeken authored Oct 4, 2024
1 parent 9ee3fd0 commit 34a51fb
Showing 1 changed file with 53 additions and 2 deletions.
55 changes: 53 additions & 2 deletions SeatsioDotNet/Events/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,9 @@ public async Task<BestAvailableResult> BookAsync(string eventKey, BestAvailable
public async Task<ChangeObjectStatusResult> ReleaseAsync(string eventKey, IEnumerable<string> 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<ChangeObjectStatusResult> ReleaseAsync(string[] eventKeys, IEnumerable<string> objects,
Expand Down Expand Up @@ -352,6 +353,11 @@ public async Task<ChangeObjectStatusResult> ChangeObjectStatusAsync(IEnumerable<
{
var requestBody = ChangeObjectStatusRequest(events, objects, status, holdToken, orderId, keepExtraData,
ignoreChannels, channelKeys, allowedPreviousStatuses, rejectedPreviousStatuses);
return await DoChangeObjectStatusAsync(requestBody, cancellationToken);
}

private async Task<ChangeObjectStatusResult> DoChangeObjectStatusAsync(Dictionary<string, object> requestBody, CancellationToken cancellationToken)
{
var restRequest = new RestRequest("/events/groups/actions/change-object-status", Method.Post)
.AddQueryParameter("expand", "objects")
.AddJsonBody(requestBody);
Expand Down Expand Up @@ -379,6 +385,15 @@ private Dictionary<string, object> ChangeObjectStatusRequest(string evnt, IEnume
request.Add("event", evnt);
return request;
}

private Dictionary<string, object> ReleaseObjectsRequest(IEnumerable<string> events,
IEnumerable<ObjectProperties> 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<string, object> ChangeObjectStatusRequest(IEnumerable<string> events,
IEnumerable<ObjectProperties> objects, string status, string holdToken, string orderId, bool? keepExtraData,
Expand All @@ -398,6 +413,7 @@ private Dictionary<string, object> ChangeObjectStatusRequest(IEnumerable<ObjectP
{
var requestBody = new Dictionary<string, object>()
{
{"type", "CHANGE_STATUS_TO"},
{"status", status},
{"objects", objects.Select(o => o.AsDictionary())},
};
Expand Down Expand Up @@ -439,6 +455,41 @@ private Dictionary<string, object> ChangeObjectStatusRequest(IEnumerable<ObjectP

return requestBody;
}

private Dictionary<string, object> ReleaseObjectsRequest(IEnumerable<ObjectProperties> objects, string holdToken, string orderId, bool? keepExtraData, bool? ignoreChannels = null, string[] channelKeys = null)
{
var requestBody = new Dictionary<string, object>()
{
{"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<BestAvailableResult> ChangeObjectStatusAsync(string eventKey, BestAvailable bestAvailable, string status,
string holdToken = null, string orderId = null, bool? keepExtraData = null, bool? ignoreChannels = null,
Expand Down

0 comments on commit 34a51fb

Please sign in to comment.