Skip to content

Commit

Permalink
Batch status change call supports channels
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux committed Jul 24, 2020
1 parent 9bbe816 commit ea52d39
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
49 changes: 48 additions & 1 deletion SeatsioDotNet.Test/Events/ChangeObjectStatusInBatchTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SeatsioDotNet.Events;
using System.Collections.Generic;
using SeatsioDotNet.Events;
using Xunit;

namespace SeatsioDotNet.Test.Events
Expand All @@ -25,5 +26,51 @@ public void Test()
Assert.Equal("lolzor", result[1].Objects["A-2"].Status);
Assert.Equal("lolzor", Client.Events.RetrieveObjectStatus(evnt2.Key, "A-2").Status);
}

[Fact]
public void ChannelKeys()
{
var chartKey = CreateTestChart();
var evnt = Client.Events.Create(chartKey);
var channels = new Dictionary<string, Channel>()
{
{"channelKey1", new Channel("channel 1", "#FFFF00", 1)}
};
Client.Events.UpdateChannels(evnt.Key, channels);
Client.Events.AssignObjectsToChannel(evnt.Key, new
{
channelKey1 = new[] {"A-1"}
});

var result = Client.Events.ChangeObjectStatus(new[]
{
new StatusChangeRequest(evnt.Key, new[] {"A-1"}, "lolzor", channelKeys: new[] {"channelKey1"}),
});

Assert.Equal("lolzor", result[0].Objects["A-1"].Status);
}

[Fact]
public void IgnoreChannels()
{
var chartKey = CreateTestChart();
var evnt = Client.Events.Create(chartKey);
var channels = new Dictionary<string, Channel>()
{
{"channelKey1", new Channel("channel 1", "#FFFF00", 1)}
};
Client.Events.UpdateChannels(evnt.Key, channels);
Client.Events.AssignObjectsToChannel(evnt.Key, new
{
channelKey1 = new[] {"A-1"}
});

var result = Client.Events.ChangeObjectStatus(new[]
{
new StatusChangeRequest(evnt.Key, new[] {"A-1"}, "lolzor", ignoreChannels: true),
});

Assert.Equal("lolzor", result[0].Objects["A-1"].Status);
}
}
}
2 changes: 1 addition & 1 deletion SeatsioDotNet/Events/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public ChangeObjectStatusResult ChangeObjectStatus(IEnumerable<string> events, I

public List<ChangeObjectStatusResult> ChangeObjectStatus(StatusChangeRequest[] requests)
{
var serializedRequests = requests.Select(r => ChangeObjectStatusRequest(r.EventKey, r.Objects, r.Status, r.HoldToken, r.OrderId, r.KeepExtraData));
var serializedRequests = requests.Select(r => ChangeObjectStatusRequest(r.EventKey, r.Objects, r.Status, r.HoldToken, r.OrderId, r.KeepExtraData, r.IgnoreChannels, r.ChannelKeys));
var restRequest = new RestRequest("/events/actions/change-object-status", Method.POST)
.AddQueryParameter("expand", "objects")
.AddJsonBody(new Dictionary<string, object> {{ "statusChanges", serializedRequests}});
Expand Down
10 changes: 8 additions & 2 deletions SeatsioDotNet/Events/StatusChangeRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,31 @@ public class StatusChangeRequest
public string HoldToken { get; }
public string OrderId { get; }
public bool? KeepExtraData { get; }
public bool? IgnoreChannels { get; }
public string[] ChannelKeys { get; }

public StatusChangeRequest(string eventKey, IEnumerable<ObjectProperties> objects, string status, string holdToken = null, string orderId = null, bool? keepExtraData = null)
public StatusChangeRequest(string eventKey, IEnumerable<ObjectProperties> objects, string status, string holdToken = null, string orderId = null, bool? keepExtraData = null, bool? ignoreChannels = null, string[] channelKeys = null)
{
EventKey = eventKey;
Objects = objects;
Status = status;
HoldToken = holdToken;
OrderId = orderId;
KeepExtraData = keepExtraData;
IgnoreChannels = ignoreChannels;
ChannelKeys = channelKeys;
}

public StatusChangeRequest(string eventKey, IEnumerable<string> objects, string status, string holdToken = null, string orderId = null, bool? keepExtraData = null)
public StatusChangeRequest(string eventKey, IEnumerable<string> objects, string status, string holdToken = null, string orderId = null, bool? keepExtraData = null, bool? ignoreChannels = null, string[] channelKeys = null)
{
EventKey = eventKey;
Objects = objects.Select(o => new ObjectProperties(o));
Status = status;
HoldToken = holdToken;
OrderId = orderId;
KeepExtraData = keepExtraData;
IgnoreChannels = ignoreChannels;
ChannelKeys = channelKeys;
}
}
}
2 changes: 1 addition & 1 deletion SeatsioDotNet/SeatsioDotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Library</OutputType>
<IsPackable>true</IsPackable>
<Version>70.11.0</Version>
<Version>70.12.0</Version>
<Authors>mroloux;bverbeken</Authors>
<Title>Official Seats.io .NET API client</Title>
<Description>Official Seats.io .NET API client</Description>
Expand Down

0 comments on commit ea52d39

Please sign in to comment.