Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
194 lines (139 sloc) 6.76 KB

Groups

Groups are sets of users that can be used in collaborations.

Get All Groups

Calling the static getAllGroups(BoxAPIConnection api) will return an iterable that will page through all of the user's groups.

Iterable<BoxGroup.Info> groups = BoxGroup.getAllGroups(api);
for (BoxGroup.Info groupInfo : groups) {
    // Do something with the group.
}

Create a Group

The static createGroup(BoxAPIConnection api, String name) method will let you create a new group with a specified name.

BoxGroup.Info groupInfo = BoxGroup.createGroup(api, "My Group");

Get Information About a Group

To look up the information about a group by the group's ID, instantiate the BoxGroup object with the group ID and then call getInfo() on the group. You can optionally call getInfo(String... fields) to specify the list of fields to retrieve for the group, which can result in reduced payload size.

String groupID = "92875";
BoxGroup.Info groupInfo = new BoxGroup(api, groupID).getInfo();

Update a Group

To update a group, call updateInfo(BoxGroup.Info fieldsToUpdate) method.

BoxGroup group = new BoxGroup(api, id);
BoxGroup.Info groupInfo = group.getInfo();
groupInfo.addPendingChange("name", "New name for My Group");
group.updateInfo(groupInfo);

Delete a Group

A group can be deleted by calling the delete() method.

BoxGroup group = new BoxGroup(api, "id");
group.delete();

Get a Groups collaborations

A groups collaborations can be retrieved by calling the getCollaborations() method.

BoxGroup group = new BoxGroup(api, "id");
group.getCollaborations();

Create Membership

Membership for the group can be created by calling the addMembership(BoxUser user) and addMembership(BoxUser user, BoxGroupMembership.Role role) methods.

BoxGroup group = new BoxGroup(api, "groupID");
BoxUser user = new BoxUser(api, "userID");
BoxGroupMembership.Info groupMembershipInfo = group.addMembership(user);

Get Membership

A groups membership can be retrieved by calling the BoxGroupMembership.getInfo() method.

BoxGroupMembership membership = new BoxGroupMembership(api, id);
BoxGroupMembership.Info groupMembershipInfo = membership.getInfo();

Update Membership

A groups membership can be updated by calling the BoxGroupMembership.updateInfo(BoxGroupMembership.Info fieldsToUpdate) method.

BoxGroupMembership membership = new BoxGroupMembership(api, id);
BoxGroupMembership.Info info = membership.new Info();
info.addPendingChange("role", role);
membership.updateInfo(info);

Delete Membership

A group can be deleted by calling the BoxGroupMembership.delete() method.

BoxGroupMembership membership = new BoxGroupMembership(api, id);
membership.delete();

Get Memberships for Group

Calling the getAllMemberships(String... fields) will return an iterable that will page through all of the group's memberships. Optional parameters can be used to retrieve specific fields of the Group Membership object.

BoxGroup group = new BoxGroup(api, id);
Iterable<BoxGroupMembership.Info> memberships = group.getAllMemberships();
for (BoxGroupMembership.Info membershipInfo : memberships) {
    // Do something with the membership.
}

Get Memberships for User

Calling the BoxUser.getAllMemberships(String... fields) will return an iterable that will page through all of the user's memberships. Optional parameters can be used to retrieve specific fields of the Group Membership object.

BoxUser user = new BoxUser(api, id);
Iterable<BoxGroupMembership.Info> memberships = user.getAllMemberships();
for (BoxGroupMembership.Info membershipInfo : memberships) {
    // Do something with the membership.
}