diff --git a/SeatsioDotNet.Test/Events/AssignObjectsToChannelTest.cs b/SeatsioDotNet.Test/Events/AssignObjectsToChannelTest.cs new file mode 100644 index 0000000..a510eae --- /dev/null +++ b/SeatsioDotNet.Test/Events/AssignObjectsToChannelTest.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using SeatsioDotNet.Events; +using Xunit; + + +namespace SeatsioDotNet.Test.Events +{ + public class AssignObjectsToChannelTest : SeatsioClientTest + { + + [Fact] + public void assignObjectsToChannel() { + var chartKey1 = CreateTestChart(); + var event1 = Client.Events.Create(chartKey1); + var channels = new Dictionary() + { + { "channelKey1", new Channel("channel 1", "#FFFF00", 1) }, + { "channelKey2", new Channel("channel 2", "#00FFFF", 2) } + }; + Client.Events.UpdateChannels(event1.Key, channels); + + Client.Events.AssignObjectsToChannel(event1.Key, new + { + channelKey1 = new [] {"A-1", "A-2"}, + channelKey2 = new [] {"A-3"}, + }); + + var retrievedChannels = Client.Events.Retrieve(event1.Key).Channels; + Assert.Equal(new [] {"A-1", "A-2"}, retrievedChannels[0].Objects); + Assert.Equal(new [] {"A-3"}, retrievedChannels[1].Objects); + } + } +} diff --git a/SeatsioDotNet.Test/Events/UpdateChannelsTest.cs b/SeatsioDotNet.Test/Events/UpdateChannelsTest.cs new file mode 100644 index 0000000..3834dbd --- /dev/null +++ b/SeatsioDotNet.Test/Events/UpdateChannelsTest.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using SeatsioDotNet.Events; +using Xunit; + + +namespace SeatsioDotNet.Test.Events +{ + public class UpdateChannelsTest : SeatsioClientTest + { + + [Fact] + public void UpdateChannels() { + var chartKey1 = CreateTestChart(); + var event1 = Client.Events.Create(chartKey1); + + var channels = new Dictionary() + { + { "channelKey1", new Channel("channel 1", "#FFFF00", 1) }, + { "channelKey2", new Channel("channel 2", "#00FFFF", 2) } + }; + + Client.Events.UpdateChannels(event1.Key, channels); + + var retrievedEvent = Client.Events.Retrieve(event1.Key); + Assert.Equal(2, retrievedEvent.Channels.Count); + + var channel1 = retrievedEvent.Channels[0]; + Assert.Equal("channelKey1", channel1.Key); + Assert.Equal("channel 1", channel1.Name); + Assert.Equal("#FFFF00", channel1.Color); + Assert.Equal(1, channel1.Index); + Assert.Empty(channel1.Objects); + + + var channel2 = retrievedEvent.Channels[1]; + Assert.Equal("channelKey2", channel2.Key); + Assert.Equal("channel 2", channel2.Name); + Assert.Equal("#00FFFF", channel2.Color); + Assert.Equal(2, channel2.Index); + Assert.Empty(channel1.Objects); + } + + } +} diff --git a/SeatsioDotNet/Events/Channel.cs b/SeatsioDotNet/Events/Channel.cs new file mode 100644 index 0000000..b616ef7 --- /dev/null +++ b/SeatsioDotNet/Events/Channel.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using RestSharp.Deserializers; + +namespace SeatsioDotNet.Events +{ + public class Channel + { + public string Key { get; set; } + public string Name { get; set; } + public string Color { get; set; } + public int Index { get; set; } + public IEnumerable Objects { get; set; } + + public Channel() {} + + public Channel(string name, string color, int index) + { + Name = name; + Color = color; + Index = index; + } + + public object AsJsonObject() + { + return new + { + name = Name, + index = Index, + color = Color + }; + } + + } +} diff --git a/SeatsioDotNet/Events/Event.cs b/SeatsioDotNet/Events/Event.cs index 31a7ebb..200776b 100644 --- a/SeatsioDotNet/Events/Event.cs +++ b/SeatsioDotNet/Events/Event.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using RestSharp.Deserializers; namespace SeatsioDotNet.Events { @@ -14,5 +15,6 @@ public class Event public ForSaleConfig ForSaleConfig { get; set; } public DateTimeOffset? CreatedOn { get; set; } public DateTimeOffset? UpdatedOn { get; set; } + public List Channels { get; set; } } -} \ No newline at end of file +} diff --git a/SeatsioDotNet/Events/Events.cs b/SeatsioDotNet/Events/Events.cs index 95e01ea..c4d0f31 100644 --- a/SeatsioDotNet/Events/Events.cs +++ b/SeatsioDotNet/Events/Events.cs @@ -59,7 +59,7 @@ private Event Create(string chartKey, string eventKey, bool? bookWholeTables, Di var restRequest = new RestRequest("/events", Method.POST).AddJsonBody(requestBody); return AssertOk(_restClient.Execute(restRequest)); } - + public Event[] Create(string chartKey, EventCreationParams[] eventCreationParams) { Dictionary requestBody = new Dictionary(); @@ -72,18 +72,18 @@ public Event[] Create(string chartKey, EventCreationParams[] eventCreationParams { e.Add("eventKey", param.Key); } - if (param.BookWholeTables != null) + if (param.BookWholeTables != null) { e.Add("bookWholeTables", param.BookWholeTables); } - if (param.TableBookingModes != null) + if (param.TableBookingModes != null) { e.Add("tableBookingModes", param.TableBookingModes); - } + } events.Add(e); } - requestBody.Add("events", events.ToArray()); - var restRequest = new RestRequest("/events/actions/create-multiple", Method.POST).AddJsonBody(requestBody); + requestBody.Add("events", events.ToArray()); + var restRequest = new RestRequest("/events/actions/create-multiple", Method.POST).AddJsonBody(requestBody); return AssertOk(_restClient.Execute(restRequest)).events.ToArray(); } @@ -270,7 +270,7 @@ private Dictionary ChangeObjectStatusRequest(IEnumerable request.Add("events", events); return request; } - + private Dictionary ChangeObjectStatusRequest(IEnumerable objects, string status, string holdToken, string orderId, bool? keepExtraData) { var requestBody = new Dictionary() @@ -304,7 +304,7 @@ public BestAvailableResult ChangeObjectStatus(string eventKey, BestAvailable bes {"status", status}, {"bestAvailable", bestAvailable.AsDictionary()} }; - + if (holdToken != null) { requestBody.Add("holdToken", holdToken); @@ -385,6 +385,43 @@ private Dictionary ForSaleRequest(IEnumerable objects, I return request; } + public void UpdateChannels(string eventKey, Dictionary channels) + { + var requestBody = UpdateChannelsRequest(channels); + var restRequest = new RestRequest("/events/{key}/channels/update", Method.POST) + .AddUrlSegment("key", eventKey) + .AddJsonBody(requestBody); + AssertOk(_restClient.Execute(restRequest)); + } + + private Dictionary UpdateChannelsRequest(Dictionary channels) + { + var channelsJson = new Dictionary(); + foreach(KeyValuePair entry in channels) + { + channelsJson.Add(entry.Key, entry.Value.AsJsonObject()); + } + var request = new Dictionary(); + request.Add("channels", channelsJson); + return request; + } + + public void AssignObjectsToChannel(string eventKey, object channelsConfig) + { + var requestBody = AssignObjectsToChannelsRequest(channelsConfig); + var restRequest = new RestRequest("/events/{key}/channels/assign-objects", Method.POST) + .AddUrlSegment("key", eventKey) + .AddJsonBody(requestBody); + AssertOk(_restClient.Execute(restRequest)); + } + + private Dictionary AssignObjectsToChannelsRequest(object channelsConfig) + { + var request = new Dictionary(); + request.Add("channelConfig", channelsConfig); + return request; + } + public IEnumerable ListAll() { return List().All(); @@ -443,10 +480,10 @@ public Lister StatusChangesForObject(string eventKey, string objec request => (RestRequest) request.AddUrlSegment("key", eventKey).AddUrlSegment("objectId", objectLabel) )); } - + private class ChangeObjectStatusInBatchResult { public List Results { get; set; } } } -} \ No newline at end of file +}