Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for async bugs and update packages #248

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 2 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,13 @@
[![Build status](https://ci.appveyor.com/api/projects/status/5n9e7sruxpo0mw79/branch/master?svg=true)](https://ci.appveyor.com/project/Inumedia/slackapi/branch/master)
[![NuGet](https://img.shields.io/nuget/v/SlackAPI.svg)](https://www.nuget.org/packages/SlackAPI/)
[![MyGet Pre Release](https://img.shields.io/myget/slackapi/vpre/SlackAPI.svg)](https://www.myget.org/feed/slackapi/package/nuget/SlackAPI)
[![NuGet](https://img.shields.io/nuget/v/SlackWorkAPI.svg)](https://www.nuget.org/packages/SlackWorkAPI/)

# SlackAPI
# SlackWorkAPI

This is a third party implementation of Slack's API written in C#. This supports their WebAPI as well as their Real Time Messaging API.

# Examples

Some examples can be found on the Wiki: https://github.com/Inumedia/SlackAPI/wiki/Examples

# Issues and Bugs

Please log an issue if you find any bugs or think something isn't correct.

# Getting in touch

I have a Slack setup for personal projects with a few friends, this includes this Github and a few others as public channels. If you want access, shoot me a quick email [email protected].

# Committer access

Want committer access? Feel like I'm too lazy to keep up with Slack's ever changing API? Want a bug fixed but don't want to log an issue for it?

Create some pull requests, give me a reason to give you access.

# How to build the solution
###### (aka where is the config.json file?)
The project **SlackAPI.Tests** requires a valid `config.json` file for tests. You have two options to build the solution:
- Unload SlackAPI.Tests project and you're able to build SlackAPI solution.
- Create your own config.json file to be able to run tests and validate your changes.
- Copy/paste `config.default.json` to `config.json`
- Update `config.json` file with your settings
- *userAuthToken* : Visit https://api.slack.com/docs/oauth-test-tokens to generate a token for your user
- *botAuthToken* : Visit https://my.slack.com/services/new/bot to create a bot for your Slack team and retrieve associated token
- *testChannel* : A channel ID (user associated to *userAuthToken* must be member of the channel)
- *directMessageUser* : A Slack member username
- *clientId*/*clientSecret*/*authCode* : Not used

# NuGet package
SlackAPI NuGet package is build with following platforms support:
- .NET Framework 4.5
Expand Down
11 changes: 6 additions & 5 deletions SlackAPI.Tests/SlackAPI.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Polly" Version="7.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Polly" Version="7.2.1" />
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="2.43.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0">
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="84.0.4147.3001" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions SlackAPI.Tests/UploadFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public async Task UploadFileAsync_Succeeds()
byte[] data = new byte[FileSize];

// Act
var fileUploadResponse = await this.fixture.UserClientAsync.UploadFileAsync(data, FileName, new[] { this.fixture.Config.TestChannel });
var fileUploadResponse = await this.fixture.UserClientAsync.UploadFileAsync(data, FileName, new[] { this.fixture.Config.TestChannel }).ConfigureAwait(false);

// Assert
Assert.True(fileUploadResponse.ok);
var fileInfoResponse = await this.fixture.UserClientAsync.GetFileInfoAsync(fileUploadResponse.file.id);
var fileInfoResponse = await this.fixture.UserClientAsync.GetFileInfoAsync(fileUploadResponse.file.id).ConfigureAwait(false);
Assert.True(fileInfoResponse.ok);
Assert.Equal(FileSize, fileInfoResponse.file.size);
Assert.Equal(FileName, fileInfoResponse.file.name);
Expand Down
1 change: 0 additions & 1 deletion SlackAPI.Tests/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down
8 changes: 4 additions & 4 deletions SlackAPI/RequestStateForTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private async Task<K> ExecuteResult()
HttpWebResponse response = null;
try
{
response = (HttpWebResponse)await this.request.GetResponseAsync();
response = (HttpWebResponse)await this.request.GetResponseAsync().ConfigureAwait(false);
Success = true;
}
catch (WebException we)
Expand Down Expand Up @@ -68,7 +68,7 @@ private async Task<K> ExecutePost()
{
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
using (Stream requestStream = await request.GetRequestStreamAsync())
using (Stream requestStream = await request.GetRequestStreamAsync().ConfigureAwait(false))
{
if (Post.Length > 0)
{
Expand All @@ -80,15 +80,15 @@ private async Task<K> ExecutePost()
if (!first)
writer.Write('&');

await writer.WriteAsync(string.Format("{0}={1}", Uri.EscapeDataString(postEntry.Item1), Uri.EscapeDataString(postEntry.Item2)));
await writer.WriteAsync(string.Format("{0}={1}", Uri.EscapeDataString(postEntry.Item1), Uri.EscapeDataString(postEntry.Item2))).ConfigureAwait(false);

first = false;
}
}
}
}

return await this.ExecuteResult();
return await this.ExecuteResult().ConfigureAwait(false);
}
}
}
2 changes: 1 addition & 1 deletion SlackAPI/SlackAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion SlackAPI/SlackSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void SetupReceiving()
WebSocketReceiveResult result = null;
try
{
result = await socket.ReceiveAsync(buffer, cts.Token);
result = await socket.ReceiveAsync(buffer, cts.Token).ConfigureAwait(false);
}
catch (WebSocketException wex)
{
Expand Down
4 changes: 2 additions & 2 deletions SlackAPI/SlackTaskClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public SlackTaskClient(string token, IWebProxy proxySettings)

public virtual async Task<LoginResponse> ConnectAsync()
{
var loginDetails = await EmitLoginAsync();
var loginDetails = await EmitLoginAsync().ConfigureAwait(false);
if(loginDetails.ok)
Connected(loginDetails);

Expand Down Expand Up @@ -651,7 +651,7 @@ public async Task<FileUploadResponse> UploadFileAsync(byte[] fileData, string fi
{
form.Add(new ByteArrayContent(fileData), "file", fileName);
HttpResponseMessage response = PostRequest(string.Format("{0}?{1}", target, string.Join("&", parameters.ToArray())), form);
string result = await response.Content.ReadAsStringAsync();
string result = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
return result.Deserialize<FileUploadResponse>();
}
}
Expand Down