Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reading options #82

Merged
merged 1 commit into from
Nov 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions facebook4j-core/src/main/java/facebook4j/Ordering.java
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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