Skip to content

Commit

Permalink
Merge branch 'release/2.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
roundrop committed Dec 31, 2014
2 parents a4359a3 + d27276b commit beb1165
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 17 deletions.
23 changes: 22 additions & 1 deletion facebook4j-core/src/main/java/facebook4j/FacebookImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,20 @@ public URL getPictureURL(PictureSize size) throws FacebookException {
ensureAuthorizationEnabled();
return getPictureURL("me", size);
}
public URL getPictureURL(int width, int height) throws FacebookException {
ensureAuthorizationEnabled();
return getPictureURL("me", width, height);
}
public URL getPictureURL(String userId) throws FacebookException {
return getPictureURL(userId, null);
}
public URL getPictureURL(String userId, PictureSize size) throws FacebookException {
return _getPictureURL(userId, size);
}

public URL getPictureURL(String userId, int width, int height) throws FacebookException {
return _getPictureURL(userId, width, height);
}

public URL getSSLPictureURL() throws FacebookException {
ensureAuthorizationEnabled();
return getSSLPictureURL("me");
Expand Down Expand Up @@ -2507,6 +2514,20 @@ private URL _getPictureURL(String objectId, PictureSize size) throws FacebookExc
throw new FacebookException(urle.getMessage(), urle);
}
}
private URL _getPictureURL(String objectId, int width, int height) throws FacebookException {
String url = buildEndpoint(objectId, "picture");
HttpResponse res;
if (width > 0 && height > 0) {
res = get(url, new HttpParameter[] { new HttpParameter("width", Integer.toString(width)), new HttpParameter("height", Integer.toString(height)) });
} else {
res = get(url);
}
try {
return new URL(res.getResponseHeader("Location"));
} catch (MalformedURLException urle) {
throw new FacebookException(urle.getMessage(), urle);
}
}

private URL _getSSLPictureURL(String objectId, PictureSize size) throws FacebookException {
String url = buildEndpoint(objectId, "picture");
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.2.0";
private static final String VERSION = "2.2.1";
private static final String TITLE = "Facebook4J";

private Version() {
Expand Down
23 changes: 22 additions & 1 deletion facebook4j-core/src/main/java/facebook4j/api/UserMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ public interface UserMethods {
*/
URL getPictureURL(PictureSize size) throws FacebookException;

/**
* Returns the url of the current user's profile picture.
* @param width width of the picture
* @param height height of the picture
* @return url
* @throws FacebookException when Facebook service or network is unavailable
* @see <a href="https://developers.facebook.com/docs/reference/api/user/">User - Facebook Developers</a> - Connections - picture
*/
URL getPictureURL(int width, int height) throws FacebookException;

/**
* Returns the url of a user's profile picture.
* @param userId the ID of a user
Expand All @@ -101,7 +111,18 @@ public interface UserMethods {
* @see <a href="https://developers.facebook.com/docs/reference/api/user/">User - Facebook Developers</a> - Connections - picture
*/
URL getPictureURL(String userId, PictureSize size) throws FacebookException;


/**
* Returns the url of a user's profile picture.
* @param userId the ID of a user
* @param width width of the picture
* @param height height of the picture
* @return url
* @throws FacebookException when Facebook service or network is unavailable
* @see <a href="https://developers.facebook.com/docs/reference/api/user/">User - Facebook Developers</a> - Connections - picture
*/
URL getPictureURL(String userId, int width, int height) throws FacebookException;

/**
* Returns the url of the current user's profile picture over a secure connection.
* @return url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
init(json);
}

/*package*/IdNameEntityJSONImpl(String name) {
super();
this.name = name;
}

private void init(JSONObject json) throws FacebookException {
id = getRawString("id", json);
name = getRawString("name", json);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@

package facebook4j.internal.json;

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

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

import facebook4j.FacebookException;
import facebook4j.Permission;
Expand All @@ -30,6 +25,12 @@
import facebook4j.internal.org.json.JSONException;
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 All @@ -53,7 +54,7 @@ public boolean isGranted() {
}

/*package*/
static List<Permission> createPermissionArray(HttpResponse res, Configuration conf) throws FacebookException {
static List<Permission> createPermissionArray(HttpResponse res, Configuration conf) throws FacebookException {
if (conf.isJSONStoreEnabled()) {
DataObjectFactoryUtil.clearThreadLocalMap();
}
Expand All @@ -63,11 +64,17 @@ 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);
Iterator<String> permissionNames = permissionJSONObject.keys();
while (permissionNames.hasNext()) {
String permissionName = permissionNames.next();
boolean isGranted = getFlag(permissionName, permissionJSONObject);
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));
}
}
}
if (conf.isJSONStoreEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,13 @@ private void init(JSONObject json) throws FacebookException {
}
email = getRawString("email", json);
if (!json.isNull("hometown")) {
JSONObject hometownJSON = json.getJSONObject("hometown");
hometown = new IdNameEntityJSONImpl(hometownJSON);
String hometownRawString = getRawString("hometown", json);
if (hometownRawString.startsWith("{")) {
JSONObject hometownJSON = json.getJSONObject("hometown");
hometown = new IdNameEntityJSONImpl(hometownJSON);
} else {
hometown = new IdNameEntityJSONImpl(hometownRawString);
}
}
if (!json.isNull("interestedIn")) {
JSONArray interestedInJSONArray = json.getJSONArray("interested_in");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package facebook4j;

import facebook4j.internal.http.RequestMethod;

import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
Expand All @@ -31,7 +32,8 @@
public class PermissionMethodsTest {

public static class getPermissions extends MockFacebookTestBase {
@Test

@Test
public void me() throws Exception {
facebook.setMockJSON("mock_json/permission/all.json");
List<Permission> actuals = facebook.getPermissions();
Expand All @@ -48,6 +50,26 @@ public void id() throws Exception {
assertThat(facebook.getHttpMethod(), is(RequestMethod.GET));
assertThat(facebook.getEndpointURL(), is(pathOf("/1234567890123456/permissions")));

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));
assertThat(facebook.getEndpointURL(), is(pathOf("/me/permissions")));

assertThat(actuals.size(), is(80));
}

@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));
assertThat(facebook.getEndpointURL(), is(pathOf("/1234567890123456/permissions")));

assertThat(actuals.size(), is(80));
}
}
Expand Down
23 changes: 23 additions & 0 deletions facebook4j-core/src/test/java/facebook4j/UserMethodsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ public void reading() throws Exception {
assertThat(user.getTimezone(), is(nullValue()));
assertThat(user.isInstalled(), is(nullValue()));
}

@Test
public void hometown_string() throws Exception {
facebook.setMockJSON("mock_json/user/hometown_string.json");
User user = facebook.getUser("CFKArgentina");

assertThat(user.getHometown().getId(), is(nullValue()));
assertThat(user.getHometown().getName(), is("La Plata"));
}
}

public static class getPictureURL extends MockFacebookTestBase {
Expand All @@ -180,6 +189,20 @@ public void me_size() throws Exception {
assertThat(url.toString(), is("https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/1111_22222_333333_q.jpg"));
}

@Test
public void me_width_height() throws Exception {
facebook.setMockJSON("mock_json/user/me_picture_width_height.json");
URL url = facebook.getPictureURL(720, 540);
assertThat(facebook.getEndpointURL(), hasParameter("width", "720"));
assertThat(facebook.getEndpointURL(), hasParameter("height", "540"));
assertThat(url.toString(), is("https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/1111_22222_333333_a.jpg"));
url = facebook.getPictureURL("100001568838021", 720, 540);
assertThat(facebook.getEndpointURL(), is(pathOf("/100001568838021/picture")));
assertThat(facebook.getEndpointURL(), hasParameter("width", "720"));
assertThat(facebook.getEndpointURL(), hasParameter("height", "540"));
assertThat(url.toString(), is("https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/1111_22222_333333_a.jpg"));
}

@Test
public void id() throws Exception {
facebook.setMockJSON("mock_json/user/me_picture.json");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"data": [
{"permission":"ads_management","status":"granted"},
{"permission":"basic_info","status":"granted"},
{"permission":"create_event","status":"granted"},
{"permission":"create_note","status":"granted"},
{"permission":"email","status":"granted"},
{"permission":"export_stream","status":"granted"},
{"permission":"friends_about_me","status":"granted"},
{"permission":"friends_actions.music","status":"granted"},
{"permission":"friends_actions.news","status":"granted"},
{"permission":"friends_actions.video","status":"granted"},
{"permission":"friends_activities","status":"granted"},
{"permission":"friends_birthday","status":"granted"},
{"permission":"friends_education_history","status":"granted"},
{"permission":"friends_events","status":"granted"},
{"permission":"friends_games_activity","status":"granted"},
{"permission":"friends_groups","status":"granted"},
{"permission":"friends_hometown","status":"granted"},
{"permission":"friends_interests","status":"granted"},
{"permission":"friends_likes","status":"granted"},
{"permission":"friends_location","status":"granted"},
{"permission":"friends_notes","status":"granted"},
{"permission":"friends_online_presence","status":"granted"},
{"permission":"friends_photo_video_tags","status":"granted"},
{"permission":"friends_photos","status":"granted"},
{"permission":"friends_questions","status":"granted"},
{"permission":"friends_relationship_details","status":"granted"},
{"permission":"friends_relationships","status":"granted"},
{"permission":"friends_religion_politics","status":"granted"},
{"permission":"friends_status","status":"granted"},
{"permission":"friends_subscriptions","status":"granted"},
{"permission":"friends_videos","status":"granted"},
{"permission":"friends_website","status":"granted"},
{"permission":"friends_work_history","status":"granted"},
{"permission":"installed","status":"granted"},
{"permission":"manage_friendlists","status":"granted"},
{"permission":"manage_notifications","status":"granted"},
{"permission":"manage_pages","status":"granted"},
{"permission":"photo_upload","status":"granted"},
{"permission":"publish_actions","status":"granted"},
{"permission":"publish_checkins","status":"granted"},
{"permission":"publish_stream","status":"granted"},
{"permission":"read_friendlists","status":"granted"},
{"permission":"read_insights","status":"granted"},
{"permission":"read_mailbox","status":"granted"},
{"permission":"read_page_mailboxes","status":"granted"},
{"permission":"read_requests","status":"granted"},
{"permission":"read_stream","status":"granted"},
{"permission":"rsvp_event","status":"granted"},
{"permission":"share_item","status":"granted"},
{"permission":"sms","status":"granted"},
{"permission":"status_update","status":"granted"},
{"permission":"user_about_me","status":"granted"},
{"permission":"user_actions.music","status":"granted"},
{"permission":"user_actions.news","status":"granted"},
{"permission":"user_actions.video","status":"granted"},
{"permission":"user_activities","status":"granted"},
{"permission":"user_birthday","status":"granted"},
{"permission":"user_education_history","status":"granted"},
{"permission":"user_events","status":"granted"},
{"permission":"user_games_activity","status":"granted"},
{"permission":"user_groups","status":"granted"},
{"permission":"user_hometown","status":"granted"},
{"permission":"user_interests","status":"granted"},
{"permission":"user_likes","status":"granted"},
{"permission":"user_location","status":"granted"},
{"permission":"user_notes","status":"granted"},
{"permission":"user_online_presence","status":"granted"},
{"permission":"user_photo_video_tags","status":"granted"},
{"permission":"user_photos","status":"granted"},
{"permission":"user_questions","status":"granted"},
{"permission":"user_relationship_details","status":"granted"},
{"permission":"user_relationships","status":"granted"},
{"permission":"user_religion_politics","status":"granted"},
{"permission":"user_status","status":"granted"},
{"permission":"user_subscriptions","status":"granted"},
{"permission":"user_videos","status":"granted"},
{"permission":"user_website","status":"granted"},
{"permission":"user_work_history","status":"granted"},
{"permission":"video_upload","status":"granted"},
{"permission":"xmpp_login","status":"granted"}
],
"paging": {"next": "https://graph.facebook.com/1234567890123456/permissions?access_token=access_token&limit=5000&offset=5000"}
}

0 comments on commit beb1165

Please sign in to comment.