Skip to content

Commit

Permalink
Implements new Post in ISlackApiClient
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmurb committed Aug 26, 2019
1 parent 3e8e4ee commit 2138473
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 58 deletions.
3 changes: 3 additions & 0 deletions SlackNet.Tests/ApiLintTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ public Task Post(string apiMethod, Args args, HttpContent content, CancellationT
return Task.FromResult(0);
}

public Task Post(string apiMethod, Args args, CancellationToken? cancellationToken) =>
Post<object>(apiMethod, args, cancellationToken);

public Task<T> Post<T>(string apiMethod, Args args, CancellationToken? cancellationToken) where T : class
{
HttpMethod = "POST";
Expand Down
36 changes: 26 additions & 10 deletions SlackNet/SlackApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,28 @@ public interface ISlackApiClient
/// Calls a Slack API that requires POST content.
/// </summary>
/// <param name="apiMethod">Name of Slack method.</param>
/// <param name="args">Arguments to send to Slack. The "token" parameter will be filled in automatically.</param>
/// <param name="content">POST body content. Should be either <see cref="FormUrlEncodedContent"/> or <see cref="MultipartFormDataContent"/>.</param>
/// <param name="args">Arguments to send to Slack. Authorization headers will be added automatically.</param>
/// <param name="cancellationToken"></param>
Task Post(string apiMethod, Args args, HttpContent content, CancellationToken? cancellationToken);

Task Post(string apiMethod, Args args, CancellationToken? cancellationToken);
/// <summary>
/// Calls a Slack API that requires POST content.
/// </summary>
/// <typeparam name="T">Type of response expected.</typeparam>
/// <param name="apiMethod">Name of Slack method.</param>
/// <param name="args">Arguments to send to Slack. Authorization headers will be added automagically.</param>
/// <param name="args">Arguments to send to Slack. Authorization headers will be added automatically.</param>
/// <param name="cancellationToken"></param>
Task<T> Post<T>(string apiMethod, Args args, CancellationToken? cancellationToken) where T : class;

/// <summary>
/// Calls a Slack API that requires POST content.
/// </summary>
/// <param name="apiMethod">Name of Slack method.</param>
/// <param name="args">Arguments to send to Slack. The "token" parameter will be filled in automatically.</param>
/// <param name="content">POST body content. Should be either <see cref="FormUrlEncodedContent"/> or <see cref="MultipartFormDataContent"/>.</param>
/// <param name="cancellationToken"></param>
Task Post(string apiMethod, Args args, HttpContent content, CancellationToken? cancellationToken);

/// <summary>
/// Calls a Slack API that requires POST content.
/// </summary>
Expand Down Expand Up @@ -161,17 +169,15 @@ public async Task<T> Get<T>(string apiMethod, Args args, CancellationToken? canc
var requestMessage = new HttpRequestMessage(HttpMethod.Get, Url(apiMethod, args));
return Deserialize<T>(await _http.Execute<WebApiResponse>(requestMessage, cancellationToken ?? CancellationToken.None).ConfigureAwait(false));
}



/// <summary>
/// Calls a Slack API that requires POST content.
/// </summary>
/// <param name="apiMethod">Name of Slack method.</param>
/// <param name="args">Arguments to send to Slack. The "token" parameter will be filled in automatically.</param>
/// <param name="content">POST body content. Should be either <see cref="FormUrlEncodedContent"/> or <see cref="MultipartFormDataContent"/>.</param>
/// <param name="cancellationToken"></param>
public Task Post(string apiMethod, Args args, HttpContent content, CancellationToken? cancellationToken) =>
Post<object>(apiMethod, args, content, cancellationToken);
public Task Post(string apiMethod, Args args, CancellationToken? cancellationToken) =>
Post<object>(apiMethod, args, cancellationToken);

/// <summary>
/// Calls a Slack API that requires POST content.
Expand All @@ -190,6 +196,16 @@ public async Task<T> Post<T>(string apiMethod, Args args, CancellationToken? can
return Deserialize<T>(response);
}

/// <summary>
/// Calls a Slack API that requires POST content.
/// </summary>
/// <param name="apiMethod">Name of Slack method.</param>
/// <param name="args">Arguments to send to Slack. The "token" parameter will be filled in automatically.</param>
/// <param name="content">POST body content. Should be either <see cref="FormUrlEncodedContent"/> or <see cref="MultipartFormDataContent"/>.</param>
/// <param name="cancellationToken"></param>
public Task Post(string apiMethod, Args args, HttpContent content, CancellationToken? cancellationToken) =>
Post<object>(apiMethod, args, content, cancellationToken);

/// <summary>
/// Calls a Slack API that requires POST content.
/// </summary>
Expand Down
10 changes: 5 additions & 5 deletions SlackNet/WebApi/ChannelsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public class ChannelsApi : IChannelsApi
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task Archive(string channelId, CancellationToken? cancellationToken = null) =>
_client.Post<object>("channels.archive", new Args { { "channel", channelId } }, cancellationToken);
_client.Post("channels.archive", new Args { { "channel", channelId } }, cancellationToken);

/// <summary>
/// Used to create a channel.
Expand Down Expand Up @@ -253,7 +253,7 @@ public Task<ChannelJoinResponse> Join(string channelName, bool validate = false,
/// <param name="userId">User to remove from channel.</param>
/// <param name="cancellationToken"></param>
public Task Kick(string channelId, string userId, CancellationToken? cancellationToken = null) =>
_client.Post<object>("channels.kick", new Args
_client.Post("channels.kick", new Args
{
{ "channel", channelId },
{ "user", userId }
Expand All @@ -266,7 +266,7 @@ public Task Kick(string channelId, string userId, CancellationToken? cancellatio
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task Leave(string channelId, CancellationToken? cancellationToken = null) =>
_client.Post<object>("channels.leave", new Args { { "channel", channelId } }, cancellationToken);
_client.Post("channels.leave", new Args { { "channel", channelId } }, cancellationToken);

/// <summary>
/// Returns a list of all channels in the team.
Expand All @@ -292,7 +292,7 @@ public async Task<IReadOnlyList<Channel>> List(bool excludeArchived = false, boo
/// <param name="ts">Timestamp of the most recently seen message.</param>
/// <param name="cancellationToken"></param>
public Task Mark(string channelId, string ts, CancellationToken? cancellationToken = null) =>
_client.Post<object>("channels.mark", new Args
_client.Post("channels.mark", new Args
{
{ "channel", channelId },
{ "ts", ts }
Expand Down Expand Up @@ -366,6 +366,6 @@ public async Task<string> SetTopic(string channelId, string topic, CancellationT
/// <param name="channelId">Channel to unarchive.</param>
/// <param name="cancellationToken"></param>
public Task Unarchive(string channelId, CancellationToken? cancellationToken = null) =>
_client.Post<object>("channels.unarchive", new Args { { "channel", channelId } }, cancellationToken);
_client.Post("channels.unarchive", new Args { { "channel", channelId } }, cancellationToken);
}
}
2 changes: 1 addition & 1 deletion SlackNet/WebApi/ChatApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public Task<PostMessageResponse> PostEphemeral(string userId, Message message, C
/// Subsequent attempts with the same <see cref="ts"/> and <see cref="channelId"/> values will modify the same attachments, rather than adding more.
/// </remarks>
public Task Unfurl(string channelId, string ts, IDictionary<string, Attachment> unfurls, bool userAuthRequired = false, CancellationToken? cancellationToken = null) =>
_client.Post<object>("chat.unfurl", new Args
_client.Post("chat.unfurl", new Args
{
{ "channel", channelId },
{ "ts", ts },
Expand Down
10 changes: 5 additions & 5 deletions SlackNet/WebApi/ConversationsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public class ConversationsApi : IConversationsApi
/// <param name="channelId">ID of conversation to archive.</param>
/// <param name="cancellationToken"></param>
public Task Archive(string channelId, CancellationToken? cancellationToken = null) =>
_client.Post<object>("conversations.archive", new Args { { "channel", channelId } }, cancellationToken);
_client.Post("conversations.archive", new Args { { "channel", channelId } }, cancellationToken);

/// <summary>
/// Closes a direct message or multi-person direct message.
Expand All @@ -216,7 +216,7 @@ public Task Archive(string channelId, CancellationToken? cancellationToken = nul
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task Close(string channelId, CancellationToken? cancellationToken = null) =>
_client.Post<object>("conversations.close", new Args { { "channel", channelId } }, cancellationToken);
_client.Post("conversations.close", new Args { { "channel", channelId } }, cancellationToken);

/// <summary>
/// Initiates a public or private channel-based conversation.
Expand Down Expand Up @@ -303,7 +303,7 @@ public Task<ConversationJoinResponse> Join(string channelId, CancellationToken?
/// <param name="userId">User ID to be removed.</param>
/// <param name="cancellationToken"></param>
public Task Kick(string channelId, string userId, CancellationToken? cancellationToken = null) =>
_client.Post<object>("conversations.kick", new Args
_client.Post("conversations.kick", new Args
{
{ "channel", channelId },
{ "user", userId }
Expand All @@ -315,7 +315,7 @@ public Task Kick(string channelId, string userId, CancellationToken? cancellatio
/// <param name="channelId">Conversation to leave.</param>
/// <param name="cancellationToken"></param>
public Task Leave(string channelId, CancellationToken? cancellationToken = null) =>
_client.Post<object>("conversations.leave", new Args { { "channel", channelId } }, cancellationToken);
_client.Post("conversations.leave", new Args { { "channel", channelId } }, cancellationToken);

/// <summary>
/// Lists all channels in a Slack team.
Expand Down Expand Up @@ -478,6 +478,6 @@ public async Task<string> SetTopic(string channelId, string topic, CancellationT
/// <param name="channelId">ID of conversation to unarchive.</param>
/// <param name="cancellationToken"></param>
public Task Unarchive(string channelId, CancellationToken? cancellationToken = null) =>
_client.Post<object>("conversations.unarchive", new Args { { "channel", channelId } }, cancellationToken);
_client.Post("conversations.unarchive", new Args { { "channel", channelId } }, cancellationToken);
}
}
2 changes: 1 addition & 1 deletion SlackNet/WebApi/DialogApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class DialogApi : IDialogApi
/// <param name="dialog">The dialog definition.</param>
/// <param name="cancellationToken"></param>
public Task Open(string triggerId, Dialog dialog, CancellationToken? cancellationToken = null) =>
_client.Post<object>("dialog.open", new Args
_client.Post("dialog.open", new Args
{
{ "dialog", dialog },
{ "trigger_id", triggerId }
Expand Down
2 changes: 1 addition & 1 deletion SlackNet/WebApi/DndApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class DndApi : IDndApi
/// </summary>
/// <param name="cancellationToken"></param>
public Task EndDnd(CancellationToken? cancellationToken = null) =>
_client.Post<object>("dnd.endDnd", new Args(), cancellationToken);
_client.Post("dnd.endDnd", new Args(), cancellationToken);

/// <summary>
/// Ends the current user's snooze mode immediately.
Expand Down
2 changes: 1 addition & 1 deletion SlackNet/WebApi/FileCommentsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class FileCommentsApi : IFileCommentsApi
/// <param name="commentId">The comment to delete.</param>
/// <param name="cancellationToken"></param>
public Task Delete(string fileId, string commentId, CancellationToken? cancellationToken = null) =>
_client.Post<object>("files.comments.delete", new Args
_client.Post("files.comments.delete", new Args
{
{ "file", fileId },
{ "id", commentId }
Expand Down
2 changes: 1 addition & 1 deletion SlackNet/WebApi/FilesApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public class FilesApi : IFilesApi
/// <param name="fileId">ID of file to delete.</param>
/// <param name="cancellationToken"></param>
public Task Delete(string fileId, CancellationToken? cancellationToken = null) =>
_client.Post<object>("files.delete", new Args { { "file", fileId } }, cancellationToken);
_client.Post("files.delete", new Args { { "file", fileId } }, cancellationToken);

/// <summary>
/// Returns information about a file in your team.
Expand Down
12 changes: 6 additions & 6 deletions SlackNet/WebApi/GroupsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public class GroupsApi : IGroupsApi
/// <param name="channelId">Private channel to archive.</param>
/// <param name="cancellationToken"></param>
public Task Archive(string channelId, CancellationToken? cancellationToken = null) =>
_client.Post<object>("groups.archive", new Args { { "channel", channelId } }, cancellationToken);
_client.Post("groups.archive", new Args { { "channel", channelId } }, cancellationToken);

/// <summary>
/// Closes a private channel.
Expand Down Expand Up @@ -270,7 +270,7 @@ public async Task<Channel> Invite(string channelId, string userId, CancellationT
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task Kick(string channelId, string userId, CancellationToken? cancellationToken = null) =>
_client.Post<object>("groups.kick", new Args
_client.Post("groups.kick", new Args
{
{ "channel", channelId },
{ "user", userId }
Expand All @@ -282,7 +282,7 @@ public Task Kick(string channelId, string userId, CancellationToken? cancellatio
/// <param name="channelId">Private channel to leave.</param>
/// <param name="cancellationToken"></param>
public Task Leave(string channelId, CancellationToken? cancellationToken = null) =>
_client.Post<object>("groups.leave", new Args { { "channel", channelId } }, cancellationToken);
_client.Post("groups.leave", new Args { { "channel", channelId } }, cancellationToken);

/// <summary>
/// Returns a list of private channels in the team that the caller is in and archived groups that the caller was in.
Expand All @@ -300,7 +300,7 @@ public async Task<IReadOnlyList<Channel>> List(bool excludeArchived = false, Can
/// <param name="ts">Timestamp of the most recently seen message.</param>
/// <param name="cancellationToken"></param>
public Task Mark(string channelId, string ts, CancellationToken? cancellationToken = null) =>
_client.Post<object>("groups.mark", new Args { { "channel", channelId }, { "ts", ts } }, cancellationToken);
_client.Post("groups.mark", new Args { { "channel", channelId }, { "ts", ts } }, cancellationToken);

/// <summary>
/// Opens a private channel.
Expand All @@ -309,7 +309,7 @@ public Task Mark(string channelId, string ts, CancellationToken? cancellationTok
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task Open(string channelId, CancellationToken? cancellationToken = null) =>
_client.Post<object>("groups.open", new Args { { "channel", channelId } }, cancellationToken);
_client.Post("groups.open", new Args { { "channel", channelId } }, cancellationToken);

/// <summary>
/// Renames a private channel.
Expand Down Expand Up @@ -377,6 +377,6 @@ public async Task<string> SetTopic(string channelId, string topic, CancellationT
/// <param name="channelId">Private channel to unarchive.</param>
/// <param name="cancellationToken"></param>
public Task Unarchive(string channelId, CancellationToken? cancellationToken = null) =>
_client.Post<object>("groups.unarchive", new Args { { "channel", channelId } }, cancellationToken);
_client.Post("groups.unarchive", new Args { { "channel", channelId } }, cancellationToken);
}
}
4 changes: 2 additions & 2 deletions SlackNet/WebApi/ImApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class ImApi : IImApi
/// <param name="channelId">Direct message channel to close.</param>
/// <param name="cancellationToken"></param>
public Task Close(string channelId, CancellationToken? cancellationToken = null) =>
_client.Post<object>("im.close", new Args { { "channel", channelId } }, cancellationToken);
_client.Post("im.close", new Args { { "channel", channelId } }, cancellationToken);

/// <summary>
/// Returns a portion of message events from the specified direct message channel.
Expand Down Expand Up @@ -129,7 +129,7 @@ public async Task<IReadOnlyList<Im>> List(CancellationToken? cancellationToken =
/// <param name="ts">Timestamp of the most recently seen message.</param>
/// <param name="cancellationToken"></param>
public Task Mark(string channelId, string ts, CancellationToken? cancellationToken = null) =>
_client.Post<object>("im.mark", new Args
_client.Post("im.mark", new Args
{
{ "channel", channelId },
{ "ts", ts }
Expand Down
4 changes: 2 additions & 2 deletions SlackNet/WebApi/MpimApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class MpimApi : IMpimApi
/// <param name="channelId">MPIM to close.</param>
/// <param name="cancellationToken"></param>
public Task Close(string channelId, CancellationToken? cancellationToken = null) =>
_client.Post<object>("mpim.close", new Args { { "channel", channelId } }, cancellationToken);
_client.Post("mpim.close", new Args { { "channel", channelId } }, cancellationToken);

/// <summary>
/// Returns a portion of message events from the specified multiparty direct message channel.
Expand Down Expand Up @@ -128,7 +128,7 @@ public async Task<IReadOnlyList<Channel>> List(CancellationToken? cancellationTo
/// <param name="ts">Timestamp of the most recently seen message.</param>
/// <param name="cancellationToken"></param>
public Task Mark(string channelId, string ts, CancellationToken? cancellationToken = null) =>
_client.Post<object>("mpim.mark", new Args
_client.Post("mpim.mark", new Args
{
{ "channel", channelId },
{ "ts", ts }
Expand Down
Loading

0 comments on commit 2138473

Please sign in to comment.