Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
* origin/develop:
  Add deleting all permissions method
  delete v1.0 compatibility
  Add method signature for specific user_id to getTaggableFriends()
  prepare 2.3.1
  • Loading branch information
roundrop committed Oct 26, 2015
2 parents c326e54 + 3f6938b commit 8806766
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 239 deletions.
25 changes: 23 additions & 2 deletions facebook4j-core/src/main/java/facebook4j/FacebookImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -897,10 +897,13 @@ public ResponseList<Friend> getFriends(String userId, Reading reading) throws Fa
public ResponseList<TaggableFriend> getTaggableFriends() throws FacebookException {
return getTaggableFriends("me", null);
}
public ResponseList<TaggableFriend> getTaggableFriends(Reading reading) throws FacebookException {
public ResponseList<TaggableFriend> getTaggableFriends(Reading reading) throws FacebookException {
return getTaggableFriends("me", reading);
}
public ResponseList<TaggableFriend> getTaggableFriends(String userId, Reading reading) throws FacebookException {
public ResponseList<TaggableFriend> getTaggableFriends(String userId) throws FacebookException {
return getTaggableFriends(userId, null);
}
public ResponseList<TaggableFriend> getTaggableFriends(String userId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createTaggableFriendList(get(buildEndpoint(userId, "taggable_friends", reading)));
}
Expand Down Expand Up @@ -1802,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 @@ -1811,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
2 changes: 1 addition & 1 deletion facebook4j-core/src/main/java/facebook4j/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @author Ryuji Yamashita - roundrop at gmail.com
*/
public final class Version {
private static final String VERSION = "2.3.0";
private static final String VERSION = "2.3.1";
private static final String TITLE = "Facebook4J";

private Version() {
Expand Down
18 changes: 18 additions & 0 deletions facebook4j-core/src/main/java/facebook4j/api/FriendMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,5 +325,23 @@ public interface FriendMethods {
*/
ResponseList<TaggableFriend> getTaggableFriends(Reading reading) throws FacebookException;

/**
* Returns the list of friends of the current user.
* @param userId the ID of a user
* @return taggable friend's list
* @throws FacebookException when Facebook service or network is unavailable, and when taggable friends feature requires app review
* @see <a href="https://developers.facebook.com/docs/graph-api/reference/user/taggable_friends">User#taggablefriends - Facebook Developers</a>
*/
ResponseList<TaggableFriend> getTaggableFriends(String userId) throws FacebookException;

/**
* Returns the list of friends of the current user.
* @param userId the ID of a user
* @param reading optional reading parameters. see <a href="https://developers.facebook.com/docs/reference/api/#reading">Graph API#reading - Facebook Developers</a>
* @return taggable friend's list
* @throws FacebookException when Facebook service or network is unavailable,and when taggable friends feature requires app review
* @see <a href="https://developers.facebook.com/docs/graph-api/reference/user/taggable_friends">User#taggablefriends - Facebook Developers</a>
*/
ResponseList<TaggableFriend> getTaggableFriends(String userId, Reading reading) throws FacebookException;

}
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 @@ -26,11 +26,8 @@
import facebook4j.internal.org.json.JSONObject;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import static facebook4j.internal.util.z_F4JInternalParseUtil.*;

/**
* @author Ryuji Yamashita - roundrop at gmail.com
*/
Expand Down Expand Up @@ -64,18 +61,9 @@ static List<Permission> createPermissionArray(HttpResponse res, Configuration co
JSONArray list = json.getJSONArray("data");
for (int i = 0; i < list.length(); i++) {
JSONObject permissionJSONObject = list.getJSONObject(i);
if (permissionJSONObject.has("permission") && permissionJSONObject.has("status")) {
String permissionName = permissionJSONObject.getString("permission");
boolean isGranted = "granted".equalsIgnoreCase(permissionJSONObject.getString("status"));
permissions.add(new PermissionJSONImpl(permissionName, isGranted));
} else {
Iterator<String> permissionNames = permissionJSONObject.keys();
while (permissionNames.hasNext()) {
String permissionName = permissionNames.next();
boolean isGranted = getFlag(permissionName, permissionJSONObject);
permissions.add(new PermissionJSONImpl(permissionName, isGranted));
}
}
String permissionName = permissionJSONObject.getString("permission");
boolean isGranted = "granted".equalsIgnoreCase(permissionJSONObject.getString("status"));
permissions.add(new PermissionJSONImpl(permissionName, isGranted));
}
if (conf.isJSONStoreEnabled()) {
DataObjectFactoryUtil.registerJSONObject(permissions, list);
Expand Down
120 changes: 79 additions & 41 deletions facebook4j-core/src/test/java/facebook4j/FriendMethodsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,47 +111,6 @@ public void id_reading() throws Exception {
}
}

public static class getTaggableFriends extends MockFacebookTestBase {
@Test
public void me() throws Exception {
facebook.setMockJSON("mock_json/friend/taggable_friends.json");
ResponseList<TaggableFriend> actuals = facebook.getTaggableFriends();
assertThat(facebook.getHttpMethod(), is(RequestMethod.GET));
assertThat(facebook.getEndpointURL(), is(pathOf("/me/taggable_friends")));

assertThat(actuals.size(), is(2));
TaggableFriend actual1 = actuals.get(0);
assertThat(actual1.getToken(), is("AaLml5U5tssCqmaVxDfaID0JWQW_cmloE_iD0UQ1ALz4g-bdAqgY0sqDIsdfastzr-yewJhYuuT7W0Mm-YEEq8n1aG9lAeAfmvA9cq-B9Hg"));
assertThat(actual1.getName(), is("Friend One"));
TaggableFriend actual5 = actuals.get(1);
assertThat(actual5.getToken(), is("AaJ73QgEXPUlrEb6XNob5B6S_Xl2qeCCpj5parsRlvmFkXs7SOq5hPEcIt8Enw37MasfmLxnJ0i1RGRrspiPjhb_KXDQbzKW68Tg"));
assertThat(actual5.getName(), is("Friend Two"));
}

@Test
public void me_reading() throws Exception {
facebook.setMockJSON("mock_json/friend/taggable_friends.json");
ResponseList<TaggableFriend> actuals = facebook.getTaggableFriends(new Reading().fields("name").fields("picture.type(large)").limit(2));
assertThat(facebook.getHttpMethod(), is(RequestMethod.GET));
assertThat(facebook.getEndpointURL(), is(pathOf("/me/taggable_friends")));
assertThat(facebook.getEndpointURL(), hasParameter("fields", "name,picture.type(large)"));
assertThat(facebook.getEndpointURL(), hasParameter("limit", "2"));

assertThat(actuals.size(), is(2));
TaggableFriend actual1 = actuals.get(0);
assertThat(actual1.getToken(), is("AaLml5U5tssCqmaVxDfaID0JWQW_cmloE_iD0UQ1ALz4g-bdAqgY0sqDIsdfastzr-yewJhYuuT7W0Mm-YEEq8n1aG9lAeAfmvA9cq-B9Hg"));
assertThat(actual1.getName(), is("Friend One"));
assertThat(actual1.getPicture().getURL().toString(), is("https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpa1/v/t1.0-1/p50x50/1532100_61720120769_7344809391293777_n.jpg"));
assertThat(actual1.getPicture().isSilhouette(), is(false));
TaggableFriend actual3 = actuals.get(1);
assertThat(actual3.getToken(), is("AaJ73QgEXPUlrEb6XNob5B6S_Xl2qeCCpj5parsRlvmFkXs7SOq5hPEcIt8Enw37MasfmLxnJ0i1RGRrspiPjhb_KXDQbzKW68Tg"));
assertThat(actual3.getName(), is("Friend Two"));
assertThat(actual3.getPicture().getURL().toString(), is("https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xaf1/v/t1.0-1/c51.50.611.119/s50x50/3146305_1015111258096607_1858078876_n.jpg"));
assertThat(actual3.getPicture().isSilhouette(), is(false));
}

}

public static class getBelongsFriend extends MockFacebookTestBase {
@Test
public void me() throws Exception {
Expand Down Expand Up @@ -609,4 +568,83 @@ public void id_reading() throws Exception {
}
}

public static class getTaggableFriends extends MockFacebookTestBase {
@Test
public void me() throws Exception {
facebook.setMockJSON("mock_json/friend/taggable_friends.json");
ResponseList<TaggableFriend> actuals = facebook.getTaggableFriends();
assertThat(facebook.getHttpMethod(), is(RequestMethod.GET));
assertThat(facebook.getEndpointURL(), is(pathOf("/me/taggable_friends")));

assertThat(actuals.size(), is(2));
TaggableFriend actual1 = actuals.get(0);
assertThat(actual1.getToken(), is("AaLml5U5tssCqmaVxDfaID0JWQW_cmloE_iD0UQ1ALz4g-bdAqgY0sqDIsdfastzr-yewJhYuuT7W0Mm-YEEq8n1aG9lAeAfmvA9cq-B9Hg"));
assertThat(actual1.getName(), is("Friend One"));
TaggableFriend actual5 = actuals.get(1);
assertThat(actual5.getToken(), is("AaJ73QgEXPUlrEb6XNob5B6S_Xl2qeCCpj5parsRlvmFkXs7SOq5hPEcIt8Enw37MasfmLxnJ0i1RGRrspiPjhb_KXDQbzKW68Tg"));
assertThat(actual5.getName(), is("Friend Two"));
}

@Test
public void me_reading() throws Exception {
facebook.setMockJSON("mock_json/friend/taggable_friends.json");
ResponseList<TaggableFriend> actuals = facebook.getTaggableFriends(new Reading().fields("name").fields("picture.type(large)").limit(2));
assertThat(facebook.getHttpMethod(), is(RequestMethod.GET));
assertThat(facebook.getEndpointURL(), is(pathOf("/me/taggable_friends")));
assertThat(facebook.getEndpointURL(), hasParameter("fields", "name,picture.type(large)"));
assertThat(facebook.getEndpointURL(), hasParameter("limit", "2"));

assertThat(actuals.size(), is(2));
TaggableFriend actual1 = actuals.get(0);
assertThat(actual1.getToken(), is("AaLml5U5tssCqmaVxDfaID0JWQW_cmloE_iD0UQ1ALz4g-bdAqgY0sqDIsdfastzr-yewJhYuuT7W0Mm-YEEq8n1aG9lAeAfmvA9cq-B9Hg"));
assertThat(actual1.getName(), is("Friend One"));
assertThat(actual1.getPicture().getURL().toString(), is("https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpa1/v/t1.0-1/p50x50/1532100_61720120769_7344809391293777_n.jpg"));
assertThat(actual1.getPicture().isSilhouette(), is(false));
TaggableFriend actual3 = actuals.get(1);
assertThat(actual3.getToken(), is("AaJ73QgEXPUlrEb6XNob5B6S_Xl2qeCCpj5parsRlvmFkXs7SOq5hPEcIt8Enw37MasfmLxnJ0i1RGRrspiPjhb_KXDQbzKW68Tg"));
assertThat(actual3.getName(), is("Friend Two"));
assertThat(actual3.getPicture().getURL().toString(), is("https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xaf1/v/t1.0-1/c51.50.611.119/s50x50/3146305_1015111258096607_1858078876_n.jpg"));
assertThat(actual3.getPicture().isSilhouette(), is(false));
}

@Test
public void id() throws Exception {
facebook.setMockJSON("mock_json/friend/taggable_friends.json");
ResponseList<TaggableFriend> actuals = facebook.getTaggableFriends("1234567890123456");
assertThat(facebook.getHttpMethod(), is(RequestMethod.GET));
assertThat(facebook.getEndpointURL(), is(pathOf("/1234567890123456/taggable_friends")));

assertThat(actuals.size(), is(2));
TaggableFriend actual1 = actuals.get(0);
assertThat(actual1.getToken(), is("AaLml5U5tssCqmaVxDfaID0JWQW_cmloE_iD0UQ1ALz4g-bdAqgY0sqDIsdfastzr-yewJhYuuT7W0Mm-YEEq8n1aG9lAeAfmvA9cq-B9Hg"));
assertThat(actual1.getName(), is("Friend One"));
TaggableFriend actual5 = actuals.get(1);
assertThat(actual5.getToken(), is("AaJ73QgEXPUlrEb6XNob5B6S_Xl2qeCCpj5parsRlvmFkXs7SOq5hPEcIt8Enw37MasfmLxnJ0i1RGRrspiPjhb_KXDQbzKW68Tg"));
assertThat(actual5.getName(), is("Friend Two"));
}

@Test
public void id_reading() throws Exception {
facebook.setMockJSON("mock_json/friend/taggable_friends.json");
ResponseList<TaggableFriend> actuals = facebook.getTaggableFriends("1234567890123456", new Reading().fields("name").fields("picture.type(large)").limit(2));
assertThat(facebook.getHttpMethod(), is(RequestMethod.GET));
assertThat(facebook.getEndpointURL(), is(pathOf("/1234567890123456/taggable_friends")));
assertThat(facebook.getEndpointURL(), hasParameter("fields", "name,picture.type(large)"));
assertThat(facebook.getEndpointURL(), hasParameter("limit", "2"));

assertThat(actuals.size(), is(2));
TaggableFriend actual1 = actuals.get(0);
assertThat(actual1.getToken(), is("AaLml5U5tssCqmaVxDfaID0JWQW_cmloE_iD0UQ1ALz4g-bdAqgY0sqDIsdfastzr-yewJhYuuT7W0Mm-YEEq8n1aG9lAeAfmvA9cq-B9Hg"));
assertThat(actual1.getName(), is("Friend One"));
assertThat(actual1.getPicture().getURL().toString(), is("https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpa1/v/t1.0-1/p50x50/1532100_61720120769_7344809391293777_n.jpg"));
assertThat(actual1.getPicture().isSilhouette(), is(false));
TaggableFriend actual3 = actuals.get(1);
assertThat(actual3.getToken(), is("AaJ73QgEXPUlrEb6XNob5B6S_Xl2qeCCpj5parsRlvmFkXs7SOq5hPEcIt8Enw37MasfmLxnJ0i1RGRrspiPjhb_KXDQbzKW68Tg"));
assertThat(actual3.getName(), is("Friend Two"));
assertThat(actual3.getPicture().getURL().toString(), is("https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xaf1/v/t1.0-1/c51.50.611.119/s50x50/3146305_1015111258096607_1858078876_n.jpg"));
assertThat(actual3.getPicture().isSilhouette(), is(false));
}

}

}
48 changes: 36 additions & 12 deletions facebook4j-core/src/test/java/facebook4j/PermissionMethodsTest.java
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 @@ -54,24 +53,27 @@ public void id() throws Exception {
assertThat(actuals.size(), is(80));
}

@Test
public void me_v2() throws Exception {
facebook.setMockJSON("mock_json/permission/all_v2.2.json");
List<Permission> actuals = facebook.getPermissions();
assertThat(facebook.getHttpMethod(), is(RequestMethod.GET));
}

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(actuals.size(), is(80));
assertThat(actual, is(true));
}

@Test
public void id_v2() throws Exception {
facebook.setMockJSON("mock_json/permission/all_v2.2.json");
List<Permission> actuals = facebook.getPermissions("1234567890123456");
assertThat(facebook.getHttpMethod(), is(RequestMethod.GET));
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(actuals.size(), is(80));
assertThat(actual, is(true));
}
}

Expand Down Expand Up @@ -108,6 +110,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
Loading

0 comments on commit 8806766

Please sign in to comment.