Skip to content

Commit

Permalink
Cake.Core upgraded to 3.0.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
Selman Gülmez committed Apr 28, 2023
1 parent 3bc1a2c commit 62b3f9c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,4 @@ Source/Cake.Discord/tools/**
BuildArtifacts/*

.DS_Store
/Source/.cr/personal/FavoritesList
5 changes: 2 additions & 3 deletions Source/Cake.Discord/Cake.Discord.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
Expand All @@ -15,8 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Cake.Core" Version="0.33.0" PrivateAssets="All" />
<PackageReference Include="Cake.Common" Version="0.33.0" PrivateAssets="All" />
<PackageReference Include="Cake.Common" Version="3.0.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
Expand Down
76 changes: 37 additions & 39 deletions Source/Cake.Discord/Chat/DiscordChatApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,47 +51,45 @@ internal static async Task<DiscordChatMessageResult> PostMessage(

context.Debug("Parameter: {0}", json);

using (var client = new HttpClient())
{
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");

var httpResponse = await client.PostAsync(webHookUrl, stringContent);
context.Debug($"Status Code: {httpResponse.StatusCode}");

DiscordChatMessageResult parsedResult = null;
if(httpResponse.StatusCode != System.Net.HttpStatusCode.NoContent)
{
var response = await httpResponse.Content.ReadAsStringAsync();
context.Debug($"Response: {response}");

var result = JsonMapper.ToObject(response);

parsedResult = new DiscordChatMessageResult(
false,
DateTime.UtcNow.ToString(),
result.GetInteger("code").Value,
result.GetString("message"));
}
else
{
parsedResult = new DiscordChatMessageResult(
true,
DateTime.UtcNow.ToString(),
0,
string.Empty);
using var client = new HttpClient();
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");

var httpResponse = await client.PostAsync(webHookUrl, stringContent);
context.Debug($"Status Code: {httpResponse.StatusCode}");

DiscordChatMessageResult parsedResult = null;
if (httpResponse.StatusCode != System.Net.HttpStatusCode.NoContent)
{
var response = await httpResponse.Content.ReadAsStringAsync();
context.Debug($"Response: {response}");

var result = JsonMapper.ToObject(response);

parsedResult = new DiscordChatMessageResult(
false,
DateTime.UtcNow.ToString(),
result.GetInteger("code").Value,
result.GetString("message"));
}
else
{
parsedResult = new DiscordChatMessageResult(
true,
DateTime.UtcNow.ToString(),
0,
string.Empty);
}

context.Debug("Result parsed: {0}", parsedResult);

if (!parsedResult.Ok && messageSettings.ThrowOnFail == true)
{
throw new CakeException(parsedResult.Error ?? "Failed to send message, unknown error");
}

return parsedResult;
}

context.Debug("Result parsed: {0}", parsedResult);

if (!parsedResult.Ok && messageSettings.ThrowOnFail == true)
{
throw new CakeException(parsedResult.Error ?? "Failed to send message, unknown error");
}

return parsedResult;
}
}

private static int? GetInteger(this JsonData data, string key)
{
return (data != null && data.Keys.Contains(key))
Expand Down

0 comments on commit 62b3f9c

Please sign in to comment.