diff --git a/facebook4j-core/src/main/java/facebook4j/Ordering.java b/facebook4j-core/src/main/java/facebook4j/Ordering.java new file mode 100644 index 00000000..ee531dfd --- /dev/null +++ b/facebook4j-core/src/main/java/facebook4j/Ordering.java @@ -0,0 +1,27 @@ +/* + * 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.4.0 + */ +public enum Ordering { + CHRONOLOGICAL, + REVERSE_CHRONOLOGICAL, + ; +} diff --git a/facebook4j-core/src/main/java/facebook4j/Reading.java b/facebook4j-core/src/main/java/facebook4j/Reading.java index 590e26b7..aae45494 100644 --- a/facebook4j-core/src/main/java/facebook4j/Reading.java +++ b/facebook4j-core/src/main/java/facebook4j/Reading.java @@ -187,6 +187,35 @@ public Reading filter(String filterName) { return this; } + public Reading order(Ordering ordering) { + if (parameterMap.containsKey("order")) { + throw new IllegalStateException("'order' already sets"); + } + parameterMap.put("order", ordering.toString().toLowerCase()); + return this; + } + + public Reading includeHidden(boolean includeHidden) { + if (parameterMap.containsKey("include_hidden")) { + throw new IllegalStateException("'includeHidden' already sets"); + } + parameterMap.put("include_hidden", Boolean.toString(includeHidden)); + return this; + } + + public Reading showExpired(boolean showExpired) { + if (parameterMap.containsKey("show_expired")) { + throw new IllegalStateException("'showExpired' already sets"); + } + parameterMap.put("show_expired", Boolean.toString(showExpired)); + return this; + } + + public Reading addParameter(String name, Object value) { + parameterMap.put(name, value.toString()); + return this; + } + @Override public int hashCode() { final int prime = 31; diff --git a/facebook4j-core/src/test/java/facebook4j/ReadingTest.java b/facebook4j-core/src/test/java/facebook4j/ReadingTest.java index f71bb1ad..e6778cec 100644 --- a/facebook4j-core/src/test/java/facebook4j/ReadingTest.java +++ b/facebook4j-core/src/test/java/facebook4j/ReadingTest.java @@ -235,6 +235,58 @@ public void summary_true() throws Exception { } } + public static class Order { + @Test + public void chronological() throws Exception { + Reading reading = new Reading().order(Ordering.CHRONOLOGICAL); + assertThat(reading.getQuery(), is("order=chronological")); + } + @Test + public void reverseChronological() throws Exception { + Reading reading = new Reading().order(Ordering.REVERSE_CHRONOLOGICAL); + assertThat(reading.getQuery(), is("order=reverse_chronological")); + } + } + + public static class IncludeHidden { + @Test + public void true_() throws Exception { + Reading reading = new Reading().includeHidden(true); + assertThat(reading.getQuery(), is("include_hidden=true")); + } + @Test + public void false_() throws Exception { + Reading reading = new Reading().includeHidden(false); + assertThat(reading.getQuery(), is("include_hidden=false")); + } + } + + public static class ShowExpired { + @Test + public void true_() throws Exception { + Reading reading = new Reading().showExpired(true); + assertThat(reading.getQuery(), is("show_expired=true")); + } + @Test + public void false_() throws Exception { + Reading reading = new Reading().showExpired(false); + assertThat(reading.getQuery(), is("show_expired=false")); + } + } + + public static class AddParameter { + @Test + public void string() throws Exception { + Reading reading = new Reading().addParameter("name", "value"); + assertThat(reading.getQuery(), is("name=value")); + } + @Test + public void object() throws Exception { + Reading reading = new Reading().addParameter("foo", PrivacyType.EVERYONE); + assertThat(reading.getQuery(), is("foo=EVERYONE")); + } + } + public static class Combination { @Test public void offset_based() throws Exception {