Skip to content

Commit

Permalink
FFJ-24 add 'summary' parameter for /object/comments
Browse files Browse the repository at this point in the history
  • Loading branch information
roundrop committed Oct 6, 2014
1 parent 54e3ad0 commit 6e784e7
Show file tree
Hide file tree
Showing 16 changed files with 1,327 additions and 15 deletions.
Expand Up @@ -22,9 +22,9 @@
* @author Ryuji Yamashita - roundrop at gmail.com
*/
public interface InboxResponseList<T> extends ResponseList<T> {
InboxResponseList.Summary getSummary();
InboxSummary getInboxSummary();

interface Summary {
interface InboxSummary {
Integer getUnseenCount();
Integer getUnreadCount();
Date getUpdatedTime();
Expand Down
10 changes: 9 additions & 1 deletion facebook4j-core/src/main/java/facebook4j/Reading.java
Expand Up @@ -167,7 +167,15 @@ public Reading withLocation() {
parameterMap.put("with", "location");
return this;
}


public Reading summary() {
if (parameterMap.containsKey("summary")) {
throw new IllegalStateException("'summary' already sets");
}
parameterMap.put("summary", "true");
return this;
}

public Reading filter(String filterName) {
if (filterName == null) {
throw new NullPointerException("filterName is null");
Expand Down
1 change: 1 addition & 0 deletions facebook4j-core/src/main/java/facebook4j/ResponseList.java
Expand Up @@ -21,4 +21,5 @@
* @author Ryuji Yamashita - roundrop at gmail.com
*/
public interface ResponseList<T> extends PagableList<T> {
Summary getSummary();
}
41 changes: 41 additions & 0 deletions facebook4j-core/src/main/java/facebook4j/Summary.java
@@ -0,0 +1,41 @@
/*
* Copyright 2012 Ryuji Yamashita
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package facebook4j;

/**
* @author Ryuji Yamashita - roundrop at gmail.com
* @since Facebook4J 2.2.0
*/
public interface Summary {
SummaryOrder getOrder();
Integer getTotalCount();

public enum SummaryOrder {
ranked,
chronological,
;
public static SummaryOrder getInstance(String logic) {
for (SummaryOrder so : SummaryOrder.values()) {
if (so.toString().equals(logic.toLowerCase())) {
return so;
}
}
//throw new IllegalArgumentException();
return null;
}
}
}
Expand Up @@ -16,18 +16,19 @@

package facebook4j.internal.json;

import java.util.Date;

import static facebook4j.internal.util.z_F4JInternalParseUtil.*;
import facebook4j.FacebookException;
import facebook4j.InboxResponseList;
import facebook4j.internal.org.json.JSONException;
import facebook4j.internal.org.json.JSONObject;

import java.util.Date;

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

public class InboxResponseListImpl<T> extends ResponseListImpl<T> implements InboxResponseList<T> {
private static final long serialVersionUID = -392100352680662139L;

private InboxResponseList.Summary summary;
private InboxSummary inboxSummary;

/*package*/InboxResponseListImpl(JSONObject json, T... t) throws FacebookException {
super(json, t);
Expand All @@ -43,32 +44,32 @@ private void init(JSONObject json) throws FacebookException {
try {
if (!json.isNull("summary")) {
JSONObject summaryJSONObject = json.getJSONObject("summary");
summary = new SummaryJSONImpl(summaryJSONObject);
inboxSummary = new InboxSummaryJSONImpl(summaryJSONObject);
}
} catch (JSONException jsone) {
throw new FacebookException(jsone.getMessage(), jsone);
}
}

public InboxResponseList.Summary getSummary() {
return summary;
public InboxSummary getInboxSummary() {
return inboxSummary;
}

@Override
public String toString() {
return "InboxResponseListImpl [summary=" + summary + "]";
return "InboxResponseListImpl [summary=" + inboxSummary + "]";
}



private class SummaryJSONImpl implements InboxResponseList.Summary, java.io.Serializable {
private class InboxSummaryJSONImpl implements InboxSummary, java.io.Serializable {
private static final long serialVersionUID = 1988071486977638655L;

private Integer unseenCount;
private Integer unreadCount;
private Date updatedTime;

public SummaryJSONImpl(JSONObject json) throws FacebookException {
public InboxSummaryJSONImpl(JSONObject json) throws FacebookException {
if (!json.isNull("unseen_count")) {
unseenCount = getPrimitiveInt("unseen_count", json);
}
Expand Down
Expand Up @@ -18,6 +18,7 @@

import facebook4j.FacebookException;
import facebook4j.ResponseList;
import facebook4j.Summary;
import facebook4j.conf.Configuration;
import facebook4j.internal.http.HttpResponse;
import facebook4j.internal.org.json.JSONArray;
Expand All @@ -28,14 +29,27 @@
* @author Ryuji Yamashita - roundrop at gmail.com
*/
/*package*/ class ResponseListImpl<T> extends PagableListImpl<T> implements ResponseList<T> {
private static final long serialVersionUID = 1252744169603170859L;

private Summary summary;

/*package*/ResponseListImpl(JSONObject json, T... t) throws FacebookException {
super(json, t);
init(json);
}

/*package*/ResponseListImpl(int size, JSONObject json, T... t) throws FacebookException {
super(size, json, t);
init(json);
}

private void init(JSONObject json) throws FacebookException {
if (!json.isNull("summary")) {
try {
summary = new SummaryJSONImpl(json.getJSONObject("summary"));
} catch (JSONException jsone) {
throw new FacebookException(jsone.getMessage(), jsone);
}
}
}

/*package*/
Expand Down Expand Up @@ -72,4 +86,7 @@ private static ResponseList<JSONObject> createJSONObjectList(JSONObject json, Co
}
}

public Summary getSummary() {
return summary;
}
}
@@ -0,0 +1,85 @@
/*
* Copyright 2012 Ryuji Yamashita
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package facebook4j.internal.json;

import facebook4j.FacebookException;
import facebook4j.Summary;
import facebook4j.internal.org.json.JSONObject;

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

/**
* @author Ryuji Yamashita - roundrop at gmail.com
* @since Facebook4J 2.2.0
*/
public class SummaryJSONImpl extends FacebookResponseImpl implements Summary, java.io.Serializable {
private static final long serialVersionUID = 1378907332444378409L;

private final SummaryOrder order;
private Integer totalCount;

/*package*/SummaryJSONImpl(JSONObject json) throws FacebookException {
super();
if (json.isNull("order")) {
order = null;
} else {
order = SummaryOrder.getInstance(getRawString("order", json));
}

if (json.isNull("total_count")) {
totalCount = null;
} else {
totalCount = getInt("total_count", json);
}
}

public SummaryOrder getOrder() {
return order;
}

public Integer getTotalCount() {
return totalCount;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SummaryJSONImpl)) return false;

SummaryJSONImpl that = (SummaryJSONImpl) o;

if (order != that.order) return false;
if (totalCount != null ? !totalCount.equals(that.totalCount) : that.totalCount != null) return false;

return true;
}

@Override
public int hashCode() {
int result = order != null ? order.hashCode() : 0;
result = 31 * result + (totalCount != null ? totalCount.hashCode() : 0);
return result;
}

@Override
public String toString() {
return "SummaryJSONImpl{" +
"order=" + order +
", totalCount=" + totalCount +
"} ";
}
}
Expand Up @@ -31,6 +31,7 @@ public static MockFacebook create() {
}

public static MockFacebook create(Configuration conf) {
System.out.println("###############" + conf.getRestBaseURL());
return new MockFacebookImpl(conf, new MockAuthorization());
}
}
22 changes: 22 additions & 0 deletions facebook4j-core/src/test/java/facebook4j/MockFacebookTestBase.java
Expand Up @@ -17,9 +17,18 @@
package facebook4j;

import facebook4j.auth.AccessToken;
import facebook4j.conf.Configuration;
import facebook4j.junit.FacebookAPIVersion;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TestName;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public abstract class MockFacebookTestBase extends FacebookTestBase {
@Rule
public TestName name = new TestName();

protected MockFacebook facebook;

Expand All @@ -45,6 +54,19 @@ public void setUp() throws Exception {
if (appSecretProofEnabled != null) {
facebook.setAppSecretProofEnabled(Boolean.valueOf(appSecretProofEnabled));
}

// @FacebookAPIVersion
String restBaseURL = "https://graph.facebook.com/";
Method method = this.getClass().getMethod(this.name.getMethodName(), new Class[0]);
FacebookAPIVersion annotation = method.getAnnotation(FacebookAPIVersion.class);
if (annotation != null) {
String apiVersion = annotation.value();
restBaseURL += apiVersion + "/";
}
Configuration conf = ((FacebookBaseImpl) facebook).conf;
Field field = conf.getClass().getSuperclass().getDeclaredField("restBaseURL");
field.setAccessible(true);
field.set(conf, restBaseURL);
}

}

0 comments on commit 6e784e7

Please sign in to comment.