Skip to content

Commit

Permalink
Merge pull request #11 from seatsio/matti/api-calls-take-optional-acc…
Browse files Browse the repository at this point in the history
…ount-id

API calls take optional account ID
  • Loading branch information
mroloux authored Oct 9, 2019
2 parents 2355d3e + f33a9c8 commit 2212aee
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion SeatsioDotNet.Test/ErrorHandlingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void Test4xx()
public void WeirdError()
{
var e = Assert.Throws<SeatsioException>(() =>
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);
Expand Down
1 change: 1 addition & 0 deletions SeatsioDotNet.Test/HoldTokens/RetrieveHoldTokenTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
7 changes: 6 additions & 1 deletion SeatsioDotNet.Test/SeatsioClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
1 change: 1 addition & 0 deletions SeatsioDotNet.Test/Subaccounts/RetrieveSubaccountTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
18 changes: 18 additions & 0 deletions SeatsioDotNet.Test/WorkspaceKeyAuthenticationTest.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
1 change: 1 addition & 0 deletions SeatsioDotNet/HoldTokens/HoldToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
17 changes: 13 additions & 4 deletions SeatsioDotNet/SeatsioClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
}
Expand Down
1 change: 1 addition & 0 deletions SeatsioDotNet/Subaccounts/Subaccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit 2212aee

Please sign in to comment.