Skip to content

Commit

Permalink
Add reading options
Browse files Browse the repository at this point in the history
- order
- include_hidden
- show_expired
- util method for adding reading parameter manually
  • Loading branch information
roundrop committed Nov 12, 2015
1 parent 3f6938b commit b1100f9
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
27 changes: 27 additions & 0 deletions 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,
;
}
29 changes: 29 additions & 0 deletions facebook4j-core/src/main/java/facebook4j/Reading.java
Expand Up @@ -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;
Expand Down
52 changes: 52 additions & 0 deletions facebook4j-core/src/test/java/facebook4j/ReadingTest.java
Expand Up @@ -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 {
Expand Down

0 comments on commit b1100f9

Please sign in to comment.