Skip to content

Commit

Permalink
Adding cursor-based paging to new methods that support it
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Oxtoby committed Jul 12, 2020
1 parent d693f6c commit 35786f6
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 24 deletions.
11 changes: 8 additions & 3 deletions SlackNet/WebApi/FilesApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ public interface IFilesApi
/// <param name="fileId">Specify a file by providing its ID.</param>
/// <param name="count">Number of comments to return per page.</param>
/// <param name="page">Page number of comments to return.</param>
/// <param name="cursor">
/// Parameter for pagination. File comments are paginated for a single file.
/// Set cursor equal to the <see cref="ResponseMetadata.NextCursor"/> returned by the previous request's <see cref="FileAndCommentsResponse.ResponseMetadata"/>.
/// </param>
/// <param name="cancellationToken"></param>
Task<FileAndCommentsResponse> Info(string fileId, int count = 100, int page = 1, CancellationToken? cancellationToken = null);
Task<FileAndCommentsResponse> Info(string fileId, int count = 100, int page = 1, string cursor = null, CancellationToken? cancellationToken = null);

/// <summary>
/// Returns a list of files within the team. It can be filtered and sliced in various ways.
Expand Down Expand Up @@ -173,12 +177,13 @@ public Task Delete(string fileId, CancellationToken? cancellationToken = null) =
/// <param name="count">Number of comments to return per page.</param>
/// <param name="page">Page number of comments to return.</param>
/// <param name="cancellationToken"></param>
public Task<FileAndCommentsResponse> Info(string fileId, int count = 100, int page = 1, CancellationToken? cancellationToken = null) =>
public Task<FileAndCommentsResponse> Info(string fileId, int count = 100, int page = 1, string cursor = null, CancellationToken? cancellationToken = null) =>
_client.Get<FileAndCommentsResponse>("files.info", new Args
{
{ "file", fileId },
{ "count", count },
{ "page", page }
{ "page", page },
{ "cursor", cursor }
}, cancellationToken);

/// <summary>
Expand Down
15 changes: 12 additions & 3 deletions SlackNet/WebApi/ReactionsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ public interface IReactionsApi
/// <param name="full">If true always return the complete reaction list.</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<ReactionItemListResponse> List(string userId = null, bool full = false, int count = 100, int page = 1, CancellationToken? cancellationToken = null);
Task<ReactionItemListResponse> List(string userId = null, bool full = false, int count = 100, int page = 1, string cursor = null, CancellationToken? cancellationToken = null);

/// <summary>
/// Removes a reaction (emoji) from a file.
Expand Down Expand Up @@ -148,14 +152,19 @@ public async Task<MessageEvent> GetForMessage(string channelId, string ts, bool
/// <param name="full">If true always return the complete reaction list.</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>
public Task<ReactionItemListResponse> List(string userId = null, bool full = false, int count = 100, int page = 1, CancellationToken? cancellationToken = null) =>
public Task<ReactionItemListResponse> List(string userId = null, bool full = false, int count = 100, int page = 1, string cursor = null, CancellationToken? cancellationToken = null) =>
_client.Get<ReactionItemListResponse>("reactions.list", new Args
{
{ "user", userId },
{ "full", full },
{ "count", count },
{ "page", page }
{ "page", page },
{ "cursor", cursor }
}, cancellationToken);

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions SlackNet/WebApi/Responses/ConversationListResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace SlackNet.WebApi
{
public class ConversationListResponse
{
public IList<Conversation> Channels { get; set; }
public ResponseMetadata ResponseMetadata { get; set; }
public IList<Conversation> Channels { get; set; } = new List<Conversation>();
public ResponseMetadata ResponseMetadata { get; set; } = new ResponseMetadata();
}
}
2 changes: 1 addition & 1 deletion SlackNet/WebApi/Responses/ConversationMembersResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace SlackNet.WebApi
public class ConversationMembersResponse
{
public IList<string> Members { get; set; } = new List<string>();
public ResponseMetadata ResponseMetadata { get; set; }
public ResponseMetadata ResponseMetadata { get; set; } = new ResponseMetadata();
}
}
2 changes: 1 addition & 1 deletion SlackNet/WebApi/Responses/ConversationMessagesResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public class ConversationMessagesResponse
{
public IList<MessageEvent> Messages { get; set; } = new List<MessageEvent>();
public bool HasMore { get; set; }
public ResponseMetadata ResponseMetadata { get; set; }
public ResponseMetadata ResponseMetadata { get; set; } = new ResponseMetadata();
}
}
3 changes: 2 additions & 1 deletion SlackNet/WebApi/Responses/FileAndCommentsResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace SlackNet.WebApi
public class FileAndCommentsResponse : FileResponse
{
public IList<FileComment> Comments { get; set; } = new List<FileComment>();
public Paging Paging { get; set; }
public Paging Paging { get; set; } = new Paging();
public ResponseMetadata ResponseMetadata { get; set; } = new ResponseMetadata();
}
}
4 changes: 2 additions & 2 deletions SlackNet/WebApi/Responses/FileListResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace SlackNet.WebApi
public class FileListResponse
{
public IList<File> Files { get; set; } = new List<File>();
public Paging Paging { get; set; }
public ResponseMetadata ResponseMetadata { get; set; }
public Paging Paging { get; set; } = new Paging();
public ResponseMetadata ResponseMetadata { get; set; } = new ResponseMetadata();
}
}
5 changes: 3 additions & 2 deletions SlackNet/WebApi/Responses/ReactionItemListResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ namespace SlackNet.WebApi
{
public class ReactionItemListResponse
{
public IList<ReactionItem> Items { get; set; }
public Paging Paging { get; set; }
public IList<ReactionItem> Items { get; set; } = new List<ReactionItem>();
public Paging Paging { get; set; } = new Paging();
public ResponseMetadata ResponseMetadata { get; set; } = new ResponseMetadata();
}
}
2 changes: 1 addition & 1 deletion SlackNet/WebApi/Responses/ScheduledMessageListResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace SlackNet.WebApi
public class ScheduledMessageListResponse
{
public IList<ScheduledMessage> ScheduledMessages { get; set; } = new List<ScheduledMessage>();
public ResponseMetadata ResponseMetadata { get; set; }
public ResponseMetadata ResponseMetadata { get; set; } = new ResponseMetadata();
}

public class ScheduledMessage
Expand Down
5 changes: 3 additions & 2 deletions SlackNet/WebApi/Responses/StarListResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ namespace SlackNet.WebApi
{
public class StarListResponse
{
public IList<StarredItem> Items { get; set; }
public Paging Paging { get; set; }
public IList<StarredItem> Items { get; set; } = new List<StarredItem>();
public Paging Paging { get; set; } = new Paging();
public ResponseMetadata ResponseMetadata { get; set; } = new ResponseMetadata();
}
}
2 changes: 1 addition & 1 deletion SlackNet/WebApi/Responses/UserListResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public class UserListResponse
public int CacheTs { get; set; }
[JsonIgnore]
public DateTime CacheTime => CacheTs.ToDateTime().GetValueOrDefault();
public ResponseMetadata ResponseMetadata { get; set; }
public ResponseMetadata ResponseMetadata { get; set; } = new ResponseMetadata();
}
}
17 changes: 12 additions & 5 deletions SlackNet/WebApi/StarsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ public interface IStarsApi
/// </summary>
/// <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="StarListResponse.ResponseMetadata"/>.
/// </param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<StarListResponse> List(int count = 100, int page = 1, CancellationToken? cancellationToken = null);
Task<StarListResponse> List(int count = 100, int page = 1, string cursor = null, CancellationToken? cancellationToken = null);

/// <summary>
/// Removes a star from a file.
Expand Down Expand Up @@ -121,13 +124,17 @@ public Task AddToMessage(string channelId, string ts, CancellationToken? cancell
/// </summary>
/// <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="StarListResponse.ResponseMetadata"/>.
/// </param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<StarListResponse> List(int count = 100, int page = 1, CancellationToken? cancellationToken = null) =>
public Task<StarListResponse> List(int count = 100, int page = 1, string cursor = null, CancellationToken? cancellationToken = null) =>
_client.Get<StarListResponse>("stars.list", new Args
{
{ "count", count },
{ "page", page }
{ "page", page },
{ "cursor", cursor }
}, cancellationToken);

/// <summary>
Expand Down

0 comments on commit 35786f6

Please sign in to comment.