Skip to content

Commit

Permalink
Adding WithToken to ISlackApiClient for using a different access token
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Oxtoby committed May 4, 2020
1 parent 355a95c commit 41b7213
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions SlackNet.Tests/ApiLintTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ public Task Respond(string responseUrl, IReadOnlyMessage message, CancellationTo
throw new NotImplementedException();
}

public ISlackApiClient WithAccessToken(string accessToken)
{
throw new NotImplementedException();
}

public IApiApi Api { get; }
public IAuthApi Auth { get; }
public IBotsApi Bots { get; }
Expand Down
14 changes: 14 additions & 0 deletions SlackNet/SlackApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ public interface ISlackApiClient
/// <param name="message">The message to respond with.</param>
/// <param name="cancellationToken"></param>
Task Respond(string responseUrl, IReadOnlyMessage message, CancellationToken? cancellationToken);

/// <summary>
/// Returns a copy of the client using a different access token.
/// Useful when you need to run a command as a specific user.
/// </summary>
/// <param name="accessToken">New access token.</param>
ISlackApiClient WithAccessToken(string accessToken);
}

public class SlackApiClient : ISlackApiClient
Expand All @@ -130,6 +137,13 @@ public SlackApiClient(IHttp http, ISlackUrlBuilder urlBuilder, SlackJsonSettings
_token = token;
}

/// <summary>
/// Returns a copy of the client using a different access token.
/// Useful when you need to run a command as a specific user.
/// </summary>
/// <param name="accessToken">New access token.</param>
public ISlackApiClient WithAccessToken(string accessToken) => new SlackApiClient(_http, _urlBuilder, _jsonSettings, accessToken);

public IApiApi Api => new ApiApi(this);
public IAuthApi Auth => new AuthApi(this);
public IBotsApi Bots => new BotsApi(this);
Expand Down

0 comments on commit 41b7213

Please sign in to comment.