Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
roundrop committed Jan 31, 2018
2 parents d184eba + 07243ca commit 6daa57b
Show file tree
Hide file tree
Showing 15 changed files with 467 additions and 23 deletions.
Binary file added .mvn/wrapper/maven-wrapper.jar
Binary file not shown.
1 change: 1 addition & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.2.1/apache-maven-3.2.1-bin.zip
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
language: java
addons:
apt:
packages:
- openjdk-6-jdk
jdk:
- openjdk6
cache:
Expand All @@ -7,4 +11,4 @@ cache:
before_script:
- echo "debug=false" >> facebook4j-core/src/test/resources/test.properties && echo "oauth.appId=1" >> facebook4j-core/src/test/resources/test.properties && echo "oauth.appSecret=1" >> facebook4j-core/src/test/resources/test.properties && echo "oauth.accessToken=access_token" >> facebook4j-core/src/test/resources/test.properties
after_success:
- mvn -pl facebook4j-core clean cobertura:cobertura org.eluder.coveralls:coveralls-maven-plugin:cobertura
- ./mvnw -pl facebook4j-core clean cobertura:cobertura org.eluder.coveralls:coveralls-maven-plugin:cobertura
9 changes: 9 additions & 0 deletions facebook4j-core/src/main/java/facebook4j/FacebookImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,15 @@ public Page getPage(String pageId, Reading reading) throws FacebookException {
return factory.createPage(res);
}

public ResponseList<Like> getPageLikes(String pageId) throws FacebookException {
return getPageLikes(pageId, null);
}

public ResponseList<Like> getPageLikes(String pageId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createLikeList(get(buildEndpoint(pageId, "likes", reading)));
}

public URL getPagePictureURL() throws FacebookException {
return getPagePictureURL("me", null);
}
Expand Down
8 changes: 2 additions & 6 deletions facebook4j-core/src/main/java/facebook4j/Page.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ public interface Page {
String getCategory();
Boolean isPublished();
Boolean canPost();

/**
* Number of pages this page likes.
* @return
*/
Integer getLikes();
Place.Location getLocation();
String getPhone();
Integer getCheckins();
Expand Down Expand Up @@ -65,4 +59,6 @@ public interface Page {
String getMission();
Map<String,String> getHours();

PagableList<Like> getLikes();

}
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.4.10";
private static final String VERSION = "2.4.11";
private static final String TITLE = "Facebook4J";

private Version() {
Expand Down
21 changes: 20 additions & 1 deletion facebook4j-core/src/main/java/facebook4j/api/PageMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import facebook4j.BackdatingPostUpdate;
import facebook4j.FacebookException;
import facebook4j.Insight;
import facebook4j.Like;
import facebook4j.Media;
import facebook4j.Milestone;
import facebook4j.MilestoneUpdate;
Expand Down Expand Up @@ -794,5 +795,23 @@ public interface PageMethods {
* @see <a href="https://developers.facebook.com/docs/reference/api/user/#likes">User#likes - Facebook Developers</a>
*/
Page getLikedPage(String userId, String pageId, Reading reading) throws FacebookException;


/**
* Returns likes made by the page.
* @param pageId the ID of a page
* @return likes
* @throws FacebookException when Facebook service or network is unavailable
* @see <a href="https://developers.facebook.com/docs/graph-api/reference/page/likes">Page Likes - Facebook Developers</a>
*/
ResponseList<Like> getPageLikes(String pageId) throws FacebookException;

/**
* Returns likes made by the page.
* @param pageId the ID of a page
* @param reading optional reading parameters. see <a href="https://developers.facebook.com/docs/reference/api/#reading">Graph API#reading - Facebook Developers</a> see <a href="https://developers.facebook.com/docs/reference/api/#reading">Graph API#reading - Facebook Developers</a>
* @return likes
* @throws FacebookException when Facebook service or network is unavailable
* @see <a href="https://developers.facebook.com/docs/graph-api/reference/page/likes">Page Likes - Facebook Developers</a>
*/
ResponseList<Like> getPageLikes(String pageId, Reading reading) throws FacebookException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
private URL link;
private Boolean isPublished;
private Boolean canPost;
private Integer likes;
private Place.Location location;
private String phone;
private Integer checkins;
Expand All @@ -62,6 +61,8 @@
private String mission;
private Map<String,String> hours;

private PagableList<Like> likes;

/*package*/PageJSONImpl(HttpResponse res, Configuration conf) throws FacebookException {
super(res);
JSONObject json = res.asJSONObject();
Expand All @@ -86,7 +87,24 @@ private void init(JSONObject json) throws FacebookException {
link = getURL("link", json);
isPublished = getBoolean("is_published", json);
canPost = getBoolean("can_post", json);
likes = getInt("likes", json);

if (!json.isNull("likes")) {
JSONObject likesJSONObject = json.getJSONObject("likes");
if (!likesJSONObject.isNull("data")) {
JSONArray list = likesJSONObject.getJSONArray("data");
final int size = list.length();
likes = new PagableListImpl<Like>(size, likesJSONObject);
for (int i = 0; i < size; i++) {
LikeJSONImpl like = new LikeJSONImpl(list.getJSONObject(i));
likes.add(like);
}
} else {
likes = new PagableListImpl<Like>(1, likesJSONObject);
}
} else {
likes = new PagableListImpl<Like>(0);
}

if (!json.isNull("location")) {
JSONObject locationJSONObject = json.getJSONObject("location");
location = new PlaceJSONImpl.LocationJSONImpl(locationJSONObject);
Expand Down Expand Up @@ -146,7 +164,7 @@ public Boolean canPost() {
return canPost;
}

public Integer getLikes() {
public PagableList<Like> getLikes() {
return likes;
}

Expand All @@ -163,7 +181,7 @@ public Integer getCheckins() {
}

public URL getPicture() {
return picture.getURL();
return picture == null ? null : picture.getURL();
}

public Picture getPagePicture() {
Expand Down
18 changes: 11 additions & 7 deletions facebook4j-core/src/test/java/facebook4j/PageMethodsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,10 @@

package facebook4j;

import facebook4j.internal.http.HttpParameter;
import facebook4j.internal.http.RequestMethod;
import facebook4j.internal.org.json.JSONArray;
import facebook4j.internal.org.json.JSONException;
import facebook4j.internal.org.json.JSONObject;
import facebook4j.junit.FacebookAPIVersion;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.internal.matchers.TypeSafeMatcher;
import org.junit.runner.RunWith;

import java.io.File;
Expand Down Expand Up @@ -89,6 +82,16 @@ public void id_reading() throws Exception {
assertThat(page.getName(), is("F4J"));
}

@Test
public void likes() throws Exception {
facebook.setMockJSON("mock_json/page/likes.json");
ResponseList<Like> likes = facebook.getPageLikes("10150146071791729");

assertThat(likes.size(), is(2));
assertThat(likes.get(0).getName(), is("Iveta Frybertova"));
assertThat(likes.get(1).getName(), is("Adel Youssef Youssef"));
}

@Test
public void about_and_username() throws Exception {
facebook.setMockJSON("mock_json/page/platform.json");
Expand Down Expand Up @@ -136,6 +139,7 @@ public void hours() throws Exception {
assertThat(actual.getHours().size(), is(28));
assertThat(actual.getHours().get("sat_2_close"), is("22:00"));
}

}

public static class getPagePictureURL extends MockFacebookTestBase {
Expand Down
4 changes: 3 additions & 1 deletion facebook4j-core/src/test/resources/mock_json/page/f4j.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"id": "137246726435626",
"is_community_page": false,
"is_published": false,
"likes": 0,
"likes": {
"data": []
},
"link": "http://www.facebook.com/pages/F4J/137246726435626",
"name": "F4J",
"new_like_count": 0,
Expand Down
19 changes: 19 additions & 0 deletions facebook4j-core/src/test/resources/mock_json/page/likes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"data": [
{
"id": "100002157503112",
"name": "Iveta Frybertova"
},
{
"id": "100003337717356",
"name": "Adel Youssef Youssef"
}
],
"paging": {
"cursors": {
"after": "MTAwMDAwNjM2MjQzMTQx",
"before": "MTAwMDAyMTU3NTAzMTEy"
},
"next": "https://graph.facebook.com/10150146071791729/likes?access_token=access_token&limit=25&after=MTAwMDAwNjM2MjQzMTQx"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"id": "19292868552",
"is_community_page": false,
"is_published": true,
"likes": 3270042,
"likes": {
"data": []
},
"link": "https://www.facebook.com/FacebookDevelopers",
"name": "Facebook Developers",
"parking": {
Expand Down
Loading

0 comments on commit 6daa57b

Please sign in to comment.