diff --git a/SeatsioDotNet.Test/ErrorHandlingTest.cs b/SeatsioDotNet.Test/ErrorHandlingTest.cs index a4d931b..27ec8ce 100644 --- a/SeatsioDotNet.Test/ErrorHandlingTest.cs +++ b/SeatsioDotNet.Test/ErrorHandlingTest.cs @@ -19,7 +19,7 @@ public void Test4xx() public void WeirdError() { var e = Assert.Throws(() => - new SeatsioClient("", "unknownProtocol://").Events.RetrieveObjectStatus("unexistingEvent", "unexistingObject")); + new SeatsioClient("", null, "unknownProtocol://").Events.RetrieveObjectStatus("unexistingEvent", "unexistingObject")); Assert.Equal("GET resulted in a 0 response.", e.Message); Assert.Null(e.Errors); diff --git a/SeatsioDotNet.Test/HoldTokens/RetrieveHoldTokenTest.cs b/SeatsioDotNet.Test/HoldTokens/RetrieveHoldTokenTest.cs index 352d7f3..81a6095 100644 --- a/SeatsioDotNet.Test/HoldTokens/RetrieveHoldTokenTest.cs +++ b/SeatsioDotNet.Test/HoldTokens/RetrieveHoldTokenTest.cs @@ -14,6 +14,7 @@ public void Test() Assert.Equal(holdToken.Token, retrievedHoldToken.Token); Assert.Equal(holdToken.ExpiresAt, retrievedHoldToken.ExpiresAt); Assert.InRange(holdToken.ExpiresInSeconds, 14 * 60, 15 * 60); + Assert.NotNull(holdToken.workspaceKey); } } } \ No newline at end of file diff --git a/SeatsioDotNet.Test/SeatsioClientTest.cs b/SeatsioDotNet.Test/SeatsioClientTest.cs index b6efa89..c2bd2da 100644 --- a/SeatsioDotNet.Test/SeatsioClientTest.cs +++ b/SeatsioDotNet.Test/SeatsioClientTest.cs @@ -64,7 +64,12 @@ protected string CreateTestChartFromJson(String json) protected SeatsioClient CreateSeatsioClient(string secretKey) { - return new SeatsioClient(secretKey, BaseUrl); + return new SeatsioClient(secretKey, null, BaseUrl); + } + + protected SeatsioClient CreateSeatsioClient(string secretKey, string workspaceKey) + { + return new SeatsioClient(secretKey, workspaceKey, BaseUrl); } } } \ No newline at end of file diff --git a/SeatsioDotNet.Test/Subaccounts/RetrieveSubaccountTest.cs b/SeatsioDotNet.Test/Subaccounts/RetrieveSubaccountTest.cs index d96197b..96b6c52 100644 --- a/SeatsioDotNet.Test/Subaccounts/RetrieveSubaccountTest.cs +++ b/SeatsioDotNet.Test/Subaccounts/RetrieveSubaccountTest.cs @@ -17,6 +17,7 @@ public void Test() Assert.Equal(subaccount.PublicKey, retrievedSubaccount.PublicKey); Assert.Equal("joske", retrievedSubaccount.Name); Assert.True(retrievedSubaccount.Active); + Assert.NotNull(retrievedSubaccount.workspaceKey); } } } \ No newline at end of file diff --git a/SeatsioDotNet.Test/WorkspaceKeyAuthenticationTest.cs b/SeatsioDotNet.Test/WorkspaceKeyAuthenticationTest.cs new file mode 100644 index 0000000..02cb08e --- /dev/null +++ b/SeatsioDotNet.Test/WorkspaceKeyAuthenticationTest.cs @@ -0,0 +1,18 @@ +using Xunit; + +namespace SeatsioDotNet.Test +{ + public class WorkspaceKeyAuthenticationTest : SeatsioClientTest + { + [Fact] + public void Test() + { + var subaccount = Client.Subaccounts.Create(); + + var subaccountClient = CreateSeatsioClient(User.SecretKey, subaccount.workspaceKey); + var holdToken = subaccountClient.HoldTokens.Create(); + + Assert.Equal(subaccount.workspaceKey, holdToken.workspaceKey); + } + } +} \ No newline at end of file diff --git a/SeatsioDotNet/HoldTokens/HoldToken.cs b/SeatsioDotNet/HoldTokens/HoldToken.cs index 3c27fbf..dc7e713 100644 --- a/SeatsioDotNet/HoldTokens/HoldToken.cs +++ b/SeatsioDotNet/HoldTokens/HoldToken.cs @@ -9,5 +9,6 @@ public class HoldToken public string Token { get; set; } public DateTimeOffset ExpiresAt { get; set; } public int ExpiresInSeconds { get; set; } + public string workspaceKey { get; set; } } } \ No newline at end of file diff --git a/SeatsioDotNet/SeatsioClient.cs b/SeatsioDotNet/SeatsioClient.cs index a624a90..7761c83 100644 --- a/SeatsioDotNet/SeatsioClient.cs +++ b/SeatsioDotNet/SeatsioClient.cs @@ -14,9 +14,9 @@ public class SeatsioClient public ChartReports.ChartReports ChartReports { get; } public UsageReports.UsageReports UsageReports { get; } - public SeatsioClient(string secretKey, string baseUrl) + public SeatsioClient(string secretKey, string workspaceKey, string baseUrl) { - var restClient = CreateRestClient(secretKey, baseUrl); + var restClient = CreateRestClient(secretKey, workspaceKey, baseUrl); Charts = new Charts.Charts(restClient); Events = new Events.Events(restClient); Accounts = new Accounts.Accounts(restClient); @@ -27,14 +27,23 @@ public SeatsioClient(string secretKey, string baseUrl) UsageReports = new UsageReports.UsageReports(restClient); } - public SeatsioClient(string secretKey): this(secretKey, "https://api.seatsio.net") + public SeatsioClient(string secretKey, string workspaceKey) : this(secretKey, workspaceKey, "https://api.seatsio.net") { } - private static RestClient CreateRestClient(string secretKey, string baseUrl) + public SeatsioClient(string secretKey) : this(secretKey, null) + { + } + + private static RestClient CreateRestClient(string secretKey, string workspaceKey, string baseUrl) { var client = new RestClient(baseUrl); client.Authenticator = new HttpBasicAuthenticator(secretKey, null); + if (workspaceKey != null) + { + client.AddDefaultHeader("X-Workspace-Key", workspaceKey.ToString()); + } + return client; } } diff --git a/SeatsioDotNet/Subaccounts/Subaccount.cs b/SeatsioDotNet/Subaccounts/Subaccount.cs index bf772f7..5173acb 100644 --- a/SeatsioDotNet/Subaccounts/Subaccount.cs +++ b/SeatsioDotNet/Subaccounts/Subaccount.cs @@ -3,6 +3,7 @@ public class Subaccount { public long Id { get; set; } + public string workspaceKey { get; set; } public string SecretKey { get; set; } public string DesignerKey { get; set; } public string PublicKey { get; set; }