Skip to content

Commit

Permalink
age_range field management
Browse files Browse the repository at this point in the history
age_range comes as part of the public_profile permission, it indicates
unspecific age range that this person's age fits into.
values: min-max: (13-17 / 18-20 / 21-null)

usage:
Facebook facebook = new FacebookFactory().getInstance();
facebook.setOAuthAccessToken(new AccessToken(facebookToken, null));
User me = facebook.getMe(new Reading().fields(new String[]
{“age_range”, "birthday", "email", … }));
  • Loading branch information
paolobiavati committed Jan 9, 2015
1 parent 380da68 commit 2ad97a9
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
8 changes: 8 additions & 0 deletions facebook4j-core/src/main/java/facebook4j/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public interface User {
User.VideoUploadLimits getVideoUploadLimits();
URL getWebsite();
List<User.Work> getWork();
User.AgeRange getAgeRange();

interface Education {
IdNameEntity getYear();
Expand Down Expand Up @@ -90,6 +91,13 @@ interface Work {

}

interface AgeRange {
// one value could be null (13-17 / 18-20 / 21 - null)
Long getMin();
Long getMax();

}


String BIRTHDAY_DATE_FORMAT = "MM/dd/yyyy";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
private User.VideoUploadLimits videoUploadLimits;
private URL website;
private List<User.Work> work;
private User.AgeRange ageRange;

/*package*/UserJSONImpl(HttpResponse res, Configuration conf) throws FacebookException {
if (conf.isJSONStoreEnabled()) {
Expand Down Expand Up @@ -220,6 +221,10 @@ private void init(JSONObject json) throws FacebookException {
} else {
work = Collections.emptyList();
}
if (!json.isNull("age_range")) {
JSONObject ageRangeJSONObject = json.getJSONObject("age_range");
ageRange = new AgeRangeJSONImpl(ageRangeJSONObject);
}
} catch (JSONException jsone) {
throw new FacebookException(jsone.getMessage() + ":" + json.toString(), jsone);
}
Expand Down Expand Up @@ -361,6 +366,10 @@ public List<Work> getWork() {
return work;
}

public User.AgeRange getAgeRange() {
return ageRange;
}

/*package*/
static ResponseList<User> createUserList(HttpResponse res, Configuration conf) throws FacebookException {
try {
Expand Down Expand Up @@ -452,7 +461,7 @@ public String toString() {
+ relationshipStatus + ", religion=" + religion
+ ", significantOther=" + significantOther
+ ", videoUploadLimits=" + videoUploadLimits + ", website="
+ website + ", work=" + work + "]";
+ website + ", work=" + work + ", ageRange=" + ageRange + "]";
}


Expand Down Expand Up @@ -857,4 +866,55 @@ public String toString() {
}
}

private final class AgeRangeJSONImpl implements User.AgeRange, java.io.Serializable {
private static final long serialVersionUID = -4890967721976343047L;

private final Long min;
private final Long max;

AgeRangeJSONImpl(JSONObject json) throws FacebookException {
min = getLong("min", json);
max = getLong("max", json);
}

public Long getMin() {
return min;
}

public Long getMax() {
return max;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (min ^ (min >>> 32));
result = prime * result + (int) (max ^ (max >>> 32));
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
AgeRangeJSONImpl other = (AgeRangeJSONImpl) obj;
if (min != other.min)
return false;
if (max != other.max)
return false;
return true;
}

@Override
public String toString() {
return "AgeRangeJSONImpl [min=" + min + ", max=" + max
+ "]";
}
}

}

0 comments on commit 2ad97a9

Please sign in to comment.