Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cursor-based pagination to team.accessLogs API calls #1160

Merged
merged 1 commit into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion json-logs/samples/api/team.accessLogs.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
},
"error": "",
"needed": "",
"provided": ""
"provided": "",
"response_metadata": {
"next_cursor": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2286,6 +2286,8 @@ public static FormBody.Builder toForm(TeamAccessLogsRequest req) {
setIfNotNull("count", req.getCount(), form);
setIfNotNull("page", req.getPage(), form);
setIfNotNull("team_id", req.getTeamId(), form);
setIfNotNull("limit", req.getLimit(), form);
setIfNotNull("cursor", req.getCursor(), form);
return form;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,18 @@ public class TeamAccessLogsRequest implements SlackApiRequest {
*/
private String teamId;

/**
* The maximum number of items to return. Fewer than the requested number of items may be returned,
* even if the end of the list hasn't been reached.
* If specified, result is returned using a cursor-based approach instead of a classic one.
*/
private Integer limit;

/**
* Parameter for pagination. Set cursor equal to the next_cursor attribute returned
* by the previous request's response_metadata. This parameter is optional,
* but pagination is mandatory: the default value simply fetches the first "page" of the collection.
*/
private String cursor;

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.slack.api.methods.SlackApiTextResponse;
import com.slack.api.model.Login;
import com.slack.api.model.Paging;
import com.slack.api.model.ResponseMetadata;
import lombok.Data;

import java.util.List;
Expand All @@ -20,4 +21,5 @@ public class TeamAccessLogsResponse implements SlackApiTextResponse {

private List<Login> logins;
private Paging paging;
private ResponseMetadata responseMetadata;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

import java.util.List;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;

@Slf4j
Expand Down Expand Up @@ -54,6 +53,29 @@ public void teamAccessLogs() throws Exception {
}
}

@Test
public void teamAccessLogs_cursor() throws Exception {
TeamAccessLogsResponse error = slack.methods(userToken).teamAccessLogs(r -> r.cursor("xxxx"));
assertThat(error.getError(), is(notNullValue()));

TeamAccessLogsResponse response = slack.methods(userToken).teamAccessLogs(r -> r.limit(1));
if (response.isOk()) {
// when you pay for this team
assertThat(response.getError(), is(nullValue()));
assertThat(response.isOk(), is(true));

String nextCursor = response.getResponseMetadata().getNextCursor();
response = slack.methods(userToken).teamAccessLogs(r -> r.limit(1).cursor(nextCursor));
assertThat(response.getError(), is(nullValue()));
assertThat(response.isOk(), is(true));
assertThat(response.getResponseMetadata().getNextCursor(), is(not(equals(nextCursor))));
} else {
// when you don't pay for this team
assertThat(response.isOk(), is(false));
assertThat(response.getError(), is("paid_only"));
}
}

@Test
public void teamAccessLogs_async() throws Exception {
TeamAccessLogsResponse response = slack.methodsAsync().teamAccessLogs(r -> r.token(userToken)).get();
Expand Down