Skip to content

Commit

Permalink
Added best available support when holding objects
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux committed Aug 22, 2018
1 parent 3776ffa commit 5f1d22a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
14 changes: 14 additions & 0 deletions SeatsioDotNet.Test/Events/HoldObjectsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,19 @@ public void OrderId()
Assert.Equal("order1", Client.Events.RetrieveObjectStatus(evnt.Key, "A-1").OrderId);
Assert.Equal("order1", Client.Events.RetrieveObjectStatus(evnt.Key, "A-2").OrderId);
}

[Fact]
public void BestAvailable()
{
var chartKey = CreateTestChart();
var evnt = Client.Events.Create(chartKey);
HoldToken holdToken = Client.HoldTokens.Create();

var bestAvailableResult = Client.Events.Hold(evnt.Key, new BestAvailable(3), holdToken.Token, "order1");

Assert.True(bestAvailableResult.NextToEachOther);
Assert.Equal(new[] {"B-4", "B-5", "B-6"}, bestAvailableResult.Objects);
Assert.Equal("order1", Client.Events.RetrieveObjectStatus(evnt.Key, "B-4").OrderId);
}
}
}
16 changes: 15 additions & 1 deletion SeatsioDotNet/Events/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ public ChangeObjectStatusResult Hold(string[] eventKeys, IEnumerable<ObjectPrope
return ChangeObjectStatus(eventKeys, objects, ObjectStatus.Held, holdToken, orderId);
}

public BestAvailableResult Hold(string eventKey, BestAvailable bestAvailable, string holdToken, string orderId = null)
{
return ChangeObjectStatus(eventKey, bestAvailable, ObjectStatus.Held, holdToken, orderId);
}

public ChangeObjectStatusResult ChangeObjectStatus(string eventKey, IEnumerable<string> objects, string status, string holdToken = null, string orderId = null)
{
return ChangeObjectStatus(new[] {eventKey}, objects.Select(o => new ObjectProperties(o)), status, holdToken, orderId);
Expand Down Expand Up @@ -186,13 +191,22 @@ public ChangeObjectStatusResult ChangeObjectStatus(IEnumerable<string> events, I
return AssertOk(_restClient.Execute<ChangeObjectStatusResult>(restRequest));
}

public BestAvailableResult ChangeObjectStatus(string eventKey, BestAvailable bestAvailable, string status)
public BestAvailableResult ChangeObjectStatus(string eventKey, BestAvailable bestAvailable, string status, string holdToken = null, string orderId = null)
{
var requestBody = new Dictionary<string, object>()
{
{"status", status},
{"bestAvailable", bestAvailable.AsDictionary()}
};
if (holdToken != null)
{
requestBody.Add("holdToken", holdToken);
}

if (orderId != null)
{
requestBody.Add("orderId", orderId);
}

var restRequest = new RestRequest("/events/{key}/actions/change-object-status", Method.POST)
.AddUrlSegment("key", eventKey)
Expand Down
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>32</Version>
<Version>33</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 5f1d22a

Please sign in to comment.