Skip to content

Commit

Permalink
Fixed method name spelling error. (#21)
Browse files Browse the repository at this point in the history
* Fixed method name spelling error.

* Fixed remaining spelling mistakes.

* Updated documentation.
  • Loading branch information
brokenprogrammer authored Oct 5, 2020
1 parent d2cf5c3 commit 0a7f4df
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand All @@ -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<TaskCanceledException>(() => client.Recieve(token));

// Receive that will be cancelled after 2,5 seconds.
await Assert.ThrowsExceptionAsync<TaskCanceledException>(() => client.Receive(token));

// Underlying ClientWebSocket state will be set to "Aborted" once cancelled so we cannot re-use the socket now.
await Assert.ThrowsExceptionAsync<WebSocketException>(() => client.Recieve(token));
await Assert.ThrowsExceptionAsync<WebSocketException>(() => client.Receive(token));

await client.Close();
}
Expand All @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions Fortnox.NET/WebSockets/FortnoxWebSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class FortnoxWebSocketClient
/// </summary>
/// <param name="accessToken">The Fortnox passkey.</param>
/// <param name="clientSecret">The integrators key for making requests to Fortnox.</param>
/// <param name="bufferSize">Optional target buffer size when recieving messages from the socket connection.</param>
/// <param name="bufferSize">Optional target buffer size when receiving messages from the socket connection.</param>
public FortnoxWebSocketClient(string clientSecret, int bufferSize = DEFAULT_BUFFER_SIZE)
{
this._accessTokens = new List<string>();
Expand Down Expand Up @@ -80,7 +80,7 @@ private async Task Send(string message, CancellationToken cancellationToken = de
await _webSocket.SendAsync(messageBuffer, WebSocketMessageType.Text, true, cancellationToken);
}

public async Task<WebSocketResponse> Recieve(CancellationToken cancellationToken = default)
public async Task<WebSocketResponse> Receive(CancellationToken cancellationToken = default)
{
var finished = false;
var resultString = "";
Expand All @@ -105,7 +105,7 @@ public async Task<WebSocketResponse> Recieve(CancellationToken cancellationToken
}
else
{
throw new WebSocketException("Unable to recieve as Websocket is closed.");
throw new WebSocketException("Unable to receive as Websocket is closed.");
}
}

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 0a7f4df

Please sign in to comment.