Skip to content

Commit

Permalink
Add deleting all permissions method
Browse files Browse the repository at this point in the history
  • Loading branch information
roundrop committed Oct 21, 2015
1 parent 5c3d791 commit 08cf41a
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 1 deletion.
18 changes: 18 additions & 0 deletions facebook4j-core/src/main/java/facebook4j/FacebookImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1805,6 +1805,16 @@ public List<Permission> getPermissions(String userId) throws FacebookException {
return factory.createPermissions(get(buildEndpoint(userId, "permissions")));
}

public boolean revokeAllPermissions() throws FacebookException {
return revokeAllPermissions("me");
}

public boolean revokeAllPermissions(String userId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = delete(buildEndpoint(userId, "permissions"));
return parseBoolean(res);
}

public boolean revokePermission(String permissionName) throws FacebookException {
return revokePermission("me", permissionName);
}
Expand All @@ -1814,6 +1824,14 @@ public boolean revokePermission(String userId, String permissionName) throws Fac
return parseBoolean(res);
}

public boolean deleteAllPermissions() throws FacebookException {
return revokeAllPermissions();
}

public boolean deleteAllPermissions(String userId) throws FacebookException {
return revokeAllPermissions(userId);
}

public boolean deletePermission(String permissionName) throws FacebookException {
return revokePermission(permissionName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ public interface PermissionMethods {
List<Permission> getPermissions(String userId) throws FacebookException;


/**
* Revokes all permissions from the current application.
* @return true if revoke is succressful
* @throws FacebookException when Facebook service or network is unavailable
* @see <a href="https://developers.facebook.com/docs/reference/api/user/#permissions">User#permissions - Facebook Developers</a>
*/
boolean revokeAllPermissions() throws FacebookException;

/**
* Revokes all permissions from the current application.
* @param userId the ID of a user
* @return true if revoke is succressful
* @throws FacebookException when Facebook service or network is unavailable
* @see <a href="https://developers.facebook.com/docs/reference/api/user/#permissions">User#permissions - Facebook Developers</a>
*/
boolean revokeAllPermissions(String userId) throws FacebookException;

/**
* Revokes a specific permission from the current application.
* @param permissionName permission name
Expand All @@ -62,6 +79,23 @@ public interface PermissionMethods {
*/
boolean revokePermission(String userId, String permissionName) throws FacebookException;

/**
* This method is an alias of: {@link facebook4j.api.PermissionMethods#revokeAllPermissions()} .
* @return true if revoke is succressful
* @throws FacebookException when Facebook service or network is unavailable
* @see <a href="https://developers.facebook.com/docs/reference/api/user/#permissions">User#permissions - Facebook Developers</a>
*/
boolean deleteAllPermissions() throws FacebookException;

/**
* This method is an alias of: {@link facebook4j.api.PermissionMethods#revokeAllPermissions()} .
* @param userId the ID of a user
* @return true if revoke is succressful
* @throws FacebookException when Facebook service or network is unavailable
* @see <a href="https://developers.facebook.com/docs/reference/api/user/#permissions">User#permissions - Facebook Developers</a>
*/
boolean deleteAllPermissions(String userId) throws FacebookException;

/**
* This method is an alias of: {@link facebook4j.api.PermissionMethods#revokePermission(String)} .
* @param permissionName permission name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package facebook4j;

import facebook4j.internal.http.RequestMethod;

import facebook4j.junit.FacebookAPIVersion;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
Expand Down Expand Up @@ -75,6 +74,28 @@ public void id_v2() throws Exception {
}
}

public static class revokeAllPermission extends MockFacebookTestBase {
@Test
public void me() throws Exception {
facebook.setMockJSON("mock_json/success.json");
boolean actual = facebook.revokeAllPermissions();
assertThat(facebook.getHttpMethod(), is(RequestMethod.DELETE));
assertThat(facebook.getEndpointURL(), is(pathOf("/me/permissions")));

assertThat(actual, is(true));
}

@Test
public void id() throws Exception {
facebook.setMockJSON("mock_json/success.json");
boolean actual = facebook.revokeAllPermissions("1234567890123456");
assertThat(facebook.getHttpMethod(), is(RequestMethod.DELETE));
assertThat(facebook.getEndpointURL(), is(pathOf("/1234567890123456/permissions")));

assertThat(actual, is(true));
}
}

public static class revokePermission extends MockFacebookTestBase {
@Test
public void me() throws Exception {
Expand Down Expand Up @@ -108,6 +129,28 @@ public void id_v23() throws Exception {
}
}

public static class deleteAllPermission extends MockFacebookTestBase {
@Test
public void me() throws Exception {
facebook.setMockJSON("mock_json/success.json");
boolean actual = facebook.deleteAllPermissions();
assertThat(facebook.getHttpMethod(), is(RequestMethod.DELETE));
assertThat(facebook.getEndpointURL(), is(pathOf("/me/permissions")));

assertThat(actual, is(true));
}

@Test
public void id() throws Exception {
facebook.setMockJSON("mock_json/success.json");
boolean actual = facebook.deleteAllPermissions("1234567890123456");
assertThat(facebook.getHttpMethod(), is(RequestMethod.DELETE));
assertThat(facebook.getEndpointURL(), is(pathOf("/1234567890123456/permissions")));

assertThat(actual, is(true));
}
}

public static class deletePermission extends MockFacebookTestBase {
@Test
public void me() throws Exception {
Expand Down

0 comments on commit 08cf41a

Please sign in to comment.