Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

1. Removed unwanted classes

2. Renamed whereever necessary
3. Added 'shorten' link
  • Loading branch information...
commit e895c4115f6b5073b05d00acfa441ab0c6225c5e 1 parent 6f6761b
@nischal nischal authored
Showing with 285 additions and 15,154 deletions.
  1. 0  src/{face4j.properties → bit4j.properties}
  2. +105 −0 src/com/bit4j/bitly/Bitly.java
  3. +1 −1  src/com/bit4j/{facebook → bitly}/Client.java
  4. +19 −10 src/com/bit4j/{facebook → bitly}/OAuthAccessToken.java
  5. +35 −0 src/com/bit4j/bitly/entity/bitly/Data.java
  6. +26 −0 src/com/bit4j/bitly/entity/bitly/ShortURL.java
  7. +1 −1  src/com/bit4j/{facebook → bitly}/enums/HttpClientType.java
  8. +4 −4 src/com/bit4j/{facebook/exception/FacebookError.java → bitly/exception/BitlyError.java}
  9. +7 −7 src/com/bit4j/{facebook/exception/FacebookException.java → bitly/exception/BitlyException.java}
  10. +1 −1  src/com/bit4j/{facebook → bitly}/exception/GenericError.java
  11. +1 −1  src/com/bit4j/{facebook → bitly}/exception/HttpError.java
  12. +1 −1  src/com/bit4j/{facebook → bitly}/exception/RequestArg.java
  13. +24 −49 src/com/bit4j/{facebook/factory/FacebookFactory.java → bitly/factory/BitlyFactory.java}
  14. +1 −1  src/com/bit4j/{facebook → bitly}/factory/OAuthFactory.java
  15. +17 −17 src/com/bit4j/{facebook → bitly}/http/APICaller.java
  16. +2 −2 src/com/bit4j/{facebook → bitly}/http/APICallerFactory.java
  17. +5 −5 src/com/bit4j/{facebook → bitly}/http/APICallerInterface.java
  18. +14 −14 src/com/bit4j/{facebook → bitly}/http/URLFetchAPICaller.java
  19. +7 −3 src/com/bit4j/{facebook → bitly}/util/Constants.java
  20. +14 −28 src/com/bit4j/{facebook → bitly}/util/JSONToObjectTransformer.java
  21. +0 −21 src/com/bit4j/facebook/Dummy.java
  22. +0 −1,012 src/com/bit4j/facebook/Facebook.java
  23. +0 −35 src/com/bit4j/facebook/criteria/ConnectionColumnCriteria.java
  24. +0 −54 src/com/bit4j/facebook/entity/Account.java
  25. +0 −28 src/com/bit4j/facebook/entity/Action.java
  26. +0 −55 src/com/bit4j/facebook/entity/Activity.java
  27. +0 −328 src/com/bit4j/facebook/entity/Album.java
  28. +0 −37 src/com/bit4j/facebook/entity/Application.java
  29. +0 −55 src/com/bit4j/facebook/entity/Book.java
  30. +0 −173 src/com/bit4j/facebook/entity/Checkin.java
  31. +0 −75 src/com/bit4j/facebook/entity/Comment.java
  32. +0 −29 src/com/bit4j/facebook/entity/Concentration.java
  33. +0 −46 src/com/bit4j/facebook/entity/Data.java
  34. +0 −29 src/com/bit4j/facebook/entity/Degree.java
  35. +0 −49 src/com/bit4j/facebook/entity/Education.java
  36. +0 −29 src/com/bit4j/facebook/entity/Employer.java
  37. +0 −17 src/com/bit4j/facebook/entity/Entity.java
  38. +0 −243 src/com/bit4j/facebook/entity/Event.java
  39. +0 −58 src/com/bit4j/facebook/entity/EventReply.java
  40. +0 −28 src/com/bit4j/facebook/entity/Friend.java
  41. +0 −48 src/com/bit4j/facebook/entity/From.java
  42. +0 −29 src/com/bit4j/facebook/entity/GenericEntity.java
  43. +0 −125 src/com/bit4j/facebook/entity/Group.java
  44. +0 −60 src/com/bit4j/facebook/entity/GroupConnection.java
  45. +0 −33 src/com/bit4j/facebook/entity/HighSchoolInfo.java
  46. +0 −29 src/com/bit4j/facebook/entity/Hometown.java
  47. +0 −37 src/com/bit4j/facebook/entity/Image.java
  48. +0 −48 src/com/bit4j/facebook/entity/Interest.java
  49. +0 −32 src/com/bit4j/facebook/entity/Language.java
  50. +0 −46 src/com/bit4j/facebook/entity/Like.java
  51. +0 −231 src/com/bit4j/facebook/entity/Link.java
  52. +0 −96 src/com/bit4j/facebook/entity/Location.java
  53. +0 −5 src/com/bit4j/facebook/entity/Media.java
  54. +0 −29 src/com/bit4j/facebook/entity/Member.java
  55. +0 −66 src/com/bit4j/facebook/entity/Message.java
  56. +0 −46 src/com/bit4j/facebook/entity/MovieConnection.java
  57. +0 −46 src/com/bit4j/facebook/entity/MusicConnection.java
  58. +0 −132 src/com/bit4j/facebook/entity/Note.java
  59. +0 −31 src/com/bit4j/facebook/entity/Owner.java
  60. +0 −496 src/com/bit4j/facebook/entity/Page.java
  61. +0 −42 src/com/bit4j/facebook/entity/Participant.java
  62. +0 −696 src/com/bit4j/facebook/entity/PermissionCheck.java
  63. +0 −22 src/com/bit4j/facebook/entity/PermissionCheckData.java
  64. +0 −254 src/com/bit4j/facebook/entity/Photo.java
  65. +0 −47 src/com/bit4j/facebook/entity/Place.java
  66. +0 −46 src/com/bit4j/facebook/entity/PokeConnection.java
  67. +0 −29 src/com/bit4j/facebook/entity/Position.java
  68. +0 −390 src/com/bit4j/facebook/entity/Post.java
  69. +0 −84 src/com/bit4j/facebook/entity/Privacy.java
  70. +0 −33 src/com/bit4j/facebook/entity/Property.java
  71. +0 −29 src/com/bit4j/facebook/entity/School.java
  72. +0 −28 src/com/bit4j/facebook/entity/Setting.java
  73. +0 −86 src/com/bit4j/facebook/entity/StatusMessage.java
  74. +0 −145 src/com/bit4j/facebook/entity/Tab.java
  75. +0 −102 src/com/bit4j/facebook/entity/Tag.java
  76. +0 −54 src/com/bit4j/facebook/entity/Targeting.java
  77. +0 −46 src/com/bit4j/facebook/entity/TelevisionConnection.java
  78. +0 −106 src/com/bit4j/facebook/entity/Thread.java
  79. +0 −20 src/com/bit4j/facebook/entity/To.java
  80. +0 −1,202 src/com/bit4j/facebook/entity/User.java
  81. +0 −79 src/com/bit4j/facebook/entity/Venue.java
  82. +0 −251 src/com/bit4j/facebook/entity/Video.java
  83. +0 −29 src/com/bit4j/facebook/entity/VideoUploadLimit.java
  84. +0 −81 src/com/bit4j/facebook/entity/Work.java
  85. +0 −29 src/com/bit4j/facebook/entity/Year.java
  86. +0 −62 src/com/bit4j/facebook/entity/connection/Accounts.java
  87. +0 −63 src/com/bit4j/facebook/entity/connection/Activities.java
  88. +0 −66 src/com/bit4j/facebook/entity/connection/Albums.java
  89. +0 −60 src/com/bit4j/facebook/entity/connection/Books.java
  90. +0 −60 src/com/bit4j/facebook/entity/connection/Checkins.java
  91. +0 −43 src/com/bit4j/facebook/entity/connection/Comments.java
  92. +0 −60 src/com/bit4j/facebook/entity/connection/Events.java
  93. +0 −60 src/com/bit4j/facebook/entity/connection/Feed.java
  94. +0 −60 src/com/bit4j/facebook/entity/connection/FriendLists.java
  95. +0 −60 src/com/bit4j/facebook/entity/connection/Friends.java
  96. +0 −60 src/com/bit4j/facebook/entity/connection/Groups.java
  97. +0 −60 src/com/bit4j/facebook/entity/connection/Home.java
  98. +0 −59 src/com/bit4j/facebook/entity/connection/Inbox.java
  99. +0 −60 src/com/bit4j/facebook/entity/connection/Interests.java
  100. +0 −37 src/com/bit4j/facebook/entity/connection/Likes.java
  101. +0 −60 src/com/bit4j/facebook/entity/connection/Links.java
  102. +0 −60 src/com/bit4j/facebook/entity/connection/Movies.java
  103. +0 −60 src/com/bit4j/facebook/entity/connection/Music.java
  104. +0 −60 src/com/bit4j/facebook/entity/connection/Notes.java
  105. +0 −60 src/com/bit4j/facebook/entity/connection/Outbox.java
  106. +0 −60 src/com/bit4j/facebook/entity/connection/Photos.java
  107. +0 −66 src/com/bit4j/facebook/entity/connection/Pokes.java
  108. +0 −60 src/com/bit4j/facebook/entity/connection/Posts.java
  109. +0 −60 src/com/bit4j/facebook/entity/connection/Settings.java
  110. +0 −66 src/com/bit4j/facebook/entity/connection/Statuses.java
  111. +0 −60 src/com/bit4j/facebook/entity/connection/Tabs.java
  112. +0 −60 src/com/bit4j/facebook/entity/connection/Television.java
  113. +0 −60 src/com/bit4j/facebook/entity/connection/Updates.java
  114. +0 −60 src/com/bit4j/facebook/entity/connection/Videos.java
  115. +0 −194 src/com/bit4j/facebook/entity/paging/Paging.java
  116. +0 −47 src/com/bit4j/facebook/enums/ConnectionColumn.java
  117. +0 −84 src/com/bit4j/facebook/enums/ConnectionType.java
  118. +0 −25 src/com/bit4j/facebook/enums/Display.java
  119. +0 −125 src/com/bit4j/facebook/enums/FqlPageColumn.java
  120. +0 −446 src/com/bit4j/facebook/enums/FqlUserColumn.java
  121. +0 −13 src/com/bit4j/facebook/enums/Friends.java
  122. +0 −213 src/com/bit4j/facebook/enums/Permission.java
  123. +0 −34 src/com/bit4j/facebook/enums/PictureType.java
  124. +0 −7 src/com/bit4j/facebook/enums/Privacy.java
  125. +0 −142 src/com/bit4j/facebook/enums/StreamColumn.java
  126. +0 −18 src/com/bit4j/facebook/enums/TargetType.java
  127. +0 −7 src/com/bit4j/facebook/enums/Value.java
  128. +0 −48 src/com/bit4j/facebook/fql/FqlActionLink.java
  129. +0 −332 src/com/bit4j/facebook/fql/FqlAlbum.java
  130. +0 −12 src/com/bit4j/facebook/fql/FqlAppData.java
  131. +0 −92 src/com/bit4j/facebook/fql/FqlAttachment.java
  132. +0 −48 src/com/bit4j/facebook/fql/FqlComment.java
  133. +0 −89 src/com/bit4j/facebook/fql/FqlComments.java
  134. +0 −82 src/com/bit4j/facebook/fql/FqlConnection.java
  135. +0 −128 src/com/bit4j/facebook/fql/FqlLikes.java
  136. +0 −162 src/com/bit4j/facebook/fql/FqlLink.java
  137. +0 −64 src/com/bit4j/facebook/fql/FqlMedia.java
  138. +0 −284 src/com/bit4j/facebook/fql/FqlPage.java
  139. +0 −383 src/com/bit4j/facebook/fql/FqlPhoto.java
  140. +0 −521 src/com/bit4j/facebook/fql/FqlPost.java
  141. +0 −18 src/com/bit4j/facebook/fql/FqlPrivacy.java
  142. +0 −28 src/com/bit4j/facebook/fql/FqlProperties.java
  143. +0 −776 src/com/bit4j/facebook/fql/FqlUser.java
  144. +0 −55 src/com/bit4j/facebook/fql/FqlVideo.java
  145. +0 −49 src/com/bit4j/facebook/fql/otherentities/FqlEducation.java
  146. +0 −58 src/com/bit4j/facebook/fql/otherentities/FqlWork.java
  147. +0 −253 src/com/bit4j/facebook/publish/WallPost.java
  148. +0 −38 src/com/bit4j/facebook/util/FacebookUtil.java
  149. +0 −55 src/com/bit4j/facebook/util/URLMaker.java
  150. +0 −30 src/com/bit4j/facebook/wrapper/FqlPageColumnCriteria.java
  151. +0 −31 src/com/bit4j/facebook/wrapper/FqlUserColumnCriteria.java
  152. +0 −300 src/com/bit4j/facebook/wrapper/StreamColumnCriteria.java
View
0  src/face4j.properties → src/bit4j.properties
File renamed without changes
View
105 src/com/bit4j/bitly/Bitly.java
@@ -0,0 +1,105 @@
+package com.bit4j.bitly;
+
+import java.io.Serializable;
+import java.lang.reflect.Type;
+import java.util.logging.Logger;
+
+import org.apache.commons.httpclient.NameValuePair;
+
+import com.bit4j.bitly.entity.bitly.ShortURL;
+import com.bit4j.bitly.enums.HttpClientType;
+import com.bit4j.bitly.exception.BitlyException;
+import com.bit4j.bitly.http.APICallerFactory;
+import com.bit4j.bitly.http.APICallerInterface;
+import com.bit4j.bitly.util.Constants;
+import com.bit4j.bitly.util.JSONToObjectTransformer;
+
+/**
+ * This is the main Bitly class. All the action is here!
+ *
+ * @author Nischal Shetty - nischal@codigami.com
+ */
+public class Bitly implements Serializable {
+
+ private static final long serialVersionUID = -7949886324407828634L;
+
+ Logger logger = Logger.getLogger(Bitly.class.getName());
+
+ private OAuthAccessToken authAccessToken;
+
+ private APICallerInterface caller = null;
+
+ /**
+ * If only the access token is passed, then the Apache Http Client library is used for making http
+ * requests
+ *
+ * @param authAccessToken
+ */
+ public Bitly(OAuthAccessToken authAccessToken) {
+ // apache http client is the default client type
+ this(authAccessToken, HttpClientType.APACHE_HTTP_CLIENT);
+ }
+
+ public Bitly(OAuthAccessToken authAccessToken, HttpClientType clientType) {
+ this.authAccessToken = authAccessToken;
+ caller = APICallerFactory.getAPICallerInstance(clientType);
+ }
+
+ public OAuthAccessToken getAuthAccessToken() {
+ return authAccessToken;
+ }
+
+ private NameValuePair getNameValuePairAccessToken() {
+ return new NameValuePair(Constants.PARAM_ACCESS_TOKEN, this.authAccessToken.getAccessToken());
+ }
+
+ public ShortURL shorten(String longUrl) throws BitlyException {
+ //bitly expects all long urls to have / before the param start i.e. before ?
+ //2 cases:
+ //case 1: http://grabinbox.com/?param=test
+ //case 2: http://grabinbox.com?param=test
+ //By aplying #replace twice, we make sure that both the cases are satisfied
+ longUrl = longUrl.replaceFirst("/\\?", "\\?").replaceFirst("\\?", "/?");
+
+ NameValuePair[] nameValuePairs = new NameValuePair[]{getNameValuePairAccessToken(), new NameValuePair(Constants.PARAM_LONG_URL,longUrl)};
+ return pullData(Constants.BITLY_URL+Constants.BITLY_LINKS_SHORTEN_URL, ShortURL.class, nameValuePairs);
+ }
+
+
+ /**
+ * Raw API method to pull any data in json form and transform it into the right object <br>
+ * An HTTP GET method is used here
+ *
+ * @param <E>
+ * @param url
+ * @param e The class into which the json object returned by the url fetch needs to be cast
+ * @param nameValuePairs Pass parameters that need to accompany the call
+ * @return
+ * @throws BitlyException
+ */
+ public <E> E pullData(String url, Class<E> e, NameValuePair[] nameValuePairs) throws BitlyException {
+ // APICaller would retrieve the json string object from facebook by making a https call
+ // Once the json string object is obtaind, it is passed to obj transformer and the right object
+ // is retrieved
+ return JSONToObjectTransformer.getObject(caller.getData(url, nameValuePairs), e);
+ }
+
+ /**
+ * This method is useful when your json contains maps (key value pairs). Send in parameterized maps.<br>
+ * Example: Type type = new TypeToken<Map<String, User>>(){}.getType();
+ * @param <E>
+ * @param url
+ * @param type
+ * @param nameValuePairs
+ * @return
+ * @throws BitlyException
+ */
+ public <E> E pullData(String url, Type type, NameValuePair[] nameValuePairs) throws BitlyException {
+ // APICaller would retrieve the json string object from facebook by making a https call
+ // Once the json string object is obtaind, it is passed to obj transformer and the right object
+ // is retrieved
+ return JSONToObjectTransformer.<E>getObject(caller.getData(url, nameValuePairs), type);
+ }
+
+
+}
View
2  src/com/bit4j/facebook/Client.java → src/com/bit4j/bitly/Client.java
@@ -1,4 +1,4 @@
-package com.bit4j.facebook;
+package com.bit4j.bitly;
public class Client {
View
29 src/com/bit4j/facebook/OAuthAccessToken.java → src/com/bit4j/bitly/OAuthAccessToken.java
@@ -1,23 +1,22 @@
-package com.bit4j.facebook;
+package com.bit4j.bitly;
import java.io.Serializable;
public class OAuthAccessToken implements Serializable {
-
+
private static final long serialVersionUID = 359116283414855580L;
-
+
private String accessToken;
private String login;
private String apiKey;
-
- public OAuthAccessToken(String accessToken, String login, String apiKey){
+
+ public OAuthAccessToken(String accessToken) {
this.accessToken = accessToken;
- this.login = login;
- this.apiKey = apiKey;
}
/**
- * The access token as obtained from bitly.
+ * The access token as obtained from bitly.
+ *
* @return
*/
public String getAccessToken() {
@@ -31,7 +30,17 @@ public String getLogin() {
public String getApiKey() {
return apiKey;
}
-
-
+
+ public void setLogin(String login) {
+ this.login = login;
+ }
+
+ public void setApiKey(String apiKey) {
+ this.apiKey = apiKey;
+ }
+
+ public void setAccessToken(String accessToken) {
+ this.accessToken = accessToken;
+ }
}
View
35 src/com/bit4j/bitly/entity/bitly/Data.java
@@ -0,0 +1,35 @@
+package com.bit4j.bitly.entity.bitly;
+
+import java.io.Serializable;
+
+public class Data implements Serializable {
+
+ private static final long serialVersionUID = -418298335839738052L;
+
+ private String globalHash;
+ private String hash;
+ private String longUrl;
+ private String newHash;
+ private String url;
+
+ public String getGlobalHash() {
+ return globalHash;
+ }
+
+ public String getHash() {
+ return hash;
+ }
+
+ public String getLongUrl() {
+ return longUrl;
+ }
+
+ public String getNewHash() {
+ return newHash;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+}
View
26 src/com/bit4j/bitly/entity/bitly/ShortURL.java
@@ -0,0 +1,26 @@
+package com.bit4j.bitly.entity.bitly;
+
+import java.io.Serializable;
+
+public class ShortURL implements Serializable {
+
+ private static final long serialVersionUID = -3686610455246570530L;
+
+ private Data data;
+
+ private int statusCode;
+ private String statusTxt;
+
+ public Data getData() {
+ return data;
+ }
+
+ public int getStatusCode() {
+ return statusCode;
+ }
+
+ public String getStatusTxt() {
+ return statusTxt;
+ }
+
+}
View
2  src/com/bit4j/facebook/enums/HttpClientType.java → src/com/bit4j/bitly/enums/HttpClientType.java
@@ -1,4 +1,4 @@
-package com.bit4j.facebook.enums;
+package com.bit4j.bitly.enums;
public enum HttpClientType {
View
8 src/com/bit4j/facebook/exception/FacebookError.java → src/com/bit4j/bitly/exception/BitlyError.java
@@ -1,8 +1,8 @@
-package com.bit4j.facebook.exception;
+package com.bit4j.bitly.exception;
import java.io.Serializable;
-public class FacebookError implements Serializable {
+public class BitlyError implements Serializable {
private static final long serialVersionUID = -1069090066662240990L;
@@ -11,11 +11,11 @@
private RequestArg[] requestArgs;
/* Keeping a no args constructor*/
- private FacebookError() {
+ private BitlyError() {
super();
}
- public FacebookError(int errorCode, String errorMsg, RequestArg[] requestArgs) {
+ public BitlyError(int errorCode, String errorMsg, RequestArg[] requestArgs) {
super();
this.errorCode = errorCode;
this.errorMsg = errorMsg;
View
14 ...m/bit4j/facebook/exception/FacebookException.java → src/com/bit4j/bitly/exception/BitlyException.java
@@ -1,24 +1,24 @@
-package com.bit4j.facebook.exception;
+package com.bit4j.bitly.exception;
-public class FacebookException extends Exception {
+public class BitlyException extends Exception {
private static final long serialVersionUID = -3433466538055836949L;
- private FacebookError error;
+ private BitlyError error;
- public FacebookException(String msg, Exception exception) {
+ public BitlyException(String msg, Exception exception) {
super(msg, exception);
}
- public FacebookException(FacebookError error) {
+ public BitlyException(BitlyError error) {
super();
this.error = error;
}
- public FacebookError getError() {
+ public BitlyError getError() {
return error;
}
- public void setError(FacebookError error) {
+ public void setError(BitlyError error) {
this.error = error;
}
View
2  src/com/bit4j/facebook/exception/GenericError.java → src/com/bit4j/bitly/exception/GenericError.java
@@ -1,4 +1,4 @@
-package com.bit4j.facebook.exception;
+package com.bit4j.bitly.exception;
import java.io.Serializable;
View
2  src/com/bit4j/facebook/exception/HttpError.java → src/com/bit4j/bitly/exception/HttpError.java
@@ -1,4 +1,4 @@
-package com.bit4j.facebook.exception;
+package com.bit4j.bitly.exception;
import java.io.Serializable;
View
2  src/com/bit4j/facebook/exception/RequestArg.java → src/com/bit4j/bitly/exception/RequestArg.java
@@ -1,4 +1,4 @@
-package com.bit4j.facebook.exception;
+package com.bit4j.bitly.exception;
import java.io.Serializable;
View
73 src/com/bit4j/facebook/factory/FacebookFactory.java → src/com/bit4j/bitly/factory/BitlyFactory.java
@@ -1,4 +1,4 @@
-package com.bit4j.facebook.factory;
+package com.bit4j.bitly.factory;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
@@ -8,23 +8,21 @@
import org.apache.commons.httpclient.NameValuePair;
-import com.bit4j.facebook.Client;
-import com.bit4j.facebook.Facebook;
-import com.bit4j.facebook.OAuthAccessToken;
-import com.bit4j.facebook.enums.Display;
-import com.bit4j.facebook.enums.HttpClientType;
-import com.bit4j.facebook.enums.Permission;
-import com.bit4j.facebook.exception.FacebookException;
-import com.bit4j.facebook.http.APICallerFactory;
-import com.bit4j.facebook.http.APICallerInterface;
-import com.bit4j.facebook.util.Constants;
+import com.bit4j.bitly.Bitly;
+import com.bit4j.bitly.Client;
+import com.bit4j.bitly.OAuthAccessToken;
+import com.bit4j.bitly.enums.HttpClientType;
+import com.bit4j.bitly.exception.BitlyException;
+import com.bit4j.bitly.http.APICallerFactory;
+import com.bit4j.bitly.http.APICallerInterface;
+import com.bit4j.bitly.util.Constants;
/**
* You can create a singleton instance of this class. This class is thread safe and you can have
* one instance for every unique client id and client secret
* @author Nischal Shetty
*/
-public class FacebookFactory extends OAuthFactory implements Serializable {
+public class BitlyFactory extends OAuthFactory implements Serializable {
private static final long serialVersionUID = 8997415594842693532L;
@@ -32,21 +30,21 @@
private HttpClientType httpClientType;
private APICallerInterface caller;
- Logger logger = Logger.getLogger(Facebook.class.getName());
+ Logger logger = Logger.getLogger(Bitly.class.getName());
- public FacebookFactory(String clientId, String clientSecret){
+ public BitlyFactory(String clientId, String clientSecret){
this(new Client(clientId, clientSecret), HttpClientType.APACHE_HTTP_CLIENT);
}
- public FacebookFactory(Client client){
+ public BitlyFactory(Client client){
this(client,HttpClientType.APACHE_HTTP_CLIENT);
}
- public FacebookFactory(String clientId, String clientSecret, HttpClientType clientType){
+ public BitlyFactory(String clientId, String clientSecret, HttpClientType clientType){
this(new Client(clientId, clientSecret),clientType);
}
- public FacebookFactory(Client client, HttpClientType clientType){
+ public BitlyFactory(Client client, HttpClientType clientType){
this.client = client;
this.httpClientType = clientType;
caller = APICallerFactory.getAPICallerInstance(clientType);
@@ -61,45 +59,18 @@ public HttpClientType getHttpClientType() {
* @param accessToken
* @return Facebook instance
*/
- public Facebook getInstance(OAuthAccessToken accessToken){
- return new Facebook(accessToken,httpClientType);
+ public Bitly getInstance(OAuthAccessToken accessToken){
+ return new Bitly(accessToken,httpClientType);
}
- /**
- * This will return the redirect URL. You need to redirect the user to this URL.
- * @return The URL to redirect the user to. If the callbackURL is null then the default URL as set is obtained
- */
public String getRedirectURL(String callbackURL){
- return getRedirectURL(callbackURL, null, new Permission[0]);
-
- }
-
- public String getRedirectURL(String callbackURL, Display display, Permission... permission){
-
String redirectURL = null;
try {
redirectURL = Constants.AUTHORIZE_URL+"?"+Constants.PARAM_CLIENT_ID+"="+client.getClientId()
+ "&"+Constants.PARAM_REDIRECT_URI+"="+URLEncoder.encode(callbackURL,"UTF-8");
-
- if(permission!=null && permission.length>0){
- StringBuilder permissions = null;
- for(Permission tempPermission: permission){
- if(permissions!=null){
- permissions.append(","+tempPermission.toString());
- } else {
- permissions = new StringBuilder(tempPermission.toString());
- }
- }
- redirectURL += "&"+Constants.PARAM_PERMISSION + "=" + permissions.toString().toLowerCase();
- }
-
- if(display!=null){
- redirectURL += "&"+Constants.PARAM_DISPLAY + "=" + display.toString().toLowerCase();
- }
-
} catch (UnsupportedEncodingException e) {
logger.log(Level.SEVERE, "Unsupported encoding! Please use some other encoding", e);
}
@@ -110,10 +81,10 @@ public String getRedirectURL(String callbackURL, Display display, Permission...
*
* @param code As passed by the authenticating site (facebook)
* @return
- * @throws FacebookException
+ * @throws BitlyException
* @throws Exception
*/
- public OAuthAccessToken getOAuthAccessToken(String code, String callbackURL) throws FacebookException{
+ public OAuthAccessToken getOAuthAccessToken(String code, String callbackURL) throws BitlyException{
//We make a call with the provided code, client_id, client_secret and redirect_uri
@@ -136,7 +107,11 @@ public OAuthAccessToken getOAuthAccessToken(String code, String callbackURL) thr
private OAuthAccessToken getAccessToken(String rawData) {
String finalSplit[] = "access_token=5a707d09c6e6732096ea9177a2cedba595e367b4&login=grabinbox&apiKey=R_b9e35f846f8c63a301b1901363a5b6da".split("access_token=|\\&login=|\\&apiKey=");
- return new OAuthAccessToken(finalSplit[1], finalSplit[2], finalSplit[3]);
+ OAuthAccessToken accessToken = new OAuthAccessToken(finalSplit[1]);
+ accessToken.setLogin(finalSplit[2]);
+ accessToken.setApiKey(finalSplit[3]);
+
+ return accessToken;
}
}
View
2  src/com/bit4j/facebook/factory/OAuthFactory.java → src/com/bit4j/bitly/factory/OAuthFactory.java
@@ -1,4 +1,4 @@
-package com.bit4j.facebook.factory;
+package com.bit4j.bitly.factory;
public abstract class OAuthFactory {
View
34 src/com/bit4j/facebook/http/APICaller.java → src/com/bit4j/bitly/http/APICaller.java
@@ -1,4 +1,4 @@
-package com.bit4j.facebook.http;
+package com.bit4j.bitly.http;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -19,8 +19,8 @@
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
-import com.bit4j.facebook.exception.FacebookException;
-import com.bit4j.facebook.util.JSONToObjectTransformer;
+import com.bit4j.bitly.exception.BitlyException;
+import com.bit4j.bitly.util.JSONToObjectTransformer;
/**
* APICaller will make http requests, obtain that response and return it without processing. Basically, the raw response is returned by every method.
@@ -51,7 +51,7 @@ private synchronized static HttpClient getHttpClient() {
//Check if username and password exists in any resource file
try {
- InputStream inputStream = ClassLoader.getSystemResourceAsStream("face4j.properties");
+ InputStream inputStream = ClassLoader.getSystemResourceAsStream("bit4j.properties");
Properties properties = new Properties();
properties.load(inputStream);
inputStream.close();
@@ -85,7 +85,7 @@ private synchronized static HttpClient getHttpClient() {
}
public static void main(String[] args) {
- InputStream inputStream = ClassLoader.getSystemResourceAsStream("face4j.properties");
+ InputStream inputStream = ClassLoader.getSystemResourceAsStream("bit4j.properties");
try {
Properties properties = new Properties();
@@ -111,7 +111,7 @@ public static APICaller getInstance(){
}
- public String getData(String url, NameValuePair[] nameValuePairs) throws FacebookException{
+ public String getData(String url, NameValuePair[] nameValuePairs) throws BitlyException{
HttpClient client = APICaller.getHttpClient();
String response = null;
@@ -138,13 +138,13 @@ public String getData(String url, NameValuePair[] nameValuePairs) throws Faceboo
if (statusCode != HttpStatus.SC_OK) {
//FacebookError error = new FacebookError(statusCode, "I guess you are not permitted to access this url. HTTP status code:"+statusCode, null);
response = getMethod.getResponseBodyAsString();
- throw new FacebookException(JSONToObjectTransformer.getError(response, statusCode));
+ throw new BitlyException(JSONToObjectTransformer.getError(response, statusCode));
}
response = getMethod.getResponseBodyAsString();
} catch (HttpException e) {
- throw new FacebookException("Http Exception while calling facebook!",e);
+ throw new BitlyException("Http Exception while calling facebook!",e);
} catch (IOException e) {
- throw new FacebookException("IO Exception while calling facebook!",e);
+ throw new BitlyException("IO Exception while calling facebook!",e);
} finally {
getMethod.releaseConnection();
}
@@ -156,7 +156,7 @@ public String getData(String url, NameValuePair[] nameValuePairs) throws Faceboo
}
- public String postData(String url, NameValuePair[] nameValuePairs) throws FacebookException {
+ public String postData(String url, NameValuePair[] nameValuePairs) throws BitlyException {
HttpClient client = APICaller.getHttpClient();
String response = null;
@@ -173,13 +173,13 @@ public String postData(String url, NameValuePair[] nameValuePairs) throws Facebo
if (statusCode != HttpStatus.SC_OK) {
//FacebookError error = new FacebookError(statusCode, "I guess you are not permitted to access this url. HTTP status code:"+statusCode, null);
response = postMethod.getResponseBodyAsString();
- throw new FacebookException(JSONToObjectTransformer.getError(response, statusCode));
+ throw new BitlyException(JSONToObjectTransformer.getError(response, statusCode));
}
response = postMethod.getResponseBodyAsString();
} catch (HttpException e) {
- throw new FacebookException("Http Exception while calling facebook!", e);
+ throw new BitlyException("Http Exception while calling facebook!", e);
} catch (IOException e) {
- throw new FacebookException("IO Exception while calling facebook!", e);
+ throw new BitlyException("IO Exception while calling facebook!", e);
} finally {
postMethod.releaseConnection();
}
@@ -187,7 +187,7 @@ public String postData(String url, NameValuePair[] nameValuePairs) throws Facebo
return response;
}
- public String deleteData(String url, NameValuePair[] nameValuePairs) throws FacebookException {
+ public String deleteData(String url, NameValuePair[] nameValuePairs) throws BitlyException {
HttpClient client = APICaller.getHttpClient();
String response = null;
@@ -203,13 +203,13 @@ public String deleteData(String url, NameValuePair[] nameValuePairs) throws Face
int statusCode = client.executeMethod(deleteMethod);
if (statusCode != HttpStatus.SC_OK) {
response = deleteMethod.getResponseBodyAsString();
- throw new FacebookException(JSONToObjectTransformer.getError(response, statusCode));
+ throw new BitlyException(JSONToObjectTransformer.getError(response, statusCode));
}
response = deleteMethod.getResponseBodyAsString();
} catch (HttpException e) {
- throw new FacebookException("Http Exception while calling facebook!", e);
+ throw new BitlyException("Http Exception while calling facebook!", e);
} catch (IOException e) {
- throw new FacebookException("IO Exception while calling facebook!", e);
+ throw new BitlyException("IO Exception while calling facebook!", e);
} finally {
deleteMethod.releaseConnection();
}
View
4 src/com/bit4j/facebook/http/APICallerFactory.java → src/com/bit4j/bitly/http/APICallerFactory.java
@@ -1,9 +1,9 @@
-package com.bit4j.facebook.http;
+package com.bit4j.bitly.http;
import java.util.HashMap;
import java.util.Map;
-import com.bit4j.facebook.enums.HttpClientType;
+import com.bit4j.bitly.enums.HttpClientType;
public class APICallerFactory {
View
10 src/com/bit4j/facebook/http/APICallerInterface.java → src/com/bit4j/bitly/http/APICallerInterface.java
@@ -1,14 +1,14 @@
-package com.bit4j.facebook.http;
+package com.bit4j.bitly.http;
import org.apache.commons.httpclient.NameValuePair;
-import com.bit4j.facebook.exception.FacebookException;
+import com.bit4j.bitly.exception.BitlyException;
public interface APICallerInterface {
- public String getData(String url, NameValuePair[] nameValuePairs) throws FacebookException;
+ public String getData(String url, NameValuePair[] nameValuePairs) throws BitlyException;
- public String postData(String url, NameValuePair[] nameValuePairs) throws FacebookException;
+ public String postData(String url, NameValuePair[] nameValuePairs) throws BitlyException;
- public String deleteData(String url, NameValuePair[] nameValuePairs) throws FacebookException;
+ public String deleteData(String url, NameValuePair[] nameValuePairs) throws BitlyException;
}
View
28 src/com/bit4j/facebook/http/URLFetchAPICaller.java → src/com/bit4j/bitly/http/URLFetchAPICaller.java
@@ -1,4 +1,4 @@
-package com.bit4j.facebook.http;
+package com.bit4j.bitly.http;
import java.io.BufferedReader;
import java.io.IOException;
@@ -15,8 +15,8 @@
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
-import com.bit4j.facebook.exception.FacebookException;
-import com.bit4j.facebook.util.JSONToObjectTransformer;
+import com.bit4j.bitly.exception.BitlyException;
+import com.bit4j.bitly.util.JSONToObjectTransformer;
import com.google.appengine.api.urlfetch.HTTPMethod;
import com.google.appengine.api.urlfetch.HTTPRequest;
import com.google.appengine.api.urlfetch.HTTPResponse;
@@ -25,7 +25,7 @@
public class URLFetchAPICaller implements APICallerInterface {
- public String getData(String url, NameValuePair[] nameValuePairs) throws FacebookException {
+ public String getData(String url, NameValuePair[] nameValuePairs) throws BitlyException {
URLFetchService fetchService = URLFetchServiceFactory.getURLFetchService();
URL fetchURL = null;
@@ -56,13 +56,13 @@ public String getData(String url, NameValuePair[] nameValuePairs) throws Faceboo
// FacebookError error = new FacebookError(statusCode,
// "I guess you are not permitted to access this url. HTTP status code:"+statusCode, null);
responseString = new String(response.getContent());
- throw new FacebookException(JSONToObjectTransformer.getError(responseString, statusCode));
+ throw new BitlyException(JSONToObjectTransformer.getError(responseString, statusCode));
}
responseString = new String(response.getContent());
} catch (HttpException e) {
- throw new FacebookException("Http Exception while calling facebook!", e);
+ throw new BitlyException("Http Exception while calling facebook!", e);
} catch (IOException e) {
- throw new FacebookException("IO Exception while calling facebook!", e);
+ throw new BitlyException("IO Exception while calling facebook!", e);
}
// if response string contains accessToken=xxx remove it!
@@ -75,9 +75,9 @@ public String getData(String url, NameValuePair[] nameValuePairs) throws Faceboo
* @param url
* @param nameValuePairs
* @return
- * @throws FacebookException
+ * @throws BitlyException
*/
- public String postData(String url, NameValuePair[] nameValuePairs) throws FacebookException {
+ public String postData(String url, NameValuePair[] nameValuePairs) throws BitlyException {
String content = null;
String constructedParams = null;
@@ -106,14 +106,14 @@ public String postData(String url, NameValuePair[] nameValuePairs) throws Facebo
//System.out.println("Content------- "+content);
- throw new FacebookException(JSONToObjectTransformer.getError(content, statusCode));
+ throw new BitlyException(JSONToObjectTransformer.getError(content, statusCode));
} else {
content = getResponse(connection);
}
} catch (MalformedURLException e) {
- throw new FacebookException("Malformed URL Exception while calling facebook!", e);
+ throw new BitlyException("Malformed URL Exception while calling facebook!", e);
} catch (IOException e) {
- throw new FacebookException("IOException while calling facebook!", e);
+ throw new BitlyException("IOException while calling facebook!", e);
} finally {
if (connection != null) {
connection.disconnect();
@@ -180,7 +180,7 @@ private String getResponse(HttpURLConnection connection) throws IOException {
* }
*/
- public String deleteData(String url, NameValuePair[] nameValuePairs) throws FacebookException {
+ public String deleteData(String url, NameValuePair[] nameValuePairs) throws BitlyException {
String content = null;
String constructedParams = null;
int statusCode = 0;
@@ -201,7 +201,7 @@ public String deleteData(String url, NameValuePair[] nameValuePairs) throws Face
if (statusCode != HttpURLConnection.HTTP_OK) {
content = new String(response.getContent());
- throw new FacebookException(JSONToObjectTransformer.getError(content, statusCode));
+ throw new BitlyException(JSONToObjectTransformer.getError(content, statusCode));
} else {
content = new String(response.getContent());
}
View
10 src/com/bit4j/facebook/util/Constants.java → src/com/bit4j/bitly/util/Constants.java
@@ -1,4 +1,4 @@
-package com.bit4j.facebook.util;
+package com.bit4j.bitly.util;
public class Constants {
@@ -11,14 +11,18 @@
/**
* This URL will return the access token
*/
- public static final String ACCESS_TOKEN_URL = Constants.FACEBOOK_GRAPH_URL + "/oauth/access_token";
+ public static final String ACCESS_TOKEN_URL = Constants.BITLY_URL + "/oauth/access_token";
/**
* With the access token, FACEBOOK_GRAPH_URL is used to make calls for appropriate data
*/
- public static final String FACEBOOK_GRAPH_URL = "https://api-ssl.bitly.com";
+ public static final String BITLY_URL = "https://api-ssl.bitly.com";
public static final String BITLY_AUTH_URL = "https://bitly.com";
+
+ public static final String BITLY_LINKS_SHORTEN_URL = "/v3/shorten";
+
+ public static final String PARAM_LONG_URL = "longUrl";
public static final String ME = "me";
View
42 .../bit4j/facebook/util/JSONToObjectTransformer.java → ...com/bit4j/bitly/util/JSONToObjectTransformer.java
@@ -1,14 +1,12 @@
-package com.bit4j.facebook.util;
+package com.bit4j.bitly.util;
import java.lang.reflect.Type;
import java.util.logging.Level;
import java.util.logging.Logger;
-import com.bit4j.facebook.entity.Post;
-import com.bit4j.facebook.entity.User;
-import com.bit4j.facebook.exception.FacebookError;
-import com.bit4j.facebook.exception.FacebookException;
-import com.bit4j.facebook.exception.HttpError;
+import com.bit4j.bitly.exception.BitlyError;
+import com.bit4j.bitly.exception.BitlyException;
+import com.bit4j.bitly.exception.HttpError;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@@ -31,19 +29,7 @@
private static final Gson gson = new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
- public static User getUser(String userJSON) throws FacebookException {
- //If facebook returns an error then throw the error
- errorCheck(userJSON);
- return gson.fromJson(userJSON, User.class);
- }
-
- public static Post getPost(String postJson) throws FacebookException{
- //If facebook returns an error then throw the error
- errorCheck(postJson);
- return gson.fromJson(postJson, Post.class);
- }
-
- public static <E> E getObject(String json, Class<E> e) throws FacebookException {
+ public static <E> E getObject(String json, Class<E> e) throws BitlyException {
//If facebook returns an error then throw the error
errorCheck(json);
@@ -51,33 +37,33 @@ public static Post getPost(String postJson) throws FacebookException{
return gson.fromJson(json, e);
} catch(Exception exception){
logger.log(Level.SEVERE, "Data received from Facebook for class "+e.getName()+" is "+json,exception);
- throw new FacebookException("Error while converting object. Send this to nischal@grabinbox.com : "+json, exception);
+ throw new BitlyException("Error while converting object. Send this to nischal@grabinbox.com : "+json, exception);
}
}
- public static <E> E getObject(String json, Type type) throws FacebookException {
+ public static <E> E getObject(String json, Type type) throws BitlyException {
//If facebook returns an error then throw the error
errorCheck(json);
return gson.<E>fromJson(json, type);
}
- private static void errorCheck(String json) throws FacebookException {
+ private static void errorCheck(String json) throws BitlyException {
if(json.contains("error_code")){
- FacebookError error = null;
+ BitlyError error = null;
try {
- error = gson.fromJson(json, FacebookError.class);
+ error = gson.fromJson(json, BitlyError.class);
} catch(Exception exception){
- throw new FacebookException("Error in converting facebook error to FacebookError object! Facebook data is: "+json,exception);
+ throw new BitlyException("Error in converting facebook error to FacebookError object! Facebook data is: "+json,exception);
}
- throw new FacebookException(error);
+ throw new BitlyException(error);
}
}
- public static FacebookError getError(String response, int statusCode) {
+ public static BitlyError getError(String response, int statusCode) {
HttpError httpError = gson.fromJson(response, HttpError.class);
- return new FacebookError(statusCode, "Exception Type: "+httpError.getError().getType()+ " " + httpError.getError().getMessage(), null);
+ return new BitlyError(statusCode, "Exception Type: "+httpError.getError().getType()+ " " + httpError.getError().getMessage(), null);
}
/*public static void main(String[] args) {
View
21 src/com/bit4j/facebook/Dummy.java
@@ -1,21 +0,0 @@
-package com.bit4j.facebook;
-
-import com.bit4j.facebook.enums.HttpClientType;
-import com.bit4j.facebook.factory.FacebookFactory;
-
-public class Dummy {
-
- public static void main(String[] args) {
-
- FacebookFactory facebookFactory = new FacebookFactory(new Client("test", "test"), HttpClientType.APACHE_HTTP_CLIENT);
-
- //Facebook facebook = facebookFactory.getInstance(new OAuthAccessToken(""));
-
- /*try {
- facebook.comment("", "");
- } catch (FacebookException e) {
- }*/
-
- }
-
-}
View
1,012 src/com/bit4j/facebook/Facebook.java
@@ -1,1012 +0,0 @@
-package com.bit4j.facebook;
-
-import java.io.Serializable;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Logger;
-
-import org.apache.commons.httpclient.NameValuePair;
-import org.apache.commons.lang.StringUtils;
-
-import com.bit4j.facebook.criteria.ConnectionColumnCriteria;
-import com.bit4j.facebook.entity.Page;
-import com.bit4j.facebook.entity.Post;
-import com.bit4j.facebook.entity.User;
-import com.bit4j.facebook.entity.paging.Paging;
-import com.bit4j.facebook.enums.*;
-import com.bit4j.facebook.exception.FacebookException;
-import com.bit4j.facebook.fql.FqlConnection;
-import com.bit4j.facebook.fql.FqlPage;
-import com.bit4j.facebook.fql.FqlPost;
-import com.bit4j.facebook.fql.FqlUser;
-import com.bit4j.facebook.http.APICallerFactory;
-import com.bit4j.facebook.http.APICallerInterface;
-import com.bit4j.facebook.util.Constants;
-import com.bit4j.facebook.util.JSONToObjectTransformer;
-import com.bit4j.facebook.wrapper.FqlPageColumnCriteria;
-import com.bit4j.facebook.wrapper.FqlUserColumnCriteria;
-import com.bit4j.facebook.wrapper.StreamColumnCriteria;
-import com.google.gson.reflect.TypeToken;
-
-/**
- * This is the main facebook class that will have methods which return facebook data as well as
- * publish data to facebook.
- *
- * @author Nischal Shetty - nischalshetty85@gmail.com
- */
-public class Facebook implements Serializable {
-
- private static final long serialVersionUID = 350726728289608542L;
-
- Logger logger = Logger.getLogger(Facebook.class.getName());
-
- private OAuthAccessToken authAccessToken;
-
- private APICallerInterface caller = null;
-
- /**
- * If only the access token is passed, then the Apache Http Client library is used for making http
- * requests
- *
- * @param authAccessToken
- */
- public Facebook(OAuthAccessToken authAccessToken) {
- // apache http client is the default client type
- this(authAccessToken, HttpClientType.APACHE_HTTP_CLIENT);
- }
-
- public Facebook(OAuthAccessToken authAccessToken, HttpClientType clientType) {
- this.authAccessToken = authAccessToken;
- caller = APICallerFactory.getAPICallerInstance(clientType);
- }
-
- /**
- * Returns the current user (for whom the client has been set).
- *
- * @return
- * @throws Exception
- */
- public User getCurrentUser() throws FacebookException {
- return getUser(Constants.ME);
- }
-
- /**
- * Returns a Facebook user's available info.
- *
- * @param fbId
- * @return
- * @throws FacebookException
- */
- public User getUser(String fbId) throws FacebookException {
- NameValuePair[] nameValuePairs = { new NameValuePair(Constants.PARAM_ACCESS_TOKEN, this.authAccessToken.getAccessToken()) };
- return pullData(Constants.FACEBOOK_GRAPH_URL + "/" + fbId, User.class, nameValuePairs);
- }
-
-
- /**
- * Returns an array of facebook users for all the fb user ids passed
- * @param fbIds
- * @return
- * @throws FacebookException
- */
- public User[] getUsers(String[] fbIds) throws FacebookException {
-
- String concatenatedFbIds = StringUtils.join(fbIds, ",");
- NameValuePair[] nameValuePairs = { new NameValuePair(Constants.PARAM_ACCESS_TOKEN, this.authAccessToken.getAccessToken()),
- new NameValuePair("ids",concatenatedFbIds) };
- User[] users = null;
-
- Type type = new TypeToken<Map<String, User>>(){}.getType();
- Map<String, User> userMap = pullData(Constants.FACEBOOK_GRAPH_URL+"/", type, nameValuePairs);
-
- if(userMap != null){
- users = new User[fbIds.length];
-
- int i=0;
- for(Iterator<String> iterator = userMap.keySet().iterator();iterator.hasNext();){
- users[i++] = userMap.get(iterator.next());
- }
- }
-
- return users;
- }
-
- /**
- * Returns a facebook page's available info.
- *
- * @param fbId
- * @return
- * @throws FacebookException
- */
- public Page getPage(String fbId) throws FacebookException {
- NameValuePair[] nameValuePairs = { new NameValuePair(Constants.PARAM_ACCESS_TOKEN, this.authAccessToken.getAccessToken()) };
- return pullData(Constants.FACEBOOK_GRAPH_URL + "/" + fbId, Page.class, nameValuePairs);
- }
-
-
- /**
- * Returns an array of facebook pages for all the fb page ids passed
- * @param fbIds
- * @return
- * @throws FacebookException
- */
- public Page[] getPages(String[] fbIds) throws FacebookException {
-
- String concatenatedFbIds = StringUtils.join(fbIds, ",");
- NameValuePair[] nameValuePairs = { new NameValuePair(Constants.PARAM_ACCESS_TOKEN, this.authAccessToken.getAccessToken()),
- new NameValuePair("ids",concatenatedFbIds) };
- Page[] pages = null;
-
- Type type = new TypeToken<Map<String, Page>>(){}.getType();
- Map<String, Page> userMap = pullData(Constants.FACEBOOK_GRAPH_URL+"/", type, nameValuePairs);
-
- if(userMap != null){
- pages = new Page[fbIds.length];
-
- int i=0;
- for(Iterator<String> iterator = userMap.keySet().iterator();iterator.hasNext();){
- pages[i++] = userMap.get(iterator.next());
- }
- }
-
- return pages;
- }
-
-
- /**
- * Deprecated: Use {@link #link(List)} instead
- * Posts a link on the user's/page's wall <br>
- * Requires the {@link Permission#PUBLISH_STREAM} permission
- *
- * @param link The URL to share
- * @param name The name of the link (optional)
- * @param caption The caption of the link, appears beneath the link name (optional)
- * @param description A description of the link, appears beneath the link caption (optional)
- * @param message The message from the user about this link(optional)
- * @param icon A URL to the link icon that Facebook displays in the news feed (optional)
- * @param picture A URL to the thumbnail image used in the link post (optional)
- * @param privacy
- * @throws FacebookException
- */
- /*@Deprecated
- public void postLink(String link, String name, String caption, String description, String message, String icon, String picture, Value privacy)
- throws FacebookException {
-
- List<NameValuePair> namesValues = new ArrayList<NameValuePair>();
-
- namesValues.add(new NameValuePair(Constants.PARAM_ACCESS_TOKEN, this.authAccessToken.getAccessToken()));
-
- namesValues.add(new NameValuePair(Constants.LINK, link));
-
- if (name != null) {
- namesValues.add(new NameValuePair(Constants.NAME, name));
- }
- if (caption != null) {
- namesValues.add(new NameValuePair(Constants.CAPTION, caption));
- }
- if (description != null) {
- namesValues.add(new NameValuePair(Constants.DESCRIPTION, description));
- }
- if (message != null) {
- namesValues.add(new NameValuePair(Constants.MESSAGE, message));
- }
- if (icon != null) {
- namesValues.add(new NameValuePair(Constants.ICON, icon));
- }
- if (picture != null) {
- namesValues.add(new NameValuePair(Constants.PICTURE, picture));
- }
- if(privacy != null){
- namesValues.add(new NameValuePair(Constants.PRIVACY,"{\"value\":\""+privacy.toString()+"\"}"));
- }
-
- NameValuePair[] nameValuePairs = new NameValuePair[namesValues.size()];
- namesValues.toArray(nameValuePairs);
- caller.postData(Constants.FACEBOOK_GRAPH_URL + Constants.POST_LINK.replaceFirst("PROFILE_ID", "me"), nameValuePairs);
- }*/
-
- /**
- * Posts the given url on facebook <br>
- * Internally calls {@link Facebook#postLink(String, String, String, String, String)} with other
- * params null. If you want more control call that method
- *
- * @param link The URL to share
- * @throws FacebookException
- */
-/* @Deprecated
- public void postLink(String link) throws FacebookException {
- postLink(link, null, null, null, null, null, null,Value.EVERYONE);
- }*/
-
- /**
- * Data would be posted to the logged in users wall. Requires the publish_stream permission.
- *
- * @param wallPost
- * The data to be posted to the logged in users wall
- * @throws FacebookException
- */
-/* @Deprecated
- public void post(WallPost wallPost) throws FacebookException {
- post(wallPost, Constants.ME);
- }*/
-
- /**
- * Requires the publish_stream permission.
- *
- * To publish a wall post, POST the message and optional attachment to the feed/wall of the user,
- * page or group, i.e., http://graph.facebook.com/PROFILE_ID/feed. When publishing to a Page, to
- * target a post to users in a specific location or language, use the appropriate values from the
- * following files: all cities (CSV) {@link http://developers.facebook.com/attachment/all_cities_final.csv},
- * major cities (CSV) {@link http://developers.facebook.com/attachment/major_cities_final.csv},
- * locales (CSV) {@link http://developers.facebook.com/attachment/locales_final.csv},
- * cities and locales {@link http://developers.facebook.com/attachment/targeting_ids.json}
- *
- * @param wallPost
- * @param profileId
- * @throws FacebookException
- */
- /*@Deprecated
- public void post(WallPost wallPost, String profileId) throws FacebookException{
- List<NameValuePair> namesValues = new ArrayList<NameValuePair>();
- Gson gson = new Gson();
-
- namesValues.add(new NameValuePair(Constants.PARAM_ACCESS_TOKEN, this.authAccessToken.getAccessToken()));
-
- if(wallPost.getActions()!=null){
- namesValues.add(new NameValuePair(Constants.ACTIONS,gson.toJson(wallPost.getActions())));
- }
- if(wallPost.getCaption()!=null){
- namesValues.add(new NameValuePair(Constants.CAPTION,wallPost.getCaption()));
- }
- if(wallPost.getDescription()!=null){
- namesValues.add(new NameValuePair(Constants.DESCRIPTION,wallPost.getDescription()));
- }
- if(wallPost.getLink()!=null ){
- namesValues.add(new NameValuePair(Constants.LINK,wallPost.getLink()));
- }
- if(wallPost.getMessage()!=null){
- namesValues.add(new NameValuePair(Constants.MESSAGE, wallPost.getMessage()));
- }
- if(wallPost.getName()!=null){
- namesValues.add(new NameValuePair(Constants.NAME,wallPost.getName()));
- }
- if(wallPost.getPicture()!=null){
- namesValues.add(new NameValuePair(Constants.PICTURE,wallPost.getPicture()));
- }
- if(wallPost.getPrivacy()!=null){
- namesValues.add(new NameValuePair(Constants.PRIVACY,gson.toJson(wallPost.getPrivacy())));
- }
- if(wallPost.getSource()!=null){
- namesValues.add(new NameValuePair(Constants.SOURCE,wallPost.getSource()));
- }
- if(wallPost.getTargeting()!=null){
- namesValues.add(new NameValuePair(Constants.TARGETING,gson.toJson(wallPost.getPrivacy())));
- }
-
- NameValuePair[] nameValuePairs = new NameValuePair[namesValues.size()];
- namesValues.toArray(nameValuePairs);
- caller.postData(Constants.FACEBOOK_GRAPH_URL + Constants.POST_LINK.replaceFirst("PROFILE_ID", profileId), nameValuePairs);
- }*/
-
- public OAuthAccessToken getAuthAccessToken() {
- return authAccessToken;
- }
-
- private NameValuePair getNameValuePairAccessToken() {
- return new NameValuePair(Constants.PARAM_ACCESS_TOKEN, this.authAccessToken.getAccessToken());
- }
-
- /**
- * Publish a new post on the given profile's feed/wall
- *
- * @param message
- * (required)
- * @param picture
- * @param link
- * @param name
- * @param caption
- * @param description
- * @param source
- * @param profileId
- * The user id of the user on whose wall the message needs to be posted, if null then the
- * post would be posted on the authenticated users wall. If it's a page then page id.
- * @throws FacebookException
- */
- public void wallPost(String message, String picture, String link, String name, String caption, String description, String source, String profileId) throws FacebookException{
-
- List<NameValuePair> namesValues = new ArrayList<NameValuePair>();
-
- namesValues.add(new NameValuePair(Constants.PARAM_ACCESS_TOKEN, this.authAccessToken.getAccessToken()));
-
- if(profileId == null){
- profileId = Constants.ME;
- }
-
- if(message !=null){
- namesValues.add(new NameValuePair(Constants.MESSAGE,message));
- }
-
- if(picture != null){
- namesValues.add(new NameValuePair(Constants.PICTURE,picture));
- }
-
- if(link != null){
- namesValues.add(new NameValuePair(Constants.LINK,link));
- }
-
- if(name != null){
- namesValues.add(new NameValuePair(Constants.NAME,name));
- }
-
- if(caption != null){
- namesValues.add(new NameValuePair(Constants.CAPTION,caption));
- }
-
- if(description != null){
- namesValues.add(new NameValuePair(Constants.DESCRIPTION,description));
- }
-
- if(source != null){
- namesValues.add(new NameValuePair(Constants.SOURCE,source));
- }
-
- NameValuePair[] nameValuePairs = new NameValuePair[namesValues.size()];
- namesValues.toArray(nameValuePairs);
- caller.postData(Constants.FACEBOOK_GRAPH_URL + Constants.POST_FEED.replaceFirst(Constants.REPLACE_PROFILE_ID, profileId), nameValuePairs);
-
- }
-
- /**
- * Publish a link on the given profile
- * @param link (mandatory)
- * @param message
- * @param picture
- * @param name
- * @param caption
- * @param description
- * @param profileId user id or page id
- * @throws FacebookException
- */
- public void shareLink(String link, String message, String picture, String name, String caption, String description, String profileId) throws FacebookException{
-
- List<NameValuePair> namesValues = new ArrayList<NameValuePair>();
-
- namesValues.add(new NameValuePair(Constants.PARAM_ACCESS_TOKEN, this.authAccessToken.getAccessToken()));
-
- if(profileId == null){
- profileId = Constants.ME;
- }
-
- if(message !=null){
- namesValues.add(new NameValuePair(Constants.MESSAGE,message));
- }
-
- if(picture != null){
- namesValues.add(new NameValuePair(Constants.PICTURE,picture));
- }
-
- if(link != null){
- namesValues.add(new NameValuePair(Constants.LINK,link));
- }
-
- if(name != null){
- namesValues.add(new NameValuePair(Constants.NAME,name));
- }
-
- if(caption != null){
- namesValues.add(new NameValuePair(Constants.CAPTION,caption));
- }
-
- if(description != null){
- namesValues.add(new NameValuePair(Constants.DESCRIPTION,description));
- }
-
- NameValuePair[] nameValuePairs = new NameValuePair[namesValues.size()];
- namesValues.toArray(nameValuePairs);
- caller.postData(Constants.FACEBOOK_GRAPH_URL + Constants.POST_LINK.replaceFirst(Constants.REPLACE_PROFILE_ID, profileId), nameValuePairs);
-
- }
-
- /**
- * Comment on the given object (if it has a /comments connection)
- * @param message
- * @param objectId
- * @throws FacebookException
- */
- public void comment(String message, String objectId) throws FacebookException{
- List<NameValuePair> namesValues = new ArrayList<NameValuePair>();
-
- namesValues.add(new NameValuePair(Constants.PARAM_ACCESS_TOKEN, this.authAccessToken.getAccessToken()));
- namesValues.add(new NameValuePair(Constants.MESSAGE,message));
-
- NameValuePair[] nameValuePairs = new NameValuePair[namesValues.size()];
- namesValues.toArray(nameValuePairs);
- caller.postData(Constants.FACEBOOK_GRAPH_URL + Constants.POST_COMMENTS.replaceFirst(Constants.REPLACE_OBJECT_ID, objectId), nameValuePairs);
- }
-
- /**
- *
- * @param objectId
- * @throws FacebookException
- */
- public void like(String objectId) throws FacebookException {
- List<NameValuePair> namesValues = new ArrayList<NameValuePair>();
-
- namesValues.add(new NameValuePair(Constants.PARAM_ACCESS_TOKEN, this.authAccessToken.getAccessToken()));
-
- NameValuePair[] nameValuePairs = new NameValuePair[namesValues.size()];
- namesValues.toArray(nameValuePairs);
- caller.postData(Constants.FACEBOOK_GRAPH_URL + Constants.POST_LIKES.replaceFirst(Constants.REPLACE_OBJECT_ID, objectId), nameValuePairs);
- }
-
- /**
- * Publish a note on the given profile
- * @param message
- * @param subject
- * @param profileId
- * @throws FacebookException
- */
- public void createNote(String message, String subject, String profileId) throws FacebookException {
- List<NameValuePair> namesValues = new ArrayList<NameValuePair>();
-
- namesValues.add(new NameValuePair(Constants.PARAM_ACCESS_TOKEN, this.authAccessToken.getAccessToken()));
-
- if(message != null){
- namesValues.add(new NameValuePair(Constants.MESSAGE,message));
- }
-
- if(subject != null){
- namesValues.add(new NameValuePair(Constants.SUBJECT, subject));
- }
-
- NameValuePair[] nameValuePairs = new NameValuePair[namesValues.size()];
- namesValues.toArray(nameValuePairs);
- caller.postData(Constants.FACEBOOK_GRAPH_URL + Constants.POST_NOTES.replaceFirst(Constants.REPLACE_PROFILE_ID, profileId), nameValuePairs);
- }
-
- /**
- * Create an event
- * @param name
- * @param startTime
- * @param endTime
- * @param profileId If for a user then the users id, if for a page then the page id
- * @throws FacebookException
- */
- public void createEvent(String name, String startTime, String endTime, String profileId) throws FacebookException {
- List<NameValuePair> namesValues = new ArrayList<NameValuePair>();
-
- namesValues.add(new NameValuePair(Constants.PARAM_ACCESS_TOKEN, this.authAccessToken.getAccessToken()));
-
- if(profileId == null){
- profileId = Constants.ME;
- }
-
- if(name != null){
- namesValues.add(new NameValuePair(Constants.NAME,name));
- }
-
- if(startTime != null){
- namesValues.add(new NameValuePair(Constants.START_TIME, startTime));
- }
-
- if(endTime != null){
- namesValues.add(new NameValuePair(Constants.END_TIME, endTime));
- }
-
- NameValuePair[] nameValuePairs = new NameValuePair[namesValues.size()];
- namesValues.toArray(nameValuePairs);
- caller.postData(Constants.FACEBOOK_GRAPH_URL + Constants.POST_EVENTS.replaceFirst(Constants.REPLACE_PROFILE_ID, profileId), nameValuePairs);
- }
-
- /**
- * RSVP "attending" to the given event
- * @param eventId
- * @throws FacebookException
- */
- public void eventAttending(String eventId) throws FacebookException {
- List<NameValuePair> namesValues = new ArrayList<NameValuePair>();
-
- namesValues.add(new NameValuePair(Constants.PARAM_ACCESS_TOKEN, this.authAccessToken.getAccessToken()));
-
- NameValuePair[] nameValuePairs = new NameValuePair[namesValues.size()];
- namesValues.toArray(nameValuePairs);
- caller.postData(Constants.FACEBOOK_GRAPH_URL + Constants.POST_ATTENDING.replaceFirst(Constants.REPLACE_EVENT_ID, eventId), nameValuePairs);
- }
-
- /**
- * RSVP "maybe" to the given event
- * @param eventId
- * @throws FacebookException
- */
- public void eventMaybe(String eventId) throws FacebookException {
- List<NameValuePair> namesValues = new ArrayList<NameValuePair>();
-
- namesValues.add(new NameValuePair(Constants.PARAM_ACCESS_TOKEN, this.authAccessToken.getAccessToken()));
-
- NameValuePair[] nameValuePairs = new NameValuePair[namesValues.size()];
- namesValues.toArray(nameValuePairs);
- caller.postData(Constants.FACEBOOK_GRAPH_URL + Constants.POST_MAYBE.replaceFirst(Constants.REPLACE_EVENT_ID, eventId), nameValuePairs);
- }
-
- /**
- * RSVP "declined" to the given event
- * @param eventId
- * @throws FacebookException
- */
- public void eventDeclined(String eventId) throws FacebookException {
- List<NameValuePair> namesValues = new ArrayList<NameValuePair>();
-
- namesValues.add(new NameValuePair(Constants.PARAM_ACCESS_TOKEN, this.authAccessToken.getAccessToken()));
-
- NameValuePair[] nameValuePairs = new NameValuePair[namesValues.size()];
- namesValues.toArray(nameValuePairs);
- caller.postData(Constants.FACEBOOK_GRAPH_URL + Constants.POST_DECLINED.replaceFirst(Constants.REPLACE_EVENT_ID, eventId), nameValuePairs);
- }
-
- /**
- * Create an album
- * @param name
- * @param message
- * @param profileId
- * @throws FacebookException
- */
- public void createAlbum(String name, String message, String profileId) throws FacebookException {
- List<NameValuePair> namesValues = new ArrayList<NameValuePair>();
-
- namesValues.add(new NameValuePair(Constants.PARAM_ACCESS_TOKEN, this.authAccessToken.getAccessToken()));
-
- if(profileId == null){
- profileId = Constants.ME;
- }
-
- if(name != null){
- namesValues.add(new NameValuePair(Constants.NAME,name));
- }
-
- if(message != null){
- namesValues.add(new NameValuePair(Constants.MESSAGE, message));
- }
-
- NameValuePair[] nameValuePairs = new NameValuePair[namesValues.size()];
- namesValues.toArray(nameValuePairs);
- caller.postData(Constants.FACEBOOK_GRAPH_URL + Constants.POST_ALBUMS.replaceFirst(Constants.REPLACE_PROFILE_ID, profileId), nameValuePairs);
- }
-
- //TODO: Upload photo
- /*public void photos(String name, String message, String profileId) throws FacebookException {
- List<NameValuePair> namesValues = new ArrayList<NameValuePair>();
-
- namesValues.add(new NameValuePair(Constants.PARAM_ACCESS_TOKEN, this.authAccessToken.getAccessToken()));
-
- if(profileId == null){
- profileId = Constants.ME;
- }
-
- if(name != null){
- namesValues.add(new NameValuePair(Constants.NAME,name));
- }
-
- if(message != null){
- namesValues.add(new NameValuePair(Constants.MESSAGE, message));
- }
-
- NameValuePair[] nameValuePairs = new NameValuePair[namesValues.size()];
- namesValues.toArray(nameValuePairs);
- caller.postData(Constants.FACEBOOK_GRAPH_URL + Constants.POST_EVENTS.replaceFirst(Constants.REPLACE_PROFILE_ID, profileId), nameValuePairs);
- }*/
-
- //TODO: Publish Checkins
- /*public void checkins(String coordinates, String place, String message, String tags) throws FacebookException {
- List<NameValuePair> namesValues = new ArrayList<NameValuePair>();
-
- namesValues.add(new NameValuePair(Constants.PARAM_ACCESS_TOKEN, this.authAccessToken.getAccessToken()));
-
- if(profileId == null){
- profileId = Constants.ME;
- }
-
- if(name != null){
- namesValues.add(new NameValuePair(Constants.NAME,name));
- }
-
- if(message != null){
- namesValues.add(new NameValuePair(Constants.MESSAGE, message));
- }
-
- NameValuePair[] nameValuePairs = new NameValuePair[namesValues.size()];
- namesValues.toArray(nameValuePairs);
- caller.postData(Constants.FACEBOOK_GRAPH_URL + Constants.POST_CHECKINS.replaceFirst(Constants.REPLACE_PROFILE_ID, profileId), nameValuePairs);
- }*/
-
- public FqlPost[] newsFeed() throws FacebookException {
-
- List<StreamColumn> columnNames = new ArrayList<StreamColumn>();
-
- columnNames.add(StreamColumn.POST_ID);
- columnNames.add(StreamColumn.ACTOR_ID);
- columnNames.add(StreamColumn.TARGET_ID);
- columnNames.add(StreamColumn.VIEWER_ID);
- columnNames.add(StreamColumn.SOURCE_ID);
- columnNames.add(StreamColumn.MESSAGE);
- columnNames.add(StreamColumn.ATTACHMENT);
- columnNames.add(StreamColumn.UPDATED_TIME);
- columnNames.add(StreamColumn.CREATED_TIME);
- columnNames.add(StreamColumn.ATTRIBUTION);
- columnNames.add(StreamColumn.COMMENTS);
- columnNames.add(StreamColumn.LIKES);
- columnNames.add(StreamColumn.PERMALINK);
-
- return newsFeed(columnNames, null);
- }
-
- public FqlPost[] newsFeed(List<StreamColumn> columnNames, StreamColumnCriteria columnCriteria)
- throws FacebookException {
-
- //StringBuilder criteria = constructCriteria(columnCriteria);
- StringBuilder columnName = appendColumns(columnNames);
-
- String fqlQuery = "SELECT "
- + columnName.toString()
- + " FROM stream WHERE filter_key in (SELECT filter_key FROM stream_filter WHERE uid=me() AND type='newsfeed') ";
-
- if(columnCriteria!=null){
- fqlQuery += columnCriteria.toString();
- }
-
- NameValuePair[] nameValuePairs = { getNameValuePairAccessToken(), new NameValuePair("query", fqlQuery),
- new NameValuePair("format", "JSON") };
-
- String jsonResponse = caller.getData("https://api.facebook.com/method/fql.query", nameValuePairs);
-
- // fql currently sends empty arrays with {} but we need []
- jsonResponse = jsonResponse.replaceAll("\\{\\}", "[]");
-
- FqlPost[] fqlPosts = JSONToObjectTransformer.getObject(jsonResponse, FqlPost[].class);
-
- return fqlPosts;
- }
-
- /**
- * Retrieve an array of users with the fields that you specify. Uses the Fql API
- * @param columnNames
- * @param columnCriteria
- * @return
- * @throws FacebookException
- */
- public FqlUser[] fqlUsers(List<FqlUserColumn> columnNames, FqlUserColumnCriteria columnCriteria) throws FacebookException {
-
- StringBuilder columnName = appendColumns(columnNames);
-
- String fqlQuery = "SELECT "
- + columnName.toString()
- + " FROM user WHERE "
- + columnCriteria.toString();
-
- NameValuePair[] nameValuePairs = { getNameValuePairAccessToken(), new NameValuePair("query", fqlQuery),
- new NameValuePair("format", "JSON") };
-
- String jsonResponse = caller.getData("https://api.facebook.com/method/fql.query", nameValuePairs);
-
- // fql currently sends empty arrays with {} but we need []
- jsonResponse = jsonResponse.replaceAll("\\{\\}", "[]");
-
- FqlUser[] fqlUsers = JSONToObjectTransformer.getObject(jsonResponse, FqlUser[].class);
-
- return fqlUsers;
- }
-
- public FqlPage[] fqlPages(List<FqlPageColumn> columnNames, FqlPageColumnCriteria columnCriteria) throws FacebookException {
-
- StringBuilder columnName = appendColumns(columnNames);
-
- String fqlQuery = "SELECT "
- + columnName.toString()
- + " FROM page WHERE "
- + columnCriteria.toString();
-
- NameValuePair[] nameValuePairs = { getNameValuePairAccessToken(), new NameValuePair("query", fqlQuery),
- new NameValuePair("format", "JSON") };
-
- String jsonResponse = caller.getData("https://api.facebook.com/method/fql.query", nameValuePairs);
-
- // fql currently sends empty arrays with {} but we need []
- jsonResponse = jsonResponse.replaceAll("\\{\\}", "[]");
-
- FqlPage[] fqlUsers = JSONToObjectTransformer.getObject(jsonResponse, FqlPage[].class);
- return fqlUsers;
-
- }
-
- private <E> StringBuilder appendColumns(List<E> columnNames) {
- StringBuilder columnName = null;
- for (E column : columnNames) {
- if (columnName != null) {
- columnName.append(", " + column.toString());
- } else {
- columnName = new StringBuilder();
- columnName.append(column.toString());
- }
- }
- return columnName;
- }
-
- /*private StringBuilder constructCriteria(StreamColumnCriteria columnCriteria) {
-
- StringBuilder criteria = new StringBuilder();
-
- if (columnCriteria != null) {
-
- if (columnCriteria.isDefaultXid()) {
- criteria.append(" AND " + StreamColumn.XID.toString() + " = 'default'");
- } else if (columnCriteria.getXid() != null) {
- criteria.append(" AND " + StreamColumn.XID.toString() + " = " + columnCriteria.getXid());
- }
-
- if (columnCriteria.getActorId() != null) {
- criteria.append(" AND " + StreamColumn.ACTOR_ID.toString() + " = '" + columnCriteria.getActorId() + "'");
- }
-
- if (columnCriteria.getAppId() != null) {
- criteria.append(" AND " + StreamColumn.APP_ID.toString() + " = " + columnCriteria.getAppId());
- }
-
- if (columnCriteria.getAttribution() != null) {
- criteria.append(" AND " + StreamColumn.ATTRIBUTION.toString() + " = '" + columnCriteria.getAttribution() + "'");
- }
-
- if (columnCriteria.getCreatedTimeGreaterThan() != null) {
- criteria.append(" AND " + StreamColumn.CREATED_TIME.toString() + " > "
- + columnCriteria.getCreatedTimeGreaterThan());
- }
-
- if (columnCriteria.getCreatedTimeLessThan() != null) {
- criteria.append(" AND " + StreamColumn.CREATED_TIME.toString() + " < "
- + columnCriteria.getCreatedTimeLessThan());
- }
-
- if (columnCriteria.getFilterKey() != null) {
- criteria.append(" AND " + StreamColumn.FILTER_KEY.toString() + " = '" + columnCriteria.getFilterKey() + "'");
- }
-
- if (columnCriteria.getPostId() != null) {
- criteria.append(" AND " + StreamColumn.POST_ID.toString() + " = '" + columnCriteria.getPostId() + "'");
- }
-
- if (columnCriteria.getSourceId() != null) {
- criteria.append(" AND " + StreamColumn.SOURCE_ID.toString() + " = " + columnCriteria.getSourceId());
- }
-
- if (columnCriteria.getTargetId() != null) {
- criteria.append(" AND " + StreamColumn.TARGET_ID.toString() + " = '" + columnCriteria.getTargetId() + "'");
- }
-
- if (columnCriteria.getUpdatedTimeGreaterThan() != null) {
- criteria.append(" AND " + StreamColumn.UPDATED_TIME.toString() + " > "
- + columnCriteria.getUpdatedTimeGreaterThan());
- }
-
- if (columnCriteria.getUpdatedTimeLessThan() != null) {
- criteria.append(" AND " + StreamColumn.UPDATED_TIME.toString() + " < "
- + columnCriteria.getUpdatedTimeLessThan());
- }
-
- if (columnCriteria.getViewerId() != null) {
- criteria.append(" AND " + StreamColumn.VIEWER_ID.toString() + " = " + columnCriteria.getViewerId());
- }
-
- // We will always be passing this param
- // TODO: Do we need to always set this?
- if (columnCriteria.isShowHidden()) {
- criteria.append(" AND " + isHidden + " = 0 ");
- } else {
- // criteria.append(" AND " + isHidden + " = 1 ");
- }
-
- // This should be in the end
- if (columnCriteria.getLimit() != null) {
- criteria.append(" LIMIT " + columnCriteria.getLimit());
- }
-
- }
-
- return criteria;
- }*/
-
- public FqlConnection[] getConnection(List<ConnectionColumn> columnNames, ConnectionColumnCriteria columnCriteria)throws FacebookException {
-
- StringBuilder criteria = constructCriteria(columnCriteria);
- StringBuilder columnName = appendConnectionColumns(columnNames);
-
- String fqlQuery = "SELECT "
- + columnName.toString()
- + " FROM connection WHERE source_id = me() AND "
- + criteria.toString();
-
- NameValuePair[] nameValuePairs = { getNameValuePairAccessToken(), new NameValuePair("query", fqlQuery),
- new NameValuePair("format", "JSON") };
-
- String jsonResponse = caller.getData("https://api.facebook.com/method/fql.query", nameValuePairs);
-
- // fql currently sends empty arrays with {} but we need []
- jsonResponse = jsonResponse.replaceAll("\\{\\}", "[]");
-
- FqlConnection[] fqlConnection = JSONToObjectTransformer.getObject(jsonResponse, FqlConnection[].class);
-
- return fqlConnection;
- }
-
- private StringBuilder constructCriteria(ConnectionColumnCriteria columnCriteria) {
- StringBuilder criteria = new StringBuilder();
-
- if (columnCriteria != null) {
- if (columnCriteria.getTargetType() != null) {
- criteria.append(ConnectionColumn.TARGET_TYPE.toString() + " = '" + columnCriteria.getTargetType() + "'");
- }
-
- if (columnCriteria.getLimit() != null) {
- criteria.append(" LIMIT " + columnCriteria.getLimit());
- }
-
- if (columnCriteria.getOffset() != null){
- criteria.append(" OFFSET " + columnCriteria.getOffset());
- }
- }
- return criteria;
- }
-
- private StringBuilder appendConnectionColumns(List<ConnectionColumn> columnNames) {
- StringBuilder columnName = null;
- for (ConnectionColumn column : columnNames) {
- if (columnName != null) {
- columnName.append(", " + column.toString());
- } else {
- columnName = new StringBuilder();
- columnName.append(column.toString());
- }
- }
- return columnName;
- }
-
- /**
- * Returns a Post object containing all the details of a post. <br>
- * <b>Post</b> = An individual entry in a profile's feed. The read_stream extended permission is
- * required to access any information in a profile's feed that is not shared with everyone.
- *
- * @param postId
- * @return
- * @throws FacebookException
- */
- public Post getPost(String postId) throws FacebookException{
- NameValuePair[] nameValuePairs = { new NameValuePair(Constants.PARAM_ACCESS_TOKEN, this.authAccessToken.getAccessToken()) };
- return pullData(Constants.FACEBOOK_GRAPH_URL + "/" + postId, Post.class, nameValuePairs);
- }
-
- /**
- * Returns the appropriate object for the given connection type. Facebook objects, apart from
- * their fields have connections such as likes, comments etc. This method will return the
- * connections corresponding to the type that you specify
- *
- * @param <E>
- * @param id The facebook object id
- * @param connectionType Enum, send in what the type of the connection is
- * @param e
- * @param pagingCriteria
- * @return
- * @throws FacebookException
- */
- public <E> E getConnections(String id, ConnectionType connectionType, Class<E> e, Paging paging) throws FacebookException {
-
- NameValuePair[] nameValuePairs = constructNameValuePairs(paging);
-
- E t = pullData(Constants.FACEBOOK_GRAPH_URL + "/" + id + "/" + connectionType.getType(), e, nameValuePairs);
- touchPaging(t);
-
- return t;
- }
-
- public boolean delete(String id) throws FacebookException {
- NameValuePair[] nameValuePairs = constructNameValuePairs(null);
- return Boolean.parseBoolean(caller.deleteData(Constants.FACEBOOK_GRAPH_URL + "/" + id, nameValuePairs));
- }
-
- public boolean unlike(String id) throws FacebookException {
- NameValuePair[] nameValuePairs = constructNameValuePairs(null);
- return Boolean.parseBoolean(caller.deleteData(Constants.FACEBOOK_GRAPH_URL + "/" + id +"/likes", nameValuePairs));
- }
-
- /**
- * This has been done so that we touch the paging object inside the connection. Paging object contains private fields which need to be modfied.
- * The private fields get modified on calling any of the getters. This is needed because gson directly calls private fields. It does not call the
- * getters. Since the private fields depend on the getters, we are touching the getter so that private fields get initialized accordingly.
- *
- * @param <E>
- * @param e
- */
- private <E> void touchPaging(E e) {
- try {
- Class thisClass = Class.forName(e.getClass().getName());
-
- Method method = thisClass.getDeclaredMethod("getPaging");
-
- if (method != null) {
- Object paging = method.invoke(e);
-
- if (paging != null) {
- Class pagingClass = Class.forName(Paging.class.getName());
- Method pagingMethod = pagingClass.getDeclaredMethod("getLimit");
- if(pagingMethod != null){
- pagingMethod.invoke(paging);
- }
- }
- }
- } catch (SecurityException e1) {
- } catch (IllegalArgumentException e1) {
- } catch (ClassNotFoundException e1) {
- } catch (NoSuchMethodException e1) {
- } catch (IllegalAccessException e1) {
- } catch (InvocationTargetException e1) {
- } catch (Exception e1) {
- }
-
- }
-
-
- private NameValuePair[] constructNameValuePairs(Paging paging) {
- int i = 1;
- NameValuePair[] nameValuePairs = null;
-
- if (paging != null) {
- i += Paging.pagingElementCount(paging);
- nameValuePairs = new NameValuePair[i];
- Paging.addNameValuePairs(paging, nameValuePairs);
- } else {
- nameValuePairs = new NameValuePair[i];
- }
-
- nameValuePairs[i - 1] = new NameValuePair(Constants.PARAM_ACCESS_TOKEN, this.authAccessToken.getAccessToken());
- return nameValuePairs;
- }
-
-
- /**
- * Raw API method to pull any data in json form and transform it into the right object <br>
- * An HTTP GET method is used here
- *
- * @param <E>
- * @param url
- * @param e The class into which the json object returned by the url fetch needs to be cast
- * @param nameValuePairs Pass parameters that need to accompany the call
- * @return
- * @throws FacebookException
- */
- public <E> E pullData(String url, Class<E> e, NameValuePair[] nameValuePairs) throws FacebookException {
- // APICaller would retrieve the json string object from facebook by making a https call
- // Once the json string object is obtaind, it is passed to obj transformer and the right object
- // is retrieved
- return JSONToObjectTransformer.getObject(caller.getData(url, nameValuePairs), e);
- }
-
- /**
- * This method is useful when your json contains maps (key value pairs). Send in parameterized maps.<br>
- * Example: Type type = new TypeToken<Map<String, User>>(){}.getType();
- * @param <E>
- * @param url
- * @param type
- * @param nameValuePairs
- * @return
- * @throws FacebookException
- */
- public <E> E pullData(String url, Type type, NameValuePair[] nameValuePairs) throws FacebookException {
- // APICaller would retrieve the json string object from facebook by making a https call
- // Once the json string object is obtaind, it is passed to obj transformer and the right object
- // is retrieved
- return JSONToObjectTransformer.<E>getObject(caller.getData(url, nameValuePairs), type);
- }
-
-
-}
View
35 src/com/bit4j/facebook/criteria/ConnectionColumnCriteria.java
@@ -1,35 +0,0 @@
-package com.bit4j.facebook.criteria;
-
-import com.bit4j.facebook.enums.TargetType;
-
-public class ConnectionColumnCriteria {
-
- private TargetType targetType;
- private Integer limit;
- private Integer offset;
-
- public TargetType getTargetType() {
- return targetType;
- }
-
- public void setTargetType(TargetType targetType) {
- this.targetType = targetType;
- }
-
- public Integer getLimit() {
- return limit;
- }
-
- public void setLimit(Integer limit) {
- this.limit = limit;
- }
-
- public Integer getOffset() {
- return offset;
- }
-
- public void setOffset(Integer offset) {
- this.offset = offset;
- }
-
-}
View
54 src/com/bit4j/facebook/entity/Account.java
@@ -1,54 +0,0 @@
-package com.bit4j.facebook.entity;
-
-import java.io.Serializable;
-
-public class Account implements Serializable {
-
- private static final long serialVersionUID = -1879529230536226563L;
-
- private String id;
-
- private String name;
-
- private String category;
-
- private String accessToken;
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getCategory() {
- return category;
- }
-
- public void setCategory(String category) {
- this.category = category;
- }
-
- /**
- * Available if the 'manage_pages' permission has been granted
- *
- * @return
- */
- public String getAccessToken() {
- return accessToken;
- }
-
- public void setAccessToken(String accessToken) {
- this.accessToken = accessToken;
- }
-
-}
View
28 src/com/bit4j/facebook/entity/Action.java
@@ -1,28 +0,0 @@
-package com.bit4j.facebook.entity;
-
-import java.io.Serializable;
-
-public class Action implements Serializable{
-
- private static final long serialVersionUID = -5020763289760250506L;
-
- private String name;
- private String link;
-
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getLink() {
- return link;
- }
- public void setLink(String link) {
- this.link = link;
- }
-
-
-
-
-}
View
55 src/com/bit4j/facebook/entity/Activity.java
@@ -1,55 +0,0 @@
-package com.bit4j.facebook.entity;
-
-import java.io.Serializable;
-
-/**
- * The activity listed on the user's profile
- *
- * @author nischal
- *
- */
-public class Activity implements Serializable {
-
- private static final long serialVersionUID = 3163116507230732449L;
-
- private String id;
-
- private String name;
-
- private String category;
-
- private String createTime;
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getCategory() {
- return category;
- }
-
- public void setCategory(String category) {
- this.category = category;
- }
-
- public String getCreateTime() {
- return createTime;
- }
-
- public void setCreateTime(String createTime) {
- this.createTime = createTime;
- }
-
-}
View
328 src/com/bit4j/facebook/entity/Album.java
@@ -1,328 +0,0 @@
-package com.bit4j.facebook.entity;
-
-import java.io.Serializable;
-
-import com.bit4j.facebook.Facebook;
-import com.bit4j.facebook.entity.connection.Comments;
-import com.bit4j.facebook.entity.connection.Likes;
-import com.bit4j.facebook.entity.connection.Photos;
-import com.bit4j.facebook.entity.paging.Paging;
-import com.bit4j.facebook.enums.ConnectionType;
-import com.bit4j.facebook.exception.FacebookException;
-
-/**
- * A Photo album on facebook
- *
- * @author Nischal Shetty
- */
-public class Album implements Serializable {
-
- private static final long serialVersionUID = 1805429103365132266L;
-
- /**
- * The photo album ID
- */
- private String id;
-
- /**
- * An object containing the ID and name of the profile who posted this album
- */
- private From from;
-
- /**
- * The title of the album
- */
- private String name;
-
- /**
- * The description of the album
- */
- private