Permalink
Browse files

Adding the first face4j code. May God bless the open source world!

To quote myself: I'm just a bad guy with good intentions.
  • Loading branch information...
0 parents commit 1ebb408a7ddac5b3442d618d14246278691c6590 @nischal nischal committed May 25, 2010
Showing with 1,364 additions and 0 deletions.
  1. +57 −0 build.xml
  2. BIN dist/dependencies/commons-codec-1.3.jar
  3. BIN dist/dependencies/commons-httpclient-3.1.jar
  4. BIN dist/dependencies/commons-logging-1.1.1.jar
  5. BIN dist/dependencies/gson-1.3.jar
  6. BIN dist/face4j-0.1.jar
  7. BIN lib/commons-codec-1.3.jar
  8. BIN lib/commons-httpclient-3.1.jar
  9. BIN lib/commons-logging-1.1.1.jar
  10. BIN lib/gson-1.3.jar
  11. +1 −0 readme.txt
  12. +27 −0 src/com/face4j/facebook/Client.java
  13. +88 −0 src/com/face4j/facebook/Facebook.java
  14. +36 −0 src/com/face4j/facebook/OAuthAccessToken.java
  15. +29 −0 src/com/face4j/facebook/entity/Concentration.java
  16. +29 −0 src/com/face4j/facebook/entity/Degree.java
  17. +49 −0 src/com/face4j/facebook/entity/Education.java
  18. +29 −0 src/com/face4j/facebook/entity/Employer.java
  19. +29 −0 src/com/face4j/facebook/entity/Hometown.java
  20. +29 −0 src/com/face4j/facebook/entity/Location.java
  21. +29 −0 src/com/face4j/facebook/entity/Position.java
  22. +29 −0 src/com/face4j/facebook/entity/School.java
  23. +183 −0 src/com/face4j/facebook/entity/User.java
  24. +81 −0 src/com/face4j/facebook/entity/Work.java
  25. +29 −0 src/com/face4j/facebook/entity/Year.java
  26. +25 −0 src/com/face4j/facebook/enums/Display.java
  27. +163 −0 src/com/face4j/facebook/enums/Permission.java
  28. +32 −0 src/com/face4j/facebook/enums/PictureType.java
  29. +37 −0 src/com/face4j/facebook/exception/FacebookException.java
  30. +129 −0 src/com/face4j/facebook/factory/FacebookFactory.java
  31. +5 −0 src/com/face4j/facebook/factory/OAuthFactory.java
  32. +89 −0 src/com/face4j/facebook/http/APICaller.java
  33. +48 −0 src/com/face4j/facebook/util/Constants.java
  34. +27 −0 src/com/face4j/facebook/util/JSONToObjectTransformer.java
  35. +55 −0 src/com/face4j/facebook/util/URLMaker.java
@@ -0,0 +1,57 @@
+<?xml version="1.0"?>
+
+<project name="face4j" basedir="." default="help">
+ <property name="java-src.dir" value="src" />
+ <property name="lib.dir" value="lib" />
+ <property name="build.dir" value="build" />
+ <property name="project.name" value="face4j" />
+ <property name="project.version" value="0.1" />
+ <property name="dist.dir" value="dist" />
+ <property name="archive.name-face4j" value="face4j-${project.version}" />
+ <property name="exclude-classes" value="com/face4j/dummy/**,com/face4j/facebook/test/**"></property>
+
+ <path id="classpath">
+ <fileset dir="${lib.dir}"/>
+ <pathelement path="${build.dir}" />
+ </path>
+
+ <target name="help">
+ <echo message="" />
+ <echo message="${project.name} build file" />
+ <echo message="-----------------------------------" />
+ <echo message="" />
+ <echo message="Available targets are:" />
+ <echo message="" />
+ <echo message="clean --> Deletes compiled classes and JAR" />
+ <echo message="" />
+ <echo message="compile --> Compile all Java files" />
+ <echo message="jar --> Package as JAR file" />
+ </target>
+
+ <target name="compile" description="Compile main source java files">
+ <mkdir dir="${build.dir}/classes" />
+ <javac destdir="${build.dir}/classes" debug="true" optimize="false" encoding="iso-8859-1" deprecation="false" failonerror="true" excludes="${exclude-classes}">
+ <src path="${java-src.dir}" />
+
+ <classpath refid="classpath" />
+ </javac>
+ </target>
+
+ <target name="jar" depends="compile" description="packages up the face4j class files into jar files">
+ <jar destfile="${lib.dir}/${archive.name-face4j}.jar" basedir="${build.dir}/classes" />
+ <copy todir="${dist.dir}/dependencies" >
+ <fileset dir="${lib.dir}" includes="commons-codec-1.3.jar,commons-httpclient-3.1.jar,commons-logging-1.1.1.jar,gson-1.3.jar" />
+ </copy>
+ <copy todir="${dist.dir}" >
+ <fileset dir="${lib.dir}" includes="${archive.name-face4j}.jar" />
+ </copy>
+ <delete file="${lib.dir}/${archive.name-face4j}.jar"/>
+ </target>
+
+ <target name="clean" description="Clean output directories">
+ <property name="archive.name" value="${project.name}-${project.version}" />
+ <delete dir="build" />
+ <delete file="${archive.name}.jar" />
+ </target>
+
+</project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
+The face4j.jar and all the other dependencies are needed.
@@ -0,0 +1,27 @@
+package com.face4j.facebook;
+
+public class Client {
+
+ private String clientId;
+ private String clientSecret;
+
+ /**
+ * @param clientId The client ID of your application as provided by the provider (ex. Facebook, twitter). You would need to register your
+ * application with the provider to obtain a client id.
+ * @param clientSecret The client secret of your application
+ */
+ public Client(String clientId, String clientSecret){
+ this.clientId = clientId;
+ this.clientSecret = clientSecret;
+ }
+
+ public String getClientId() {
+ return clientId;
+ }
+
+ public String getClientSecret() {
+ return clientSecret;
+ }
+
+
+}
@@ -0,0 +1,88 @@
+package com.face4j.facebook;
+
+import java.io.Serializable;
+import java.util.logging.Logger;
+
+import org.apache.commons.httpclient.NameValuePair;
+
+import com.face4j.facebook.entity.User;
+import com.face4j.facebook.exception.FacebookException;
+import com.face4j.facebook.http.APICaller;
+import com.face4j.facebook.util.Constants;
+import com.face4j.facebook.util.JSONToObjectTransformer;
+
+/**
+ * This is the main facebook class that will have methods which return facebook data as well as publish data to facebook
+ * This is a work in progress.
+ * @author Nischal Shetty - nischalshetty85 at gmail
+ *
+ */
+public class Facebook implements Serializable {
+
+ private static final long serialVersionUID = 350726728289608542L;
+
+ Logger logger = Logger.getLogger(Facebook.class.getName());
+
+ //private Client client;
+ private OAuthAccessToken authAccessToken;
+
+
+ /**
+ * @param authAccessToken
+ */
+ public Facebook(OAuthAccessToken authAccessToken){
+ this.authAccessToken = authAccessToken;
+ }
+
+
+ /**
+ * Returns the current user (for whom the client has been set).
+ * @return
+ * @throws Exception
+ */
+ public User getCurrentUser() throws FacebookException{
+ return getUser(Constants.SELF_PROFILE_INFO);
+ }
+
+
+ /**
+ * Returns a facebook users available info.
+ * @param username
+ * @return
+ * @throws FacebookException
+ */
+ public User getUser(String username) throws FacebookException{
+
+ //APICaller would retrieve the json string object from facebook by making a https call
+ APICaller caller = APICaller.getInstance();
+ String userJson = null;
+
+ NameValuePair[] nameValuePairs = {new NameValuePair(Constants.PARAM_ACCESS_TOKEN,this.authAccessToken.getAccessToken())};
+
+ //userJson = caller.getData(Constants.FACEBOOK_GRAPH_URL+"/"+username+"?"+Constants.PARAM_ACCESS_TOKEN+"="+URLEncoder.encode(this.authAccessToken.getAccessToken(),"UTF-8"));
+ userJson = caller.getData(Constants.FACEBOOK_GRAPH_URL+"/"+username,nameValuePairs);
+
+ //Once the json string object is obtaind, it is passed to obj transformer and the right object is retrieved
+ User user = JSONToObjectTransformer.getUser(userJson);
+
+ return user;
+ }
+
+ /**
+ * Returns a facebook users available info.
+ * @param username
+ * @return
+ * @throws FacebookException
+ */
+ public User getUser(long id) throws FacebookException{
+ return getUser(""+id);
+ }
+
+
+
+ public OAuthAccessToken getAuthAccessToken() {
+ return authAccessToken;
+ }
+
+
+}
@@ -0,0 +1,36 @@
+package com.face4j.facebook;
+
+public class OAuthAccessToken {
+
+ private String accessToken;
+ private Long expires;
+
+ public OAuthAccessToken(String accessToken){
+ this.accessToken = accessToken;
+ }
+
+ /**
+ * The access token as obtained from facebook.
+ * @return
+ */
+ public String getAccessToken() {
+ return accessToken;
+ }
+
+ /**
+ * Returns the expires time. null value represents the token doesn't expire meaning its long-lived
+ * @return
+ */
+ public Long getExpires() {
+ return expires;
+ }
+
+ /**
+ * Set the expires time. In case the token is long-lived set null
+ * @param expires
+ */
+ public void setExpires(Long expires) {
+ this.expires = expires;
+ }
+
+}
@@ -0,0 +1,29 @@
+package com.face4j.facebook.entity;
+
+import java.io.Serializable;
+
+public class Concentration implements Serializable{
+
+ private static final long serialVersionUID = -8571562108296652573L;
+
+ private long id;
+
+ private String name;
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
@@ -0,0 +1,29 @@
+package com.face4j.facebook.entity;
+
+import java.io.Serializable;
+
+public class Degree implements Serializable{
+
+ private static final long serialVersionUID = -4401265936474298087L;
+
+ private long id;
+
+ private String name;
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
@@ -0,0 +1,49 @@
+package com.face4j.facebook.entity;
+
+import java.io.Serializable;
+
+public class Education implements Serializable{
+
+ private static final long serialVersionUID = -3907283366668849023L;
+
+ private School school;
+
+ private Degree degree;
+
+ private Year year;
+
+ private Concentration[] concentrations;
+
+ public School getSchool() {
+ return school;
+ }
+
+ public void setSchool(School school) {
+ this.school = school;
+ }
+
+ public Degree getDegree() {
+ return degree;
+ }
+
+ public void setDegree(Degree degree) {
+ this.degree = degree;
+ }
+
+ public Year getYear() {
+ return year;
+ }
+
+ public void setYear(Year year) {
+ this.year = year;
+ }
+
+ public Concentration[] getConcentrations() {
+ return concentrations;
+ }
+
+ public void setConcentrations(Concentration[] concentrations) {
+ this.concentrations = concentrations;
+ }
+
+}
@@ -0,0 +1,29 @@
+package com.face4j.facebook.entity;
+
+import java.io.Serializable;
+
+public class Employer implements Serializable {
+
+ private static final long serialVersionUID = 7073751319710108889L;
+
+ private long id;
+
+ private String name;
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
@@ -0,0 +1,29 @@
+package com.face4j.facebook.entity;
+
+import java.io.Serializable;
+
+public class Hometown implements Serializable {
+
+ private static final long serialVersionUID = 140766500508933899L;
+
+ private long id;
+
+ private String name;
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
Oops, something went wrong.

0 comments on commit 1ebb408

Please sign in to comment.