Skip to content

Commit

Permalink
Cursor-based pagination for TeamApi.AccessLogs and FilesApi.List
Browse files Browse the repository at this point in the history
  • Loading branch information
soxtoby committed Jun 3, 2023
1 parent b39a7e7 commit 781ad3e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
9 changes: 8 additions & 1 deletion SlackNet/WebApi/FilesApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public interface IFilesApi
/// <param name="types">Filter files by type.</param>
/// <param name="count">Number of items to return per page.</param>
/// <param name="page">Page number of results to return.</param>
/// <param name="cursor">
/// Parameter for pagination.
/// Set cursor equal to the <see cref="ResponseMetadata.NextCursor"/> returned by the previous request's <see cref="ReactionItemListResponse.ResponseMetadata"/>.
/// </param>
/// <param name="cancellationToken"></param>
Task<FileListResponse> List(
string userId = null,
Expand All @@ -52,6 +56,7 @@ Task<FileListResponse> List(
IEnumerable<FileType> types = null,
int count = 100,
int page = 1,
string cursor = null,
CancellationToken? cancellationToken = null
);

Expand Down Expand Up @@ -191,6 +196,7 @@ public Task<FileListResponse> List(
IEnumerable<FileType> types = null,
int count = 100,
int page = 1,
string cursor = null,
CancellationToken? cancellationToken = null
) =>
_client.Get<FileListResponse>("files.list", new Args
Expand All @@ -201,7 +207,8 @@ public Task<FileListResponse> List(
{ "ts_to", tsTo },
{ "types", types },
{ "count", count },
{ "page", page }
{ "page", page },
{ "cursor", cursor }
}, cancellationToken);

public Task<FileResponse> RevokePublicUrl(string fileId, CancellationToken? cancellationToken = null) =>
Expand Down
1 change: 1 addition & 0 deletions SlackNet/WebApi/Responses/AccessLogsResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public class AccessLogsResponse
{
public IList<Login> Logins { get; set; } = new List<Login>();
public Paging Paging { get; set; }
public ResponseMetadata ResponseMetadata { get; set; } = new();
}
22 changes: 16 additions & 6 deletions SlackNet/WebApi/TeamApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ public interface ITeamApi
/// <param name="before">End of time range of logs to include in results (inclusive).</param>
/// <param name="count">Number of items to return per page.</param>
/// <param name="page">Page number of results to return.</param>
/// <param name="cursor">
/// Parameter for pagination.
/// Set cursor equal to the <see cref="ResponseMetadata.NextCursor"/> returned by the previous request's <see cref="ReactionItemListResponse.ResponseMetadata"/>.
/// </param>
/// <param name="cancellationToken"></param>
Task<AccessLogsResponse> AccessLogs(DateTime before, int count = 100, int page = 1, CancellationToken? cancellationToken = null);
Task<AccessLogsResponse> AccessLogs(DateTime before, int count = 100, int page = 1, string cursor = null, CancellationToken? cancellationToken = null);

/// <summary>
/// Used to get the access logs for users on a team.
Expand All @@ -25,8 +29,12 @@ public interface ITeamApi
/// <param name="before">End of time range of logs to include in results (inclusive).</param>
/// <param name="count">Number of items to return per page.</param>
/// <param name="page">Page number of results to return.</param>
/// <param name="cursor">
/// Parameter for pagination.
/// Set cursor equal to the <see cref="ResponseMetadata.NextCursor"/> returned by the previous request's <see cref="ReactionItemListResponse.ResponseMetadata"/>.
/// </param>
/// <param name="cancellationToken"></param>
Task<AccessLogsResponse> AccessLogs(int? before = null, int count = 100, int page = 1, CancellationToken? cancellationToken = null);
Task<AccessLogsResponse> AccessLogs(int? before = null, int count = 100, int page = 1, string cursor = null, CancellationToken? cancellationToken = null);

/// <summary>
/// Lists billable information for each user on the team.
Expand Down Expand Up @@ -72,20 +80,22 @@ public class TeamApi : ITeamApi
private readonly ISlackApiClient _client;
public TeamApi(ISlackApiClient client) => _client = client;

public Task<AccessLogsResponse> AccessLogs(DateTime before, int count = 100, int page = 1, CancellationToken? cancellationToken = null) =>
public Task<AccessLogsResponse> AccessLogs(DateTime before, int count = 100, int page = 1, string cursor = null, CancellationToken? cancellationToken = null) =>
_client.Get<AccessLogsResponse>("team.accessLogs", new Args
{
{ "before", before.ToTimestamp() },
{ "count", count },
{ "page", page }
{ "page", page },
{ "cursor", cursor }
}, cancellationToken);

public Task<AccessLogsResponse> AccessLogs(int? before = null, int count = 100, int page = 1, CancellationToken? cancellationToken = null) =>
public Task<AccessLogsResponse> AccessLogs(int? before = null, int count = 100, int page = 1, string cursor = null, CancellationToken? cancellationToken = null) =>
_client.Get<AccessLogsResponse>("team.accessLogs", new Args
{
{ "before", before },
{ "count", count },
{ "page", page }
{ "page", page },
{ "cursor", cursor }
}, cancellationToken);

public async Task<IList<BillableInfo>> BillableInfo(string userId = null, CancellationToken? cancellationToken = null) =>
Expand Down

0 comments on commit 781ad3e

Please sign in to comment.