diff --git a/Fortnox.NET.Tests/Fortnox.NET.Tests/WebSocket/FortnoxWebSocketClientTest.cs b/Fortnox.NET.Tests/Fortnox.NET.Tests/WebSocket/FortnoxWebSocketClientTest.cs index a853865..b141098 100644 --- a/Fortnox.NET.Tests/Fortnox.NET.Tests/WebSocket/FortnoxWebSocketClientTest.cs +++ b/Fortnox.NET.Tests/Fortnox.NET.Tests/WebSocket/FortnoxWebSocketClientTest.cs @@ -25,20 +25,20 @@ public async Task CanHandleCommandResponses() await client.Connect(); await client.AddTenant(this.connectionSettings.AccessToken); - var addTenantResponse = await client.Recieve(); + var addTenantResponse = await client.Receive(); Assert.IsTrue(addTenantResponse.Type == WebSocketResponseType.CommandResponse); Assert.IsTrue(addTenantResponse.Result.Equals("ok")); Assert.IsTrue(addTenantResponse.Response == WebSocketCommands.AddTenants); await client.AddTopic(WebSocketTopic.Articles); - var addTopicResponse = await client.Recieve(); + var addTopicResponse = await client.Receive(); Assert.IsTrue(addTopicResponse.Type == WebSocketResponseType.CommandResponse); Assert.IsTrue(addTopicResponse.Result.Equals("ok")); Assert.IsTrue(addTopicResponse.Response == WebSocketCommands.AddTopics); await client.Subscribe(); - var subscribeResponse = await client.Recieve(); + var subscribeResponse = await client.Receive(); Assert.IsTrue(subscribeResponse.Type == WebSocketResponseType.CommandResponse); Assert.IsTrue(subscribeResponse.Result.Equals("ok")); Assert.IsTrue(subscribeResponse.Response == WebSocketCommands.Subscribe); @@ -61,10 +61,10 @@ public async Task CanConnectAndListen() var updatedArticle = ArticleService.UpdateArticleAsync(request, article).GetAwaiter().GetResult(); Assert.AreEqual(updatedDescription, updatedArticle.Description); - var response = await client.Recieve(); + var response = await client.Receive(); while (response.Type != WebSocketResponseType.EventResponse) { - response = await client.Recieve(); + response = await client.Receive(); } Assert.IsTrue(response.Topic == WebSocketTopic.Articles.ToString()); @@ -89,21 +89,21 @@ public async Task CancellationTokenTest() var client = new FortnoxWebSocketClient(this.connectionSettings.ClientSecret); await client.Connect(); await client.AddTenant(this.connectionSettings.AccessToken); - await client.Recieve(); + await client.Receive(); await client.AddTopic(WebSocketTopic.Articles); - await client.Recieve(); + await client.Receive(); await client.Subscribe(); - await client.Recieve(); + await client.Receive(); CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); cancellationTokenSource.CancelAfter(2500); CancellationToken token = cancellationTokenSource.Token; - - // Recieve that will be cancelled after 2,5 seconds. - await Assert.ThrowsExceptionAsync(() => client.Recieve(token)); + + // Receive that will be cancelled after 2,5 seconds. + await Assert.ThrowsExceptionAsync(() => client.Receive(token)); // Underlying ClientWebSocket state will be set to "Aborted" once cancelled so we cannot re-use the socket now. - await Assert.ThrowsExceptionAsync(() => client.Recieve(token)); + await Assert.ThrowsExceptionAsync(() => client.Receive(token)); await client.Close(); } @@ -120,29 +120,29 @@ public async Task CanSubscribeToMultipleTopics() await client.AddTopic(WebSocketTopic.Orders); await client.Subscribe(); - var recievedArticleUpdate = false; - var recievedOrderUpdate = false; + var receivedArticleUpdate = false; + var receivedOrderUpdate = false; - while (!recievedArticleUpdate && !recievedOrderUpdate) + while (!receivedArticleUpdate && !receivedOrderUpdate) { - var response = await client.Recieve(); + var response = await client.Receive(); if (response.Type == WebSocketResponseType.EventResponse) { Assert.IsTrue(response.Topic == WebSocketTopic.Articles.ToString() || response.Topic == WebSocketTopic.Orders.ToString()); if (response.Topic == WebSocketTopic.Articles.ToString()) { - recievedArticleUpdate = true; + receivedArticleUpdate = true; } else if (response.Topic == WebSocketTopic.Orders.ToString()) { - recievedOrderUpdate = true; + receivedOrderUpdate = true; } Assert.IsTrue(response.EventType == WebSocketEventType.ArticleUpdated || response.EventType == WebSocketEventType.OrderUpdated); Assert.IsTrue(response.EntityId == "100370" || response.EntityId == "1"); - if (recievedArticleUpdate && recievedOrderUpdate) + if (receivedArticleUpdate && receivedOrderUpdate) { return; } diff --git a/Fortnox.NET/WebSockets/FortnoxWebSocketClient.cs b/Fortnox.NET/WebSockets/FortnoxWebSocketClient.cs index 81634b0..49ed633 100644 --- a/Fortnox.NET/WebSockets/FortnoxWebSocketClient.cs +++ b/Fortnox.NET/WebSockets/FortnoxWebSocketClient.cs @@ -35,7 +35,7 @@ public class FortnoxWebSocketClient /// /// The Fortnox passkey. /// The integrators key for making requests to Fortnox. - /// Optional target buffer size when recieving messages from the socket connection. + /// Optional target buffer size when receiving messages from the socket connection. public FortnoxWebSocketClient(string clientSecret, int bufferSize = DEFAULT_BUFFER_SIZE) { this._accessTokens = new List(); @@ -80,7 +80,7 @@ private async Task Send(string message, CancellationToken cancellationToken = de await _webSocket.SendAsync(messageBuffer, WebSocketMessageType.Text, true, cancellationToken); } - public async Task Recieve(CancellationToken cancellationToken = default) + public async Task Receive(CancellationToken cancellationToken = default) { var finished = false; var resultString = ""; @@ -105,7 +105,7 @@ public async Task Recieve(CancellationToken cancellationToken } else { - throw new WebSocketException("Unable to recieve as Websocket is closed."); + throw new WebSocketException("Unable to receive as Websocket is closed."); } } diff --git a/README.md b/README.md index a56555d..ff6f816 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ var response = await ArticleService.GetArticleAsync(request, "100370"); ### WebSocket If you want to subscribe to changes instead of having to poll for new information you can use the Fortnox WebSocket API. -You start by creating a FortnoxWebSocketClient with your ClientSecret. Proceed with calling `Connect` to initiate the connection with Fortnox followed by adding the desired topics and tenants to your connection and once you're ready call `Subscribe` to start recieving events. +You start by creating a FortnoxWebSocketClient with your ClientSecret. Proceed with calling `Connect` to initiate the connection with Fortnox followed by adding the desired topics and tenants to your connection and once you're ready call `Subscribe` to start receiving events. ```CSharp var client = new FortnoxWebSocketClient(this.connectionSettings.ClientSecret); @@ -55,24 +55,24 @@ await client.AddTopic(WebSocketTopic.Articles); await client.Subscribe(); ``` -Once you're subscribed you can call `Recieve` to recieve incoming messages. Performing actions such as `AddTenant`, `AddTopic` and `Subscribe` also results in a message being returned, if you wish you can handle those as well. In the following snippet we see an example which stores all action responses in their own variables followed by a while loop listening for incoming events. +Once you're subscribed you can call `Receive` to receive incoming messages. Performing actions such as `AddTenant`, `AddTopic` and `Subscribe` also results in a message being returned, if you wish you can handle those as well. In the following snippet we see an example which stores all action responses in their own variables followed by a while loop listening for incoming events. ```CSharp var client = new FortnoxWebSocketClient(this.connectionSettings.ClientSecret); await client.Connect(); await client.AddTenant(this.connectionSettings.AccessToken); -var addTenantResponse = await client.Recieve(); +var addTenantResponse = await client.Receive(); await client.AddTopic(WebSocketTopic.Articles); -var addTopicResponse = await client.Recieve(); +var addTopicResponse = await client.Receive(); await client.Subscribe(); -var subscribeResponse = await client.Recieve(); +var subscribeResponse = await client.Receive(); while (ListenToIncomingEvents) { - var response = await client.Recieve(); + var response = await client.Receive(); if (response.Type == WebSocketResponseType.EventResponse) { // Handle events