Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of https://github.com/twitter/twitter4j

  • Loading branch information...
commit 9f3943821842b04c535a5b0f5d7efce1f6ba2955 2 parents 1c24b0b + 90adbc8
tk authored
Showing with 854 additions and 661 deletions.
  1. +2 −13 package.sh
  2. +1 −1  pom.xml
  3. +2 −1  readme.txt
  4. +2 −2 twitter4j-appengine/pom.xml
  5. +1 −1  twitter4j-appengine/src/main/java/twitter4j/VersionAppEngine.java
  6. +2 −2 twitter4j-appengine/src/main/java/twitter4j/internal/json/z_T4JInternalLazyFactory.java
  7. +2 −2 twitter4j-async/pom.xml
  8. +36 −55 twitter4j-async/src/main/java/twitter4j/AsyncTwitterImpl.java
  9. +2 −9 twitter4j-async/src/main/java/twitter4j/TwitterAdapter.java
  10. +2 −10 twitter4j-async/src/main/java/twitter4j/TwitterListener.java
  11. +2 −3 twitter4j-async/src/main/java/twitter4j/TwitterMethod.java
  12. +1 −1  twitter4j-async/src/main/java/twitter4j/VersionAsync.java
  13. +23 −0 twitter4j-async/src/main/java/twitter4j/api/FavoriteMethodsAsync.java
  14. +2 −2 twitter4j-async/src/main/java/twitter4j/api/StatusMethodsAsync.java
  15. +2 −29 twitter4j-async/src/main/java/twitter4j/api/TrendsMethodsAsync.java
  16. +1 −5 twitter4j-async/src/test/java/twitter4j/AsyncTwitterTest.java
  17. +1 −1  twitter4j-core/pom.xml
  18. +54 −0 twitter4j-core/src/main/java/twitter4j/EntitySupport.java
  19. +5 −1 twitter4j-core/src/main/java/twitter4j/Query.java
  20. +2 −33 twitter4j-core/src/main/java/twitter4j/Status.java
  21. +90 −9 twitter4j-core/src/main/java/twitter4j/StatusUpdate.java
  22. +2 −1  twitter4j-core/src/main/java/twitter4j/Tweet.java
  23. +41 −32 twitter4j-core/src/main/java/twitter4j/TwitterImpl.java
  24. +0 −3  twitter4j-core/src/main/java/twitter4j/TwitterResponse.java
  25. +1 −1  twitter4j-core/src/main/java/twitter4j/Version.java
  26. +28 −0 twitter4j-core/src/main/java/twitter4j/api/FavoriteMethods.java
  27. +3 −8 twitter4j-core/src/main/java/twitter4j/api/StatusMethods.java
  28. +2 −35 twitter4j-core/src/main/java/twitter4j/api/TrendsMethods.java
  29. +2 −0  twitter4j-core/src/main/java/twitter4j/conf/Configuration.java
  30. +27 −9 twitter4j-core/src/main/java/twitter4j/conf/ConfigurationBase.java
  31. +4 −1 twitter4j-core/src/main/java/twitter4j/conf/PropertyConfiguration.java
  32. +2 −3 twitter4j-core/src/main/java/twitter4j/internal/http/HttpClientBase.java
  33. +36 −27 twitter4j-core/src/main/java/twitter4j/internal/json/StatusJSONImpl.java
  34. +88 −0 twitter4j-core/src/main/java/twitter4j/internal/json/TweetJSONImpl.java
  35. +17 −0 twitter4j-core/src/main/java/twitter4j/internal/json/z_T4JInternalFactory.java
  36. +6 −1 twitter4j-core/src/main/java/twitter4j/internal/json/z_T4JInternalJSONImplFactory.java
  37. +3 −3 twitter4j-core/src/test/java/twitter4j/HelpMethodsTest.java
  38. +10 −43 twitter4j-core/src/test/java/twitter4j/SearchAPITest.java
  39. +33 −21 twitter4j-core/src/test/java/twitter4j/StatusMethodsTest.java
  40. +6 −22 twitter4j-core/src/test/java/twitter4j/conf/ConfigurationTest.java
  41. +1 −1  twitter4j-examples/bin/account/getAccountSettings.sh
  42. +1 −1  twitter4j-examples/bin/account/getAccountTotals.sh
  43. +1 −1  twitter4j-examples/bin/account/getRateLimitStatus.sh
  44. +1 −1  twitter4j-examples/bin/account/updateProfile.sh
  45. +1 −1  twitter4j-examples/bin/account/updateProfileBackgroundImage.sh
  46. +1 −1  twitter4j-examples/bin/account/updateProfileColors.sh
  47. +1 −1  twitter4j-examples/bin/account/updateProfileImage.sh
  48. +1 −1  twitter4j-examples/bin/account/verifyCredentials.sh
  49. +1 −1  twitter4j-examples/bin/async/asyncUpdate.sh
  50. +1 −1  twitter4j-examples/bin/block/createBlock.sh
  51. +1 −1  twitter4j-examples/bin/block/destroyBlock.sh
  52. +1 −1  twitter4j-examples/bin/block/existsBlock.sh
  53. +1 −1  twitter4j-examples/bin/block/getBlockingUsers.sh
  54. +1 −1  twitter4j-examples/bin/block/getBlockingUsersIDs.sh
  55. +1 −1  twitter4j-examples/bin/directmessage/destroyDirectMessage.sh
  56. +1 −1  twitter4j-examples/bin/directmessage/getDirectMessages.sh
  57. +1 −1  twitter4j-examples/bin/directmessage/getSentDirectMessages.sh
  58. +1 −1  twitter4j-examples/bin/directmessage/sendDirectMessage.sh
  59. +1 −1  twitter4j-examples/bin/directmessage/showDirectMessage.sh
  60. +1 −1  twitter4j-examples/bin/favorite/createFavorite.sh
  61. +1 −1  twitter4j-examples/bin/favorite/destroyFavorite.sh
  62. +1 −1  twitter4j-examples/bin/favorite/getFavorites.sh
  63. +1 −1  twitter4j-examples/bin/friendsandfollowers/getFollowersIDs.sh
  64. +1 −1  twitter4j-examples/bin/friendsandfollowers/getFriendsIDs.sh
  65. +1 −1  twitter4j-examples/bin/friendship/createFriendship.sh
  66. +1 −1  twitter4j-examples/bin/friendship/destroyFriendship.sh
  67. +1 −1  twitter4j-examples/bin/friendship/existsFriendship.sh
  68. +1 −1  twitter4j-examples/bin/friendship/getIncomingFriendships.sh
  69. +1 −1  twitter4j-examples/bin/friendship/getOutgoingFriendships.sh
  70. +1 −1  twitter4j-examples/bin/friendship/lookupFriendships.sh
  71. +1 −1  twitter4j-examples/bin/friendship/showFriendship.sh
  72. +1 −1  twitter4j-examples/bin/friendship/updateFriendship.sh
  73. +1 −1  twitter4j-examples/bin/geo/createPlace.sh
  74. +1 −1  twitter4j-examples/bin/geo/getGeoDetails.sh
  75. +1 −1  twitter4j-examples/bin/geo/getSimilarPlaces.sh
  76. +1 −1  twitter4j-examples/bin/geo/reverseGeoCode.sh
  77. +1 −1  twitter4j-examples/bin/geo/searchPlaces.sh
  78. +1 −1  twitter4j-examples/bin/getAccessToken.sh
  79. +1 −1  twitter4j-examples/bin/help/test.sh
  80. +1 −1  twitter4j-examples/bin/json/loadRawJSON.sh
  81. +1 −1  twitter4j-examples/bin/json/saveRawJSON.sh
  82. +1 −1  twitter4j-examples/bin/legal/getPrivacyPolicy.sh
  83. +1 −1  twitter4j-examples/bin/legal/getTermsOfService.sh
  84. +1 −1  twitter4j-examples/bin/list/createUserList.sh
  85. +1 −1  twitter4j-examples/bin/list/destroyUserList.sh
  86. +1 −1  twitter4j-examples/bin/list/getAllUserLists.sh
  87. +1 −1  twitter4j-examples/bin/list/getUserListMemberships.sh
  88. +1 −1  twitter4j-examples/bin/list/getUserListStatuses.sh
  89. +1 −1  twitter4j-examples/bin/list/getUserListSubscriptions.sh
  90. +1 −1  twitter4j-examples/bin/list/getUserLists.sh
  91. +1 −1  twitter4j-examples/bin/list/showUserList.sh
  92. +1 −1  twitter4j-examples/bin/list/updateUserList.sh
  93. +1 −1  twitter4j-examples/bin/listmembers/addUserListMember.sh
  94. +1 −1  twitter4j-examples/bin/listmembers/addUserListMembers.sh
  95. +1 −1  twitter4j-examples/bin/listmembers/deleteUserListMember.sh
  96. +1 −1  twitter4j-examples/bin/listmembers/getUserListMembers.sh
  97. +1 −1  twitter4j-examples/bin/listmembers/showUserListMembership.sh
  98. +1 −1  twitter4j-examples/bin/listsubscribers/createUserListSubscription.sh
  99. +1 −1  twitter4j-examples/bin/listsubscribers/destroyUserListSubscription.sh
  100. +1 −1  twitter4j-examples/bin/listsubscribers/getUserListSubscribers.sh
  101. +1 −1  twitter4j-examples/bin/listsubscribers/showUserListSubscription.sh
  102. +1 −1  twitter4j-examples/bin/media/imgLyImageUpload.sh
  103. +1 −1  twitter4j-examples/bin/media/tweetPhotoImageUpload.sh
  104. +1 −1  twitter4j-examples/bin/media/twippleImageUpload.sh
  105. +1 −1  twitter4j-examples/bin/media/twitpicImageUpload.sh
  106. +1 −1  twitter4j-examples/bin/media/yFrogImageUpload.sh
  107. +1 −1  twitter4j-examples/bin/notification/disableNotification.sh
  108. +1 −1  twitter4j-examples/bin/notification/enableNotification.sh
  109. +1 −1  twitter4j-examples/bin/savedsearches/createSavedSearch.sh
  110. +1 −1  twitter4j-examples/bin/savedsearches/destroySavedSearch.sh
  111. +1 −1  twitter4j-examples/bin/savedsearches/getSavedSearches.sh
  112. +1 −1  twitter4j-examples/bin/savedsearches/showSavedSearch.sh
  113. +1 −1  twitter4j-examples/bin/search/searchTweets.sh
  114. +1 −1  twitter4j-examples/bin/spamreporting/reportSpam.sh
  115. +1 −1  twitter4j-examples/bin/stream/printFilterStream.sh
  116. +1 −1  twitter4j-examples/bin/stream/printFirehoseStream.sh
  117. +1 −1  twitter4j-examples/bin/stream/printLinksStream.sh
  118. +1 −1  twitter4j-examples/bin/stream/printRetweetStream.sh
  119. +1 −1  twitter4j-examples/bin/stream/printSampleStream.sh
  120. +1 −1  twitter4j-examples/bin/stream/printSiteStreams.sh
  121. +1 −1  twitter4j-examples/bin/stream/printUserStream.sh
  122. +1 −1  twitter4j-examples/bin/timeline/getFriendsTimeline.sh
  123. +1 −1  twitter4j-examples/bin/timeline/getHomeTimeline.sh
  124. +1 −1  twitter4j-examples/bin/timeline/getMentions.sh
  125. +1 −1  twitter4j-examples/bin/timeline/getPublicTimeline.sh
  126. +1 −1  twitter4j-examples/bin/timeline/getRetweetedByMe.sh
  127. +1 −1  twitter4j-examples/bin/timeline/getRetweetedByUser.sh
  128. +1 −1  twitter4j-examples/bin/timeline/getRetweetedToMe.sh
  129. +1 −1  twitter4j-examples/bin/timeline/getRetweetedToUser.sh
  130. +1 −1  twitter4j-examples/bin/timeline/getRetweetsOfMe.sh
  131. +1 −1  twitter4j-examples/bin/timeline/getUserTimeline.sh
  132. +1 −1  twitter4j-examples/bin/trends/getAvailableTrends.sh
  133. +0 −9 twitter4j-examples/bin/trends/getCurrentTrends.cmd
  134. +0 −7 twitter4j-examples/bin/trends/getCurrentTrends.sh
  135. +1 −1  twitter4j-examples/bin/trends/getDailyTrends.sh
  136. +1 −1  twitter4j-examples/bin/trends/getLocationTrends.sh
  137. +0 −9 twitter4j-examples/bin/trends/getTrends.cmd
  138. +0 −7 twitter4j-examples/bin/trends/getTrends.sh
  139. +1 −1  twitter4j-examples/bin/trends/getWeeklyTrends.sh
  140. +1 −1  twitter4j-examples/bin/tweets/destroyStatus.sh
  141. +1 −1  twitter4j-examples/bin/tweets/getRetweetedBy.sh
  142. +1 −1  twitter4j-examples/bin/tweets/getRetweetedByIds.sh
  143. +1 −1  twitter4j-examples/bin/tweets/getRetweets.sh
  144. +1 −1  twitter4j-examples/bin/tweets/retweetStatus.sh
  145. +1 −1  twitter4j-examples/bin/tweets/showStatus.sh
  146. +1 −1  twitter4j-examples/bin/tweets/updateStatus.sh
  147. +1 −1  twitter4j-examples/bin/user/getFollowersStatuses.sh
  148. +1 −1  twitter4j-examples/bin/user/getFriendsStatuses.sh
  149. +1 −1  twitter4j-examples/bin/user/getMemberSuggestions.sh
  150. +1 −1  twitter4j-examples/bin/user/getProfileImage.sh
  151. +1 −1  twitter4j-examples/bin/user/getSuggestedUserCategories.sh
  152. +1 −1  twitter4j-examples/bin/user/getUserSuggestions.sh
  153. +1 −1  twitter4j-examples/bin/user/lookupUsers.sh
  154. +1 −1  twitter4j-examples/bin/user/searchUsers.sh
  155. +1 −1  twitter4j-examples/bin/user/showUser.sh
  156. +5 −5 twitter4j-examples/pom.xml
  157. +0 −53 twitter4j-examples/src/main/java/twitter4j/examples/trends/GetCurrentTrends.java
  158. +0 −53 twitter4j-examples/src/main/java/twitter4j/examples/trends/GetTrends.java
  159. +2 −2 twitter4j-httpclient-support/pom.xml
  160. +1 −1  twitter4j-httpclient-support/src/main/java/twitter4j/internal/http/alternative/Version.java
  161. +2 −2 twitter4j-media-support/pom.xml
  162. +56 −4 twitter4j-media-support/src/main/java/twitter4j/media/AbstractImageUploadImpl.java
  163. +7 −3 twitter4j-media-support/src/main/java/twitter4j/media/ImageUploadFactory.java
  164. +1 −0  twitter4j-media-support/src/main/java/twitter4j/media/MediaProvider.java
  165. +83 −0 twitter4j-media-support/src/main/java/twitter4j/media/TwitterUpload.java
  166. +1 −1  twitter4j-media-support/src/main/java/twitter4j/media/Version.java
  167. +14 −0 twitter4j-media-support/src/test/java/twitter4j/media/MediaUploadTest.java
  168. +3 −3 twitter4j-stream/pom.xml
  169. +1 −1  twitter4j-stream/src/main/java/twitter4j/VersionStream.java
  170. +21 −0 twitter4j-stream/src/test/java/twitter4j/UserStreamTest.java
15 package.sh
View
@@ -1,19 +1,8 @@
+#!/bin/sh
LANG=C
export HASH=`git log|head -n 1|sed "s/^commit //g"`
-mkdir /tmp/t4jbuild
-cp -r ./* /tmp/t4jbuild/
-cd /tmp/t4jbuild/
-rm twitter4j-core/src/test/resources/test.properties
-rm twitter4j-core/src/test/resources/xauth-test.properties
-rm twitter4j-httpclient-support/src/test/resources/twitter4j.properties
-rm twitter4j-media-support/src/test/resources/twitter4j.properties
-rm twitter4j-async/src/test/resources/test.properties
-rm twitter4j-stream/src/test/resources/test.properties
-rm twitter4j-stream/src/test/resources/sitestream-test.properties
-rm twitter4j-appengine/src/test/resources/twitter4j.properties
-
sed -i '' "s/<url>http:\/\/oss.sonatype.org\/service\/local\/staging\/deploy\/maven2\//<url>file:\/Users\/yusukey\/maven2\//g" pom.xml
sed -i '' "s/<url>http:\/\/oss.sonatype.org\/service\/local\/staging\/deploy\/maven2\//<url>file:\/Users\/yusukey\/maven2\//g" twitter4j-core/pom.xml
sed -i '' "s/<url>http:\/\/oss.sonatype.org\/service\/local\/staging\/deploy\/maven2\//<url>file:\/Users\/yusukey\/maven2\//g" twitter4j-appengine/pom.xml
@@ -115,6 +104,7 @@ mkdir $DIR/twitter4j-appengine/javadoc/
unzip twitter4j-appengine/target/twitter4j-appengine-$1-javadoc.jar -d $DIR/twitter4j-appengine/javadoc/
cp twitter4j-appengine/target/twitter4j-appengine-$1-javadoc.jar -d $DIR/twitter4j-appengine/
cp twitter4j-appengine/target/twitter4j-appengine-$1-sources.jar -d $DIR/twitter4j-appengine/
+cp twitter4j-appengine/target/twitter4j-appengine-$1.jar -d $DIR/twitter4j-appengine/
mkdir $DIR/lib
cp readme-libs.txt $DIR/lib
@@ -123,7 +113,6 @@ cp twitter4j-media-support/target/twitter4j-media-support-$1.jar $DIR/lib
cp twitter4j-examples/target/twitter4j-examples-$1.jar $DIR/lib
cp twitter4j-async/target/twitter4j-async-$1.jar $DIR/lib
cp twitter4j-stream/target/twitter4j-stream-$1.jar $DIR/lib
-cp twitter4j-appengine/target/twitter4j-appengine-$1.jar $DIR/lib
cd $DIR/
find . -name ".svn" -print -exec rm -rf {} ";"
2  pom.xml
View
@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j</artifactId>
- <version>2.2.5-SNAPSHOT</version>
+ <version>2.2.6-SNAPSHOT</version>
<packaging>pom</packaging>
<name>twitter4j</name>
<description>A Java library for the Twitter API</description>
3  readme.txt
View
@@ -41,6 +41,7 @@ Perry Sakkaris <psakkaris at gmail.com>
Roberto Estrada <robestradac at gmail.com>
Roy Reshef <royreshef at gmail.com> @tsipo
Rui Silva
+Sam Pullara <sam at sampullara.com> @sampullara
Steve Lhomme <slhomme at matroska.org> @robux4
Rémy Rakic <remy.rakic at gmail.com> @lqd
Takao Nakaguchi <takao.nakaguchi at gmail.com> @takawitter
@@ -48,4 +49,4 @@ Tomohisa Igarashi <tm.igarashi at gmail.com>
Will Glozer <will at glozer.net> @ar3te
William Morgan <william at twitter.com> @wm
withgod <noname at withgod.jp> @withgod
-Yusuke Yamamoto <yusuke at mac.com> @yusukey
+Yusuke Yamamoto <yusuke at mac.com> @yusuke
4 twitter4j-appengine/pom.xml
View
@@ -3,7 +3,7 @@
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-appengine</artifactId>
- <version>2.2.5-SNAPSHOT</version>
+ <version>2.2.6-SNAPSHOT</version>
<packaging>jar</packaging>
<name>twitter4j-appengine</name>
<description>A Java library for the Twitter API</description>
@@ -96,7 +96,7 @@
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
- <version>2.2.5-SNAPSHOT</version>
+ <version>2.2.6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
2  twitter4j-appengine/src/main/java/twitter4j/VersionAppEngine.java
View
@@ -21,7 +21,7 @@
* @since Twitter4J 2.2.4
*/
public final class VersionAppEngine {
- private static final String VERSION = "2.2.5-SNAPSHOT";
+ private static final String VERSION = "2.2.6-SNAPSHOT";
private static final String TITLE = "Twitter4J App Engine Support";
private VersionAppEngine() {
4 twitter4j-appengine/src/main/java/twitter4j/internal/json/z_T4JInternalLazyFactory.java
View
@@ -223,8 +223,8 @@ public Place createPlace(HttpResponse res) throws TwitterException {
};
}
- public ResponseList<Place> createEmptyPlaceList() {
- return new ResponseListImpl<Place>(0, null);
+ public <T> ResponseList<T> createEmptyResponseList() {
+ return new ResponseListImpl<T>(0, null);
}
public SimilarPlaces createSimilarPlaces(HttpResponse res) throws TwitterException {
4 twitter4j-async/pom.xml
View
@@ -3,7 +3,7 @@
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-async</artifactId>
- <version>2.2.5-SNAPSHOT</version>
+ <version>2.2.6-SNAPSHOT</version>
<packaging>jar</packaging>
<name>twitter4j-async</name>
<description>A Java library for the Twitter API</description>
@@ -96,7 +96,7 @@
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
- <version>2.2.5-SNAPSHOT</version>
+ <version>2.2.6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
91 twitter4j-async/src/main/java/twitter4j/AsyncTwitterImpl.java
View
@@ -1,5 +1,6 @@
/*
- * Copyright 2007 Yusuke Yamamoto
+ * Copyright (C) 2007 Yusuke Yamamoto
+ * Copyright (C) 2011 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -81,60 +82,6 @@ public void invoke(List<TwitterListener> listeners) throws TwitterException {
/**
* {@inheritDoc}
*/
- public void getTrends() {
- getDispatcher().invokeLater(new AsyncTask(TRENDS, listeners) {
- public void invoke(List<TwitterListener> listeners) throws
- TwitterException {
- Trends trends = twitter.getTrends();
- for (TwitterListener listener : listeners) {
- try {
- listener.gotTrends(trends);
- } catch (Exception ignore) {
- }
- }
- }
- });
- }
-
- /**
- * {@inheritDoc}
- */
- public void getCurrentTrends() {
- getDispatcher().invokeLater(new AsyncTask(CURRENT_TRENDS, listeners) {
- public void invoke(List<TwitterListener> listeners) throws
- TwitterException {
- Trends trends = twitter.getCurrentTrends();
- for (TwitterListener listener : listeners) {
- try {
- listener.gotCurrentTrends(trends);
- } catch (Exception ignore) {
- }
- }
- }
- });
- }
-
- /**
- * {@inheritDoc}
- */
- public void getCurrentTrends(final boolean excludeHashTags) {
- getDispatcher().invokeLater(new AsyncTask(CURRENT_TRENDS, listeners) {
- public void invoke(List<TwitterListener> listeners) throws
- TwitterException {
- Trends trends = twitter.getCurrentTrends(excludeHashTags);
- for (TwitterListener listener : listeners) {
- try {
- listener.gotCurrentTrends(trends);
- } catch (Exception ignore) {
- }
- }
- }
- });
- }
-
- /**
- * {@inheritDoc}
- */
public void getDailyTrends() {
getDispatcher().invokeLater(new AsyncTask(DAILY_TRENDS, listeners) {
public void invoke(List<TwitterListener> listeners) throws
@@ -2277,6 +2224,40 @@ public void invoke(List<TwitterListener> listeners) throws TwitterException {
/**
* {@inheritDoc}
*/
+ public void getFavorites(final Paging paging) {
+ getDispatcher().invokeLater(new AsyncTask(FAVORITES, listeners) {
+ public void invoke(List<TwitterListener> listeners) throws TwitterException {
+ ResponseList<Status> statuses = twitter.getFavorites(paging);
+ for (TwitterListener listener : listeners) {
+ try {
+ listener.gotFavorites(statuses);
+ } catch (Exception ignore) {
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void getFavorites(final String id, final Paging paging) {
+ getDispatcher().invokeLater(new AsyncTask(FAVORITES, listeners) {
+ public void invoke(List<TwitterListener> listeners) throws TwitterException {
+ ResponseList<Status> statuses = twitter.getFavorites(id, paging);
+ for (TwitterListener listener : listeners) {
+ try {
+ listener.gotFavorites(statuses);
+ } catch (Exception ignore) {
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public void createFavorite(final long id) {
getDispatcher().invokeLater(new AsyncTask(CREATE_FAVORITE, listeners) {
public void invoke(List<TwitterListener> listeners) throws TwitterException {
11 twitter4j-async/src/main/java/twitter4j/TwitterAdapter.java
View
@@ -1,5 +1,6 @@
/*
- * Copyright 2007 Yusuke Yamamoto
+ * Copyright (C) 2007 Yusuke Yamamoto
+ * Copyright (C) 2011 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,8 +19,6 @@
import twitter4j.api.HelpMethods;
-import java.util.List;
-
/**
* A handy adapter of TwitterListener.
*
@@ -38,12 +37,6 @@ public void searched(QueryResult result) {
/**
* @since Twitter4J 2.0.2
*/
- public void gotTrends(Trends trends) {
- }
-
- /**
- * @since Twitter4J 2.0.2
- */
public void gotCurrentTrends(Trends trends) {
}
12 twitter4j-async/src/main/java/twitter4j/TwitterListener.java
View
@@ -1,5 +1,6 @@
/*
- * Copyright 2007 Yusuke Yamamoto
+ * Copyright (C) 2007 Yusuke Yamamoto
+ * Copyright (C) 2011 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,8 +19,6 @@
import twitter4j.api.HelpMethods;
-import java.util.List;
-
/**
* A listner for receiving asynchronous responses from Twitter Async APIs.
*
@@ -34,11 +33,6 @@
/**
* @since Twitter4J 2.0.2
*/
- void gotTrends(Trends trends);
-
- /**
- * @since Twitter4J 2.0.2
- */
void gotCurrentTrends(Trends trends);
/**
@@ -482,8 +476,6 @@
/*Search API Methods*/
TwitterMethod SEARCH = TwitterMethod.SEARCH;
- TwitterMethod TRENDS = TwitterMethod.TRENDS;
- TwitterMethod CURRENT_TRENDS = TwitterMethod.CURRENT_TRENDS;
TwitterMethod DAILY_TRENDS = TwitterMethod.DAILY_TRENDS;
TwitterMethod WEEKLY_TRENDS = TwitterMethod.WEEKLY_TRENDS;
5 twitter4j-async/src/main/java/twitter4j/TwitterMethod.java
View
@@ -1,5 +1,6 @@
/*
- * Copyright 2007 Yusuke Yamamoto
+ * Copyright (C) 2007 Yusuke Yamamoto
+ * Copyright (C) 2011 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -78,8 +79,6 @@ private Object readResolve() throws ObjectStreamException {
/*Search API Methods*/
public static final TwitterMethod SEARCH = getInstance("SEARCH");
- public static final TwitterMethod TRENDS = new TwitterMethod("TRENDS");
- public static final TwitterMethod CURRENT_TRENDS = new TwitterMethod("CURRENT_TRENDS");
public static final TwitterMethod DAILY_TRENDS = new TwitterMethod("DAILY_TRENDS");
public static final TwitterMethod WEEKLY_TRENDS = new TwitterMethod("WEEKLY_TRENDS");
2  twitter4j-async/src/main/java/twitter4j/VersionAsync.java
View
@@ -20,7 +20,7 @@
* @author Yusuke Yamamoto - yusuke at mac.com
*/
public final class VersionAsync {
- private static final String VERSION = "2.2.5-SNAPSHOT";
+ private static final String VERSION = "2.2.6-SNAPSHOT";
private static final String TITLE = "Twitter4J Async API";
private VersionAsync() {
23 twitter4j-async/src/main/java/twitter4j/api/FavoriteMethodsAsync.java
View
@@ -16,6 +16,8 @@
package twitter4j.api;
+import twitter4j.Paging;
+
/**
* @author Joern Huxhorn - jhuxhorn at googlemail.com
*/
@@ -61,6 +63,27 @@
void getFavorites(String id, int page);
/**
+ * Returns the 20 most recent favorite statuses for the authenticating user or user specified by the ID parameter in the requested format.
+ * <br>This method calls http://api.twitter.com/1/favorites.json
+ *
+ * @param paging controls pagination. Supports sinceId and page parameters.
+ * @see <a href="https://dev.twitter.com/docs/api/1/get/favorites">GET favorites | Twitter Developers</a>
+ * @since Twitter4J 2.2.5
+ */
+ void getFavorites(Paging paging);
+
+ /**
+ * Returns the 20 most recent favorite statuses for the authenticating user or user specified by the ID parameter in the requested format.
+ * <br>This method calls http://api.twitter.com/1/favorites/[id].json
+ *
+ * @param id the ID or screen name of the user for whom to request a list of favorite statuses
+ * @param paging controls pagination. Supports sinceId and page parameters.
+ * @see <a href="https://dev.twitter.com/docs/api/1/get/favorites">GET favorites | Twitter Developers</a>
+ * @since Twitter4J 2.2.5
+ */
+ void getFavorites(String id, Paging paging);
+
+ /**
* Favorites the status specified in the ID parameter as the authenticating user. Returns the favorite status when successful.
* <br>This method calls http://api.twitter.com/1/favorites/create%C2%A0
*
4 twitter4j-async/src/main/java/twitter4j/api/StatusMethodsAsync.java
View
@@ -48,11 +48,11 @@
* <br>Statuses over 140 characters will be forcibly truncated.
* <br>This method calls http://api.twitter.com/1/statuses/update
*
- * @param latestStatus the latest status to be updated.
+ * @param status the latest status to be updated.
* @see <a href="https://dev.twitter.com/docs/api/1/post/statuses/update">POST statuses/update | Twitter Developers</a>
* @since Twitter4J 2.1.1
*/
- void updateStatus(StatusUpdate latestStatus);
+ void updateStatus(StatusUpdate status);
/**
* Destroys the status specified by the required ID parameter.<br>
31 twitter4j-async/src/main/java/twitter4j/api/TrendsMethodsAsync.java
View
@@ -1,5 +1,6 @@
/*
- * Copyright 2007 Yusuke Yamamoto
+ * Copyright (C) 2007 Yusuke Yamamoto
+ * Copyright (C) 2011 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,34 +25,6 @@
*/
public interface TrendsMethodsAsync {
/**
- * Returns the top ten topics that are currently trending on Twitter. The response includes the time of the request, the name of each trend, and the url to the Twitter Search results page for that topic.
- * <br>This method calls http://search.twitter.com/trends.json
- *
- * @see <a href="https://dev.twitter.com/docs/api/1/get/trends">GET trends | Twitter Developers</a>
- * @since Twitter4J 2.0.2
- */
- void getTrends();
-
- /**
- * Returns the current top 10 trending topics on Twitter. The response includes the time of the request, the name of each trending topic, and query used on Twitter Search results page for that topic.
- * <br>This method calls http://search.twitter.com/trends/current.json
- *
- * @see <a href="https://dev.twitter.com/docs/api/1/get/trends/current">GET trends/current | Twitter Developers</a>
- * @since Twitter4J 2.0.2
- */
- void getCurrentTrends();
-
- /**
- * Returns the current top 10 trending topics on Twitter. The response includes the time of the request, the name of each trending topic, and query used on Twitter Search results page for that topic.
- * <br>This method calls http://search.twitter.com/trends/current.json
- *
- * @param excludeHashTags Setting this to true will remove all hashtags from the trends list.
- * @see <a href="https://dev.twitter.com/docs/api/1/get/trends/current">GET trends/current | Twitter Developers</a>
- * @since Twitter4J 2.0.2
- */
- void getCurrentTrends(boolean excludeHashTags);
-
- /**
* Returns the top 20 trending topics for each hour in a given day.
* <br>This method calls http://search.twitter.com/trends/daily.json
*
6 twitter4j-async/src/test/java/twitter4j/AsyncTwitterTest.java
View
@@ -20,11 +20,7 @@
import twitter4j.api.HelpMethods;
import twitter4j.json.DataObjectFactory;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
+import java.io.*;
import java.util.Date;
import java.util.List;
2  twitter4j-core/pom.xml
View
@@ -3,7 +3,7 @@
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
- <version>2.2.5-SNAPSHOT</version>
+ <version>2.2.6-SNAPSHOT</version>
<packaging>jar</packaging>
<name>twitter4j-core</name>
<description>A Java library for the Twitter API</description>
54 twitter4j-core/src/main/java/twitter4j/EntitySupport.java
View
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2007 Yusuke Yamamoto
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package twitter4j;
+
+/**
+ * @author Yusuke Yamamoto - yusuke at mac.com
+ * @since Twitter4J 2.2.5
+ */
+public interface EntitySupport {
+ /**
+ * Returns an array of user mentions in the tweet, or null if no users were mentioned.
+ *
+ * @return An array of user mention entities in the tweet.
+ * @since Twitter4J 2.1.9
+ */
+ UserMentionEntity[] getUserMentionEntities();
+
+ /**
+ * Returns an array if URLEntity mentioned in the tweet, or null if no URLs were mentioned.
+ *
+ * @return An array of URLEntity mentioned in the tweet.
+ * @since Twitter4J 2.1.9
+ */
+ URLEntity[] getURLEntities();
+
+ /**
+ * Returns an array if hashtag mentioned in the tweet, or null if no hashtag were mentioned.
+ *
+ * @return An array of Hashtag mentioned in the tweet.
+ * @since Twitter4J 2.1.9
+ */
+ HashtagEntity[] getHashtagEntities();
+
+ /**
+ * Returns an array of MediaEntities if medias are available in the tweet, or null if no media is included in the tweet.
+ *
+ * @return an array of MediaEntities.
+ * @since Twitter4J 2.2.3
+ */
+ MediaEntity[] getMediaEntities();
+}
6 twitter4j-core/src/main/java/twitter4j/Query.java
View
@@ -413,7 +413,9 @@ public Query resultType(String resultType) {
return this;
}
- /*package*/ HttpParameter[] asHttpParameterArray() {
+ private static HttpParameter WITH_TWITTER_USER_ID = new HttpParameter("with_twitter_user_id", "true");
+
+ /*package*/ HttpParameter[] asHttpParameterArray(HttpParameter includeEntities) {
ArrayList<HttpParameter> params = new ArrayList<HttpParameter>();
appendParameter("q", query, params);
appendParameter("lang", lang, params);
@@ -426,6 +428,8 @@ public Query resultType(String resultType) {
appendParameter("geocode", geocode, params);
appendParameter("until", until, params);
appendParameter("result_type", resultType, params);
+ params.add(WITH_TWITTER_USER_ID);
+ params.add(includeEntities);
HttpParameter[] paramArray = new HttpParameter[params.size()];
return params.toArray(paramArray);
}
35 twitter4j-core/src/main/java/twitter4j/Status.java
View
@@ -23,7 +23,8 @@
*
* @author Yusuke Yamamoto - yusuke at mac.com
*/
-public interface Status extends Comparable<Status>, TwitterResponse, java.io.Serializable {
+public interface Status extends Comparable<Status>, TwitterResponse,
+ EntitySupport, java.io.Serializable {
/**
* Return the created_at
*
@@ -155,42 +156,10 @@
boolean isRetweetedByMe();
/**
- * Returns an array of user mentions in the tweet, or null if no users were mentioned.
- *
- * @return An array of user mention entities in the tweet.
- * @since Twitter4J 2.1.9
- */
- UserMentionEntity[] getUserMentionEntities();
-
- /**
- * Returns an array if URLEntity mentioned in the tweet, or null if no URLs were mentioned.
- *
- * @return An array of URLEntity mentioned in the tweet.
- * @since Twitter4J 2.1.9
- */
- URLEntity[] getURLEntities();
-
- /**
- * Returns an array if hashtag mentioned in the tweet, or null if no hashtag were mentioned.
- *
- * @return An array of Hashtag mentioned in the tweet.
- * @since Twitter4J 2.1.9
- */
- HashtagEntity[] getHashtagEntities();
-
- /**
* Returns the annotations, or null if no annotations are associated with this status.
*
* @since Twitter4J 2.1.4
* @deprecated Annotations is not available for now. <a href="http://groups.google.com/group/twitter-development-talk/browse_thread/thread/4d5ff2ec4d2ce4a7">Annotations - Twitter Development Talk | Google Groups</a>
*/
Annotations getAnnotations();
-
- /**
- * Returns an array of MediaEntities if medias are available in the tweet, or null if no media is included in the tweet.
- *
- * @return an array of MediaEntities.
- * @since Twitter4J 2.2.3
- */
- MediaEntity[] getMediaEntities();
}
99 twitter4j-core/src/main/java/twitter4j/StatusUpdate.java
View
@@ -18,6 +18,8 @@
import twitter4j.internal.http.HttpParameter;
+import java.io.File;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
@@ -33,6 +35,10 @@
private String placeId = null;
private boolean displayCoordinates = true;
private Annotations annotations = null;
+ private boolean possiblySensitive;
+ private String mediaName;
+ private transient InputStream mediaBody;
+ private File mediaFile;
private static final long serialVersionUID = -3595502688477609916L;
public StatusUpdate(String status) {
@@ -95,6 +101,63 @@ public StatusUpdate displayCoordinates(boolean displayCoordinates) {
return this;
}
+ /**
+ * @since Twitter4J 2.2.5
+ */
+ public void setMedia(File file){
+ this.mediaFile = file;
+ }
+
+ /**
+ * @since Twitter4J 2.2.5
+ */
+ public StatusUpdate media(File file){
+ setMedia(file);
+ return this;
+ }
+
+ /**
+ * @since Twitter4J 2.2.5
+ */
+ public void setMedia(String name, InputStream body){
+ this.mediaName = name;
+ this.mediaBody = body;
+ }
+
+ /*package*/ boolean isWithMedia(){
+ return mediaFile != null || mediaName != null;
+ }
+
+ /**
+ * @since Twitter4J 2.2.5
+ */
+ public StatusUpdate media(String name, InputStream body){
+ setMedia(name, body);
+ return this;
+ }
+
+ /**
+ * @since Twitter4J 2.2.5
+ */
+ public void setPossiblySensitive(boolean possiblySensitive){
+ this.possiblySensitive = possiblySensitive;
+ }
+
+ /**
+ * @since Twitter4J 2.2.5
+ */
+ public StatusUpdate possiblySensitive(boolean possiblySensitive){
+ setPossiblySensitive(possiblySensitive);
+ return this;
+ }
+
+ /**
+ * @since Twitter4J 2.2.5
+ */
+ public boolean isPossiblySensitive(){
+ return possiblySensitive;
+ }
+
public Annotations getAnnotations() {
return annotations;
}
@@ -120,7 +183,7 @@ public StatusUpdate annotation(Annotation annotation) {
return this;
}
- /*package*/ HttpParameter[] asHttpParameterArray() {
+ /*package*/ HttpParameter[] asHttpParameterArray(HttpParameter includeEntities) {
ArrayList<HttpParameter> params = new ArrayList<HttpParameter>();
appendParameter("status", status, params);
if (-1 != inReplyToStatusId) {
@@ -138,6 +201,15 @@ public StatusUpdate annotation(Annotation annotation) {
if ((annotations != null) && (!annotations.isEmpty())) {
appendParameter("annotations", annotations.asParameterValue(), params);
}
+ params.add(includeEntities);
+ if(null != mediaFile){
+ params.add(new HttpParameter("media[]", mediaFile));
+ params.add(new HttpParameter("possibly_sensitive", possiblySensitive));
+ }else if(mediaName != null && mediaBody != null){
+ params.add(new HttpParameter("media[]", mediaName, mediaBody));
+ params.add(new HttpParameter("possibly_sensitive", possiblySensitive));
+ }
+
HttpParameter[] paramArray = new HttpParameter[params.size()];
return params.toArray(paramArray);
}
@@ -165,25 +237,30 @@ public boolean equals(Object o) {
if (displayCoordinates != that.displayCoordinates) return false;
if (inReplyToStatusId != that.inReplyToStatusId) return false;
- if (location != null ? !location.equals(that.location) : that.location != null)
- return false;
- if (placeId != null ? !placeId.equals(that.placeId) : that.placeId != null)
- return false;
- if (annotations != null ? !annotations.equals(that.annotations) : that.annotations != null)
- return false;
- if (!status.equals(that.status)) return false;
+ if (possiblySensitive != that.possiblySensitive) return false;
+ if (annotations != null ? !annotations.equals(that.annotations) : that.annotations != null) return false;
+ if (location != null ? !location.equals(that.location) : that.location != null) return false;
+ if (mediaBody != null ? !mediaBody.equals(that.mediaBody) : that.mediaBody != null) return false;
+ if (mediaFile != null ? !mediaFile.equals(that.mediaFile) : that.mediaFile != null) return false;
+ if (mediaName != null ? !mediaName.equals(that.mediaName) : that.mediaName != null) return false;
+ if (placeId != null ? !placeId.equals(that.placeId) : that.placeId != null) return false;
+ if (status != null ? !status.equals(that.status) : that.status != null) return false;
return true;
}
@Override
public int hashCode() {
- int result = status.hashCode();
+ int result = status != null ? status.hashCode() : 0;
result = 31 * result + (int) (inReplyToStatusId ^ (inReplyToStatusId >>> 32));
result = 31 * result + (location != null ? location.hashCode() : 0);
result = 31 * result + (placeId != null ? placeId.hashCode() : 0);
result = 31 * result + (displayCoordinates ? 1 : 0);
result = 31 * result + (annotations != null ? annotations.hashCode() : 0);
+ result = 31 * result + (possiblySensitive ? 1 : 0);
+ result = 31 * result + (mediaName != null ? mediaName.hashCode() : 0);
+ result = 31 * result + (mediaBody != null ? mediaBody.hashCode() : 0);
+ result = 31 * result + (mediaFile != null ? mediaFile.hashCode() : 0);
return result;
}
@@ -196,6 +273,10 @@ public String toString() {
", placeId='" + placeId + '\'' +
", displayCoordinates=" + displayCoordinates +
", annotations=" + annotations +
+ ", possiblySensitive=" + possiblySensitive +
+ ", mediaName='" + mediaName + '\'' +
+ ", mediaBody=" + mediaBody +
+ ", mediaFile=" + mediaFile +
'}';
}
}
3  twitter4j-core/src/main/java/twitter4j/Tweet.java
View
@@ -23,7 +23,8 @@
*
* @author Yusuke Yamamoto - yusuke at mac.com
*/
-public interface Tweet extends Comparable<Tweet>, java.io.Serializable {
+public interface Tweet extends Comparable<Tweet>, EntitySupport,
+ java.io.Serializable {
/**
* returns the text
*
73 twitter4j-core/src/main/java/twitter4j/TwitterImpl.java
View
@@ -1,5 +1,6 @@
/*
- * Copyright 2007 Yusuke Yamamoto
+ * Copyright (C) 2007 Yusuke Yamamoto
+ * Copyright (C) 2011 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -95,29 +96,7 @@
*/
public QueryResult search(Query query) throws TwitterException {
return factory.createQueryResult(get(conf.getSearchBaseURL()
- + "search.json", query.asHttpParameterArray()), query);
- }
-
- /**
- * {@inheritDoc}
- */
- public Trends getTrends() throws TwitterException {
- return factory.createTrends(get(conf.getRestBaseURL() + "trends.json"));
- }
-
- /**
- * {@inheritDoc}
- */
- public Trends getCurrentTrends() throws TwitterException {
- return factory.createTrendsList(get(conf.getRestBaseURL() + "trends/current.json")).get(0);
- }
-
- /**
- * {@inheritDoc}
- */
- public Trends getCurrentTrends(boolean excludeHashTags) throws TwitterException {
- return factory.createTrendsList(get(conf.getRestBaseURL() + "trends/current.json"
- + (excludeHashTags ? "?exclude=hashtags" : ""))).get(0);
+ + "search.json", query.asHttpParameterArray(INCLUDE_ENTITIES)), query);
}
/**
@@ -188,7 +167,7 @@ private String toDateStr(Date date) {
TwitterException {
ensureAuthorizationEnabled();
return factory.createStatusList(get(conf.getRestBaseURL()
- + "statuses/home_timeline.json", mergeParameters(paging.asPostParameterArray(), new HttpParameter[] {INCLUDE_ENTITIES, INCLUDE_MY_RETWEET})));
+ + "statuses/home_timeline.json", mergeParameters(paging.asPostParameterArray(), new HttpParameter[]{INCLUDE_ENTITIES, INCLUDE_MY_RETWEET})));
}
/**
@@ -459,12 +438,13 @@ public Status updateStatus(String status) throws TwitterException {
/**
* {@inheritDoc}
*/
- public Status updateStatus(StatusUpdate latestStatus) throws TwitterException {
+ public Status updateStatus(StatusUpdate status) throws TwitterException {
ensureAuthorizationEnabled();
- return factory.createStatus(post(conf.getRestBaseURL()
- + "statuses/update.json",
- mergeParameters(latestStatus.asHttpParameterArray(),
- INCLUDE_ENTITIES)));
+ String url = status.isWithMedia() ?
+ conf.getUploadBaseURL() + "statuses/update_with_media.json" :
+ conf.getRestBaseURL() + "statuses/update.json";
+ return factory.createStatus(post(url,
+ status.asHttpParameterArray(INCLUDE_ENTITIES)));
}
/**
@@ -1493,6 +1473,27 @@ private void checkFileValidity(File image) throws TwitterException {
/**
* {@inheritDoc}
*/
+ public ResponseList<Status> getFavorites(Paging paging) throws TwitterException {
+ ensureAuthorizationEnabled();
+ return factory.createStatusList(get(conf.getRestBaseURL() + "favorites.json",
+ mergeParameters(paging.asPostParameterArray()
+ , INCLUDE_ENTITIES)));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ResponseList<Status> getFavorites(String id, Paging paging) throws TwitterException {
+ ensureAuthorizationEnabled();
+ return factory.createStatusList(get(conf.getRestBaseURL() + "favorites/" + id + ".json",
+ mergeParameters(paging.asPostParameterArray()
+ , INCLUDE_ENTITIES)));
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
public Status createFavorite(long id) throws TwitterException {
ensureAuthorizationEnabled();
return factory.createStatus(post(conf.getRestBaseURL() + "favorites/create/" + id + ".json?include_entities="
@@ -1761,8 +1762,16 @@ public SimilarPlaces getSimilarPlaces(GeoLocation location, String name, String
* {@inheritDoc}
*/
public ResponseList<Place> reverseGeoCode(GeoQuery query) throws TwitterException {
- return factory.createPlaceList(get(conf.getRestBaseURL()
- + "geo/reverse_geocode.json", query.asHttpParameterArray()));
+ try {
+ return factory.createPlaceList(get(conf.getRestBaseURL()
+ + "geo/reverse_geocode.json", query.asHttpParameterArray()));
+ } catch (TwitterException te) {
+ if (te.getStatusCode() == 404) {
+ return factory.createEmptyResponseList();
+ } else {
+ throw te;
+ }
+ }
}
/**
3  twitter4j-core/src/main/java/twitter4j/TwitterResponse.java
View
@@ -16,9 +16,6 @@
package twitter4j;
-
-import twitter4j.internal.http.HttpResponse;
-
/**
* Super interface of Twitter Response data interfaces which indicates that rate limit status is avaialble.
*
2  twitter4j-core/src/main/java/twitter4j/Version.java
View
@@ -20,7 +20,7 @@
* @author Yusuke Yamamoto - yusuke at mac.com
*/
public final class Version {
- private static final String VERSION = "2.2.5-SNAPSHOT";
+ private static final String VERSION = "2.2.6-SNAPSHOT";
private static final String TITLE = "Twitter4J";
private Version() {
28 twitter4j-core/src/main/java/twitter4j/api/FavoriteMethods.java
View
@@ -16,6 +16,7 @@
package twitter4j.api;
+import twitter4j.Paging;
import twitter4j.ResponseList;
import twitter4j.Status;
import twitter4j.TwitterException;
@@ -74,6 +75,33 @@
*/
ResponseList<Status> getFavorites(String id, int page)
throws TwitterException;
+
+ /**
+ * Returns the 20 most recent favorite statuses for the authenticating user or user specified by the ID parameter in the requested format.
+ * <br>This method calls http://api.twitter.com/1/favorites.json
+ *
+ * @param paging controls pagination. Supports sinceId and page parameters.
+ * @return ResponseList<Status>
+ * @throws TwitterException when Twitter service or network is unavailable
+ * @see <a href="https://dev.twitter.com/docs/api/1/get/favorites">GET favorites | Twitter Developers</a>
+ * @since Twitter4J 2.2.5
+ */
+ ResponseList<Status> getFavorites(Paging paging)
+ throws TwitterException;
+
+ /**
+ * Returns the 20 most recent favorite statuses for the authenticating user or user specified by the ID parameter in the requested format.
+ * <br>This method calls http://api.twitter.com/1/favorites/[id].json
+ *
+ * @param id the ID or screen name of the user for whom to request a list of favorite statuses
+ * @param paging controls pagination. Supports sinceId and page parameters.
+ * @return ResponseList<Status>
+ * @throws TwitterException when Twitter service or network is unavailable
+ * @see <a href="https://dev.twitter.com/docs/api/1/get/favorites">GET favorites | Twitter Developers</a>
+ * @since Twitter4J 2.2.5
+ */
+ ResponseList<Status> getFavorites(String id, Paging paging)
+ throws TwitterException;
/**
* Favorites the status specified in the ID parameter as the authenticating user. Returns the favorite status when successful.
11 twitter4j-core/src/main/java/twitter4j/api/StatusMethods.java
View
@@ -16,13 +16,7 @@
package twitter4j.api;
-import twitter4j.IDs;
-import twitter4j.Paging;
-import twitter4j.ResponseList;
-import twitter4j.Status;
-import twitter4j.StatusUpdate;
-import twitter4j.TwitterException;
-import twitter4j.User;
+import twitter4j.*;
/**
* @author Joern Huxhorn - jhuxhorn at googlemail.com
@@ -54,7 +48,8 @@
/**
* Updates the authenticating user's status. A status update with text identical to the authenticating user's text identical to the authenticating user's current status will be ignored to prevent duplicates.
- * <br>This method calls http://api.twitter.com/1/statuses/update
+ * <br>This method calls http://api.twitter.com/1/statuses/update or<br>
+ * This method calls https://upload.twitter.com/1/statuses/update_with_media
*
* @param latestStatus the latest status to be updated.
* @return the latest status
37 twitter4j-core/src/main/java/twitter4j/api/TrendsMethods.java
View
@@ -1,5 +1,6 @@
/*
- * Copyright 2007 Yusuke Yamamoto
+ * Copyright (C) 2007 Yusuke Yamamoto
+ * Copyright (C) 2011 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,40 +29,6 @@
*/
public interface TrendsMethods {
/**
- * Returns the top ten topics that are currently trending on Twitter. The response includes the time of the request, the name of each trend, and the url to the Twitter Search results page for that topic.
- * <br>This method calls http://search.twitter.com/trends.json
- *
- * @return the result
- * @throws twitter4j.TwitterException when Twitter service or network is unavailable
- * @see <a href="https://dev.twitter.com/docs/api/1/get/trends">GET trends | Twitter Developers</a>
- * @since Twitter4J 2.0.2
- */
- Trends getTrends() throws TwitterException;
-
- /**
- * Returns the current top 10 trending topics on Twitter. The response includes the time of the request, the name of each trending topic, and query used on Twitter Search results page for that topic.
- * <br>This method calls http://search.twitter.com/trends/current.json
- *
- * @return the result
- * @throws TwitterException when Twitter service or network is unavailable
- * @see <a href="https://dev.twitter.com/docs/api/1/get/trends/current">GET trends/current | Twitter Developers</a>
- * @since Twitter4J 2.0.2
- */
- Trends getCurrentTrends() throws TwitterException;
-
- /**
- * Returns the current top 10 trending topics on Twitter. The response includes the time of the request, the name of each trending topic, and query used on Twitter Search results page for that topic.
- * <br>This method calls http://search.twitter.com/trends/current.json
- *
- * @param excludeHashTags Setting this to true will remove all hashtags from the trends list.
- * @return the result
- * @throws TwitterException when Twitter service or network is unavailable
- * @see <a href="https://dev.twitter.com/docs/api/1/get/trends/current">GET trends/current | Twitter Developers</a>
- * @since Twitter4J 2.0.2
- */
- Trends getCurrentTrends(boolean excludeHashTags) throws TwitterException;
-
- /**
* Returns the top 20 trending topics for each hour in a given day.
* <br>This method calls http://search.twitter.com/trends/daily.json
*
2  twitter4j-core/src/main/java/twitter4j/conf/Configuration.java
View
@@ -102,6 +102,8 @@
String getSiteStreamBaseURL();
+ String getUploadBaseURL();
+
boolean isIncludeRTsEnabled();
boolean isIncludeEntitiesEnabled();
36 twitter4j-core/src/main/java/twitter4j/conf/ConfigurationBase.java
View
@@ -19,11 +19,7 @@
import twitter4j.Version;
import java.io.ObjectStreamException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
+import java.util.*;
/**
* Configuration base class with default settings.
@@ -65,6 +61,7 @@
private String streamBaseURL;
private String userStreamBaseURL;
private String siteStreamBaseURL;
+ private String uploadBaseURL;
private String dispatcherImpl;
@@ -99,9 +96,10 @@
private static final String DEFAULT_REST_BASE_URL = "http://api.twitter.com/1/";
private static final String DEFAULT_SEARCH_BASE_URL = "http://search.twitter.com/";
- private static final String DEFAULT_STREAM_BASE_URL = "http://stream.twitter.com/1/";
+ private static final String DEFAULT_STREAM_BASE_URL = "https://stream.twitter.com/1/";
private static final String DEFAULT_USER_STREAM_BASE_URL = "https://userstream.twitter.com/2/";
- private static final String DEFAULT_SITE_STREAM_BASE_URL = "http://sitestream.twitter.com/2b/";
+ private static final String DEFAULT_SITE_STREAM_BASE_URL = "https://sitestream.twitter.com/2b/";
+ private static final String DEFAULT_UPLOAD_BASE_URL = "http://upload.twitter.com/1/";
private boolean IS_DALVIK;
private boolean IS_GAE;
@@ -143,7 +141,7 @@ protected ConfigurationBase() {
setHttpProxyPort(-1);
setHttpConnectionTimeout(20000);
setHttpReadTimeout(120000);
- setHttpStreamingReadTimeout(60 * 5 * 1000);
+ setHttpStreamingReadTimeout(40 * 1000);
setHttpRetryCount(0);
setHttpRetryIntervalSeconds(5);
setHttpMaxTotalConnections(20);
@@ -179,6 +177,7 @@ protected ConfigurationBase() {
setStreamBaseURL(DEFAULT_STREAM_BASE_URL);
setUserStreamBaseURL(DEFAULT_USER_STREAM_BASE_URL);
setSiteStreamBaseURL(DEFAULT_SITE_STREAM_BASE_URL);
+ setUploadBaseURL(DEFAULT_UPLOAD_BASE_URL);
setDispatcherImpl("twitter4j.internal.async.DispatcherImpl");
@@ -202,7 +201,7 @@ protected ConfigurationBase() {
}
IS_GAE = Boolean.valueOf(isGAE);
- setMediaProvider("YFROG");
+ setMediaProvider("TWITTER");
setMediaProviderAPIKey(null);
setMediaProviderParameters(null);
}
@@ -507,6 +506,21 @@ protected final void setSiteStreamBaseURL(String siteStreamBaseURL) {
this.siteStreamBaseURL = siteStreamBaseURL;
}
+ public String getUploadBaseURL() {
+ return uploadBaseURL;
+ }
+
+ protected final void setUploadBaseURL(String uploadBaseURL) {
+ this.uploadBaseURL = uploadBaseURL;
+ fixUploadBaseURL();
+ }
+
+ private void fixUploadBaseURL() {
+ if (DEFAULT_UPLOAD_BASE_URL.equals(fixURL(false, this.uploadBaseURL))) {
+ this.uploadBaseURL = fixURL(useSSL, this.uploadBaseURL);
+ }
+ }
+
public String getOAuthRequestTokenURL() {
return oAuthRequestTokenURL;
}
@@ -664,6 +678,7 @@ public int hashCode() {
result = 31 * result + (streamBaseURL != null ? streamBaseURL.hashCode() : 0);
result = 31 * result + (userStreamBaseURL != null ? userStreamBaseURL.hashCode() : 0);
result = 31 * result + (siteStreamBaseURL != null ? siteStreamBaseURL.hashCode() : 0);
+ result = 31 * result + (uploadBaseURL != null ? uploadBaseURL.hashCode() : 0);
result = 31 * result + (dispatcherImpl != null ? dispatcherImpl.hashCode() : 0);
result = 31 * result + asyncNumThreads;
result = 31 * result + (includeRTsEnabled ? 1 : 0);
@@ -756,6 +771,8 @@ public boolean equals(Object o) {
return false;
if (streamBaseURL != null ? !streamBaseURL.equals(that.streamBaseURL) : that.streamBaseURL != null)
return false;
+ if (uploadBaseURL != null ? !uploadBaseURL.equals(that.uploadBaseURL) : that.uploadBaseURL != null)
+ return false;
if (user != null ? !user.equals(that.user) : that.user != null)
return false;
if (userAgent != null ? !userAgent.equals(that.userAgent) : that.userAgent != null)
@@ -799,6 +816,7 @@ public String toString() {
", streamBaseURL='" + streamBaseURL + '\'' +
", userStreamBaseURL='" + userStreamBaseURL + '\'' +
", siteStreamBaseURL='" + siteStreamBaseURL + '\'' +
+ ", uploadBaseURL='" + uploadBaseURL + '\'' +
", dispatcherImpl='" + dispatcherImpl + '\'' +
", asyncNumThreads=" + asyncNumThreads +
", includeRTsEnabled=" + includeRTsEnabled +
5 twitter4j-core/src/main/java/twitter4j/conf/PropertyConfiguration.java
View
@@ -74,7 +74,7 @@
public static final String STREAM_BASE_URL = "streamBaseURL";
public static final String USER_STREAM_BASE_URL = "userStreamBaseURL";
public static final String SITE_STREAM_BASE_URL = "siteStreamBaseURL";
-
+ public static final String UPLOAD_BASE_URL = "uploadBaseURL";
public static final String ASYNC_NUM_THREADS = "async.numThreads";
public static final String ASYNC_DISPATCHER_IMPL = "async.dispatcherImpl";
@@ -341,6 +341,9 @@ private void setFieldsWithPrefix(Properties props, String prefix) {
if (notNull(props, prefix, SITE_STREAM_BASE_URL)) {
setSiteStreamBaseURL(getString(props, prefix, SITE_STREAM_BASE_URL));
}
+ if (notNull(props, prefix, UPLOAD_BASE_URL)) {
+ setUploadBaseURL(getString(props, prefix, UPLOAD_BASE_URL));
+ }
if (notNull(props, prefix, INCLUDE_RTS)) {
setIncludeRTsEnbled(getBoolean(props, prefix, INCLUDE_RTS));
}
5 twitter4j-core/src/main/java/twitter4j/internal/http/HttpClientBase.java
View
@@ -1,12 +1,11 @@
package twitter4j.internal.http;
-import twitter4j.conf.ConfigurationContext;
-import twitter4j.internal.logging.Logger;
-
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.Serializable;
+import twitter4j.internal.logging.Logger;
+
public class HttpClientBase implements Serializable {
private static final Logger logger = Logger.getLogger(HttpClientBase.class);
protected final HttpClientConfiguration CONF;
63 twitter4j-core/src/main/java/twitter4j/internal/json/StatusJSONImpl.java
View
@@ -137,35 +137,44 @@ private void init(JSONObject json) throws TwitterException {
if (!json.isNull("entities")) {
try {
JSONObject entities = json.getJSONObject("entities");
+ int len;
+ if (!entities.isNull("user_mentions")) {
+ JSONArray userMentionsArray = entities.getJSONArray("user_mentions");
+ len = userMentionsArray.length();
+ userMentionEntities = new UserMentionEntity[len];
+ for (int i = 0; i < len; i++) {
+ userMentionEntities[i] = new UserMentionEntityJSONImpl(userMentionsArray.getJSONObject(i));
+ }
- JSONArray userMentionsArray = entities.getJSONArray("user_mentions");
- int len = userMentionsArray.length();
- userMentionEntities = new UserMentionEntity[len];
- for (int i = 0; i < len; i++) {
- userMentionEntities[i] = new UserMentionEntityJSONImpl(userMentionsArray.getJSONObject(i));
}
-
- JSONArray urlsArray = entities.getJSONArray("urls");
- len = urlsArray.length();
- urlEntities = new URLEntity[len];
- for (int i = 0; i < len; i++) {
- urlEntities[i] = new URLEntityJSONImpl(urlsArray.getJSONObject(i));
+ if (!entities.isNull("urls")) {
+ JSONArray urlsArray = entities.getJSONArray("urls");
+ len = urlsArray.length();
+ urlEntities = new URLEntity[len];
+ for (int i = 0; i < len; i++) {
+ urlEntities[i] = new URLEntityJSONImpl(urlsArray.getJSONObject(i));
+ }
}
- JSONArray hashtagsArray = entities.getJSONArray("hashtags");
- len = hashtagsArray.length();
- hashtagEntities = new HashtagEntity[len];
- for (int i = 0; i < len; i++) {
- hashtagEntities[i] = new HashtagEntityJSONImpl(hashtagsArray.getJSONObject(i));
+ if (!entities.isNull("hashtags")) {
+ JSONArray hashtagsArray = entities.getJSONArray("hashtags");
+ len = hashtagsArray.length();
+ hashtagEntities = new HashtagEntity[len];
+ for (int i = 0; i < len; i++) {
+ hashtagEntities[i] = new HashtagEntityJSONImpl(hashtagsArray.getJSONObject(i));
+ }
}
- JSONArray mediaArray = entities.getJSONArray("media");
- len = mediaArray.length();
- mediaEntities = new MediaEntity[len];
- for (int i = 0; i < len; i++) {
- mediaEntities[i] = new MediaEntityJSONImpl(mediaArray.getJSONObject(i));
+ if (!entities.isNull("media")) {
+ JSONArray mediaArray = entities.getJSONArray("media");
+ len = mediaArray.length();
+ mediaEntities = new MediaEntity[len];
+ for (int i = 0; i < len; i++) {
+ mediaEntities[i] = new MediaEntityJSONImpl(mediaArray.getJSONObject(i));
+ }
}
- } catch (JSONException ignore) {
+ } catch (JSONException jsone) {
+ throw new TwitterException(jsone);
}
}
if (!json.isNull("annotations")) {
@@ -177,12 +186,12 @@ private void init(JSONObject json) throws TwitterException {
}
if (!json.isNull("current_user_retweet")) {
try {
- myRetweetedStatus = new StatusJSONImpl(json.getJSONObject("current_user_retweet"));
- wasRetweetedByMe = true;
+ myRetweetedStatus = new StatusJSONImpl(json.getJSONObject("current_user_retweet"));
+ wasRetweetedByMe = true;
} catch (JSONException ignore) {
- ignore.printStackTrace();
- logger.warn("failed to parse current_user_retweet:" + json);
- }
+ ignore.printStackTrace();
+ logger.warn("failed to parse current_user_retweet:" + json);
+ }
}
}
88 twitter4j-core/src/main/java/twitter4j/internal/json/TweetJSONImpl.java
View
@@ -18,14 +18,19 @@
import twitter4j.Annotations;
import twitter4j.GeoLocation;
+import twitter4j.HashtagEntity;
+import twitter4j.MediaEntity;
import twitter4j.Place;
import twitter4j.Tweet;
import twitter4j.TwitterException;
+import twitter4j.URLEntity;
+import twitter4j.UserMentionEntity;
import twitter4j.conf.Configuration;
import twitter4j.internal.org.json.JSONArray;
import twitter4j.internal.org.json.JSONException;
import twitter4j.internal.org.json.JSONObject;
+import java.util.Arrays;
import java.util.Date;
import static twitter4j.internal.util.z_T4JInternalParseUtil.getDate;
@@ -55,6 +60,10 @@
private GeoLocation geoLocation = null;
private Annotations annotations = null;
+ private UserMentionEntity[] userMentionEntities;
+ private URLEntity[] urlEntities;
+ private HashtagEntity[] hashtagEntities;
+ private MediaEntity[] mediaEntities;
/*package*/ TweetJSONImpl(JSONObject tweet) throws TwitterException {
text = getUnescapedString("text", tweet);
@@ -85,6 +94,49 @@
} else {
place = null;
}
+ if (!tweet.isNull("entities")) {
+ try {
+ JSONObject entities = tweet.getJSONObject("entities");
+ int len;
+ if (!entities.isNull("user_mentions")) {
+ JSONArray userMentionsArray = entities.getJSONArray("user_mentions");
+ len = userMentionsArray.length();
+ userMentionEntities = new UserMentionEntity[len];
+ for (int i = 0; i < len; i++) {
+ userMentionEntities[i] = new UserMentionEntityJSONImpl(userMentionsArray.getJSONObject(i));
+ }
+
+ }
+ if (!entities.isNull("urls")) {
+ JSONArray urlsArray = entities.getJSONArray("urls");
+ len = urlsArray.length();
+ urlEntities = new URLEntity[len];
+ for (int i = 0; i < len; i++) {
+ urlEntities[i] = new URLEntityJSONImpl(urlsArray.getJSONObject(i));
+ }
+ }
+
+ if (!entities.isNull("hashtags")) {
+ JSONArray hashtagsArray = entities.getJSONArray("hashtags");
+ len = hashtagsArray.length();
+ hashtagEntities = new HashtagEntity[len];
+ for (int i = 0; i < len; i++) {
+ hashtagEntities[i] = new HashtagEntityJSONImpl(hashtagsArray.getJSONObject(i));
+ }
+ }
+
+ if (!entities.isNull("media")) {
+ JSONArray mediaArray = entities.getJSONArray("media");
+ len = mediaArray.length();
+ mediaEntities = new MediaEntity[len];
+ for (int i = 0; i < len; i++) {
+ mediaEntities[i] = new MediaEntityJSONImpl(mediaArray.getJSONObject(i));
+ }
+ }
+ } catch (JSONException jsone) {
+ throw new TwitterException(jsone);
+ }
+ }
}
/*package*/ TweetJSONImpl(JSONObject tweet, Configuration conf) throws TwitterException {
@@ -198,6 +250,34 @@ public Place getPlace() {
/**
* {@inheritDoc}
*/
+ public UserMentionEntity[] getUserMentionEntities() {
+ return userMentionEntities;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public URLEntity[] getURLEntities() {
+ return urlEntities;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public HashtagEntity[] getHashtagEntities() {
+ return hashtagEntities;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public MediaEntity[] getMediaEntities() {
+ return mediaEntities;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Annotations getAnnotations() {
return annotations;
}
@@ -230,6 +310,10 @@ public int hashCode() {
result = 31 * result + (place != null ? place.hashCode() : 0);
result = 31 * result + (geoLocation != null ? geoLocation.hashCode() : 0);
result = 31 * result + (annotations != null ? annotations.hashCode() : 0);
+ result = 31 * result + (userMentionEntities != null ? Arrays.hashCode(userMentionEntities) : 0);
+ result = 31 * result + (urlEntities != null ? Arrays.hashCode(urlEntities) : 0);
+ result = 31 * result + (hashtagEntities != null ? Arrays.hashCode(hashtagEntities) : 0);
+ result = 31 * result + (mediaEntities != null ? Arrays.hashCode(mediaEntities) : 0);
return result;
}
@@ -250,6 +334,10 @@ public String toString() {
", place=" + place +
", geoLocation=" + geoLocation +
", annotations=" + annotations +
+ ", userMentionEntities=" + (userMentionEntities == null ? null : Arrays.asList(userMentionEntities)) +
+ ", urlEntities=" + (urlEntities == null ? null : Arrays.asList(urlEntities)) +
+ ", hashtagEntities=" + (hashtagEntities == null ? null : Arrays.asList(hashtagEntities)) +
+ ", mediaEntities=" + (mediaEntities == null ? null : Arrays.asList(mediaEntities)) +
'}';
}
}
17 twitter4j-core/src/main/java/twitter4j/internal/json/z_T4JInternalFactory.java
View
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2007 Yusuke Yamamoto
+ * Copyright (C) 2011 Twitter, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package twitter4j.internal.json;
import twitter4j.*;
@@ -82,4 +98,5 @@
ResponseList<HelpMethods.Language> createLanguageList(HttpResponse res) throws TwitterException;
+ <T> ResponseList<T> createEmptyResponseList();
}
7 twitter4j-core/src/main/java/twitter4j/internal/json/z_T4JInternalJSONImplFactory.java
View
@@ -1,5 +1,6 @@
/*
- * Copyright 2007 Yusuke Yamamoto
+ * Copyright (C) 2007 Yusuke Yamamoto
+ * Copyright (C) 2011 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -249,6 +250,10 @@ public TwitterAPIConfiguration createTwitterAPIConfiguration(HttpResponse res) t
return LanguageJSONImpl.createLanguageList(res, conf);
}
+ public <T> ResponseList<T> createEmptyResponseList() {
+ return new ResponseListImpl<T>(0, null);
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
6 twitter4j-core/src/test/java/twitter4j/HelpMethodsTest.java
View
@@ -45,9 +45,9 @@ public void testHelpMethods() throws Exception {
TwitterAPIConfiguration conf = twitter1.getAPIConfiguration();
assertEquals(3145728, conf.getPhotoSizeLimit());
- assertEquals(20, conf.getCharactersReservedPerMedia());
- assertEquals(19, conf.getShortURLLength());
- assertEquals(20, conf.getShortURLLengthHttps());
+ assertEquals(21, conf.getCharactersReservedPerMedia());
+ assertEquals(20, conf.getShortURLLength());
+ assertEquals(21, conf.getShortURLLengthHttps());
assertEquals(4, conf.getPhotoSizes().size());
assertTrue(20 < conf.getNonUsernamePaths().length);
assertEquals(1, conf.getMaxMediaPerUpload());
53 twitter4j-core/src/test/java/twitter4j/SearchAPITest.java
View
@@ -1,5 +1,6 @@
/*
- * Copyright 2007 Yusuke Yamamoto
+ * Copyright (C) 2007 Yusuke Yamamoto
+ * Copyright (C) 2011 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,7 +42,7 @@ public void testQuery() throws Exception {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Query query = new Query("test")
.until(format.format(new java.util.Date(System.currentTimeMillis() - 3600 * 24)));
- HttpParameter[] params = query.asHttpParameterArray();
+ HttpParameter[] params = query.asHttpParameterArray(new HttpParameter("include_entities", "true"));
assertTrue(findParameter(params, "q"));
assertTrue(findParameter(params, "until"));
}
@@ -114,71 +115,37 @@ public void testSearch() throws Exception {
query.setSinceId(1671199128);
queryResult = unauthenticated.search(query);
assertTrue(0 < queryResult.getTweets().size());
+ assertEquals(6358482, queryResult.getTweets().get(0).getFromUserId());
query = new Query("\\u5e30%u5e30 <%}& foobar").rpp(100).page(1);
QueryResult result = twitter1.search(query);
+
+ query = new Query("#sendro").rpp(1).page(1);
+ result = twitter1.search(query);
+ System.out.println(result.getTweets().get(0));
+ assertNotNull(result.getTweets().get(0).getHashtagEntities());
}
public void testTrends() throws Exception {
- Trends trends;
- trends = unauthenticated.getTrends();
-
- assertTrue(100000 > (trends.getAsOf().getTime() - System.currentTimeMillis()));
- assertEquals(10, trends.getTrends().length);
- for (int i = 0; i < 10; i++) {
- assertNotNull(trends.getTrends()[i].getName());
- assertNotNull(trends.getTrends()[i].getUrl());
- assertNull(trends.getTrends()[i].getQuery());
- trends.getTrends()[i].hashCode();
- trends.getTrends()[i].toString();
- }
-
- trends = unauthenticated.getCurrentTrends();
- assertTrue(100000 > (trends.getAsOf().getTime() - System.currentTimeMillis()));
- assertEquals(10, trends.getTrends().length);
- for (Trend trend : trends.getTrends()) {
- assertNotNull(trend.getName());
- assertNull(trend.getUrl());
- assertNotNull(trend.getQuery());
- trend.hashCode();
- trend.toString();
- }
-
- trends = unauthenticated.getCurrentTrends(true);
- assertTrue(100000 > (trends.getAsOf().getTime() - System.currentTimeMillis()));
- Trend[] trendArray = trends.getTrends();
- assertEquals(10, trendArray.length);
- for (Trend trend : trends.getTrends()) {
- assertNotNull(trend.getName());
- assertNull(trend.getUrl());
- assertNotNull(trend.getQuery());
- trend.hashCode();
- trend.toString();
- }
-
List<Trends> trendsList;
trendsList = unauthenticated.getDailyTrends();
- assertTrue(100000 > (trends.getAsOf().getTime() - System.currentTimeMillis()));
assertTrends(trendsList, 20);
trendsList = unauthenticated.getDailyTrends(new Date(), true);
- assertTrue(100000 > (trends.getAsOf().getTime() - System.currentTimeMillis()));
assertTrends(trendsList, 20);
trendsList = unauthenticated.getWeeklyTrends();
- assertTrue(100000 > (trends.getAsOf().getTime() - System.currentTimeMillis()));
assertTrends(trendsList, 30);
trendsList = unauthenticated.getWeeklyTrends(new Date(), true);
- assertTrue(100000 > (trends.getAsOf().getTime() - System.currentTimeMillis()));
assertTrends(trendsList, 30);
}
private void assertTrends(List<Trends> trendsArray, int expectedSize) throws Exception {
Date trendAt = null;
for (Trends singleTrends : trendsArray) {
- assertTrue((expectedSize-10) < singleTrends.getTrends().length);
+ assertTrue((expectedSize - 10) < singleTrends.getTrends().length);
if (trendAt != null) {
assertTrue(trendAt.before(singleTrends.getTrendAt()));
}
54 twitter4j-core/src/test/java/twitter4j/StatusMethodsTest.java
View
@@ -17,6 +17,7 @@
import twitter4j.json.DataObjectFactory;
+import java.io.File;
import java.util.List;
import java.util.Map;
@@ -68,21 +69,33 @@ public void testShowStatus() throws Exception {
}
public void testStatusMethods() throws Exception {
- String date = new java.util.Date().toString() + "test http://t.co/VEDROet @twit4j2 #twitter4jtest";
+ String dateStr = new java.util.Date().toString();
+ String date = dateStr + "test http://t.co/VEDROet @twit4j2 #twitter4jtest";
Status status = twitter1.updateStatus(date);
assertNotNull(DataObjectFactory.getRawJSON(status));
assertEquals(status, DataObjectFactory.createStatus(DataObjectFactory.getRawJSON(status)));
+ System.out.println(status.getText());
- assertEquals(date, status.getText());
+ assertTrue(status.getText().matches(dateStr + "test http://t.co/.* @twit4j2 #twitter4jtest"));
Status status2 = twitter2.updateStatus(new StatusUpdate("@" + id1.screenName + " " + date).inReplyToStatusId(status.getId()));
assertNotNull(DataObjectFactory.getRawJSON(status2));
assertEquals(status2, DataObjectFactory.createStatus(DataObjectFactory.getRawJSON(status2)));
- assertEquals("@" + id1.screenName + " " + date, status2.getText());
+ assertTrue(status2.getText().matches("@" + id1.screenName + " " + dateStr + "test http://t.co/.* @twit4j2 #twitter4jtest"));
assertEquals(status.getId(), status2.getInReplyToStatusId());
assertEquals(id1.id, status2.getInReplyToUserId());
status = twitter1.destroyStatus(status.getId());
assertNotNull(DataObjectFactory.getRawJSON(status));
assertEquals(status, DataObjectFactory.createStatus(DataObjectFactory.getRawJSON(status)));
+
+ date = new java.util.Date().toString();
+ String tweet = date + "test http://t.co/VEDROet @twit4j2 #twitter4jtest";
+ status = twitter1.updateStatus(new StatusUpdate(tweet).possiblySensitive(false).media(getRandomlyChosenFile()));
+ assertNotNull(DataObjectFactory.getRawJSON(status));
+ assertEquals(status, DataObjectFactory.createStatus(DataObjectFactory.getRawJSON(status)));
+
+ assertTrue(status.getText().startsWith(date));
+ assertNotNull(status.getMediaEntities());
+ assertEquals(1, status.getMediaEntities().length);
}
public void testRetweetMethods() throws Exception {
@@ -216,22 +229,21 @@ public void testEntities() throws Exception {
assertEquals(150, thumb.getHeight());
}
-// public void testAnnotations() throws Exception {
-// final String failMessage =
-// "Annotations were not added to the status, please make sure that your account is whitelisted for Annotations by Twitter";
-// Annotation annotation = new Annotation("review");
-// annotation.attribute("content", "Yahoo! landing page").
-// attribute("url", "http://yahoo.com").attribute("rating", "0.6");
-//
-// StatusUpdate update = new StatusUpdate(new java.util.Date().toString() + ": annotated status");
-// update.addAnnotation(annotation);
-//
-// Status withAnnos = twitterAPI1.updateStatus(update);
-// Annotations annotations = withAnnos.getAnnotations();
-// assertNotNull(failMessage, annotations);
-//
-// List<Annotation> annos = annotations.getAnnotations();
-// assertEquals(1, annos.size());
-// assertEquals(annotation, annos.get(0));
-// }
+ static final String[] files = {"src/test/resources/t4j-reverse.jpeg",
+ "src/test/resources/t4j-reverse.png",
+ "src/test/resources/t4j-reverse.gif",
+ "src/test/resources/t4j.jpeg",
+ "src/test/resources/t4j.png",
+ "src/test/resources/t4j.gif",
+ };
+
+ private static File getRandomlyChosenFile() {
+ int rand = (int) (System.currentTimeMillis() % 6);
+ File file = new File(files[rand]);
+ if (!file.exists()) {
+ file = new File("twitter4j-core/" + files[rand]);
+ }
+ return file;
+ }
+
}
28 twitter4j-core/src/test/java/twitter4j/conf/ConfigurationTest.java
View
@@ -1,5 +1,6 @@
/*
- * Copyright 2007 Yusuke Yamamoto
+ * Copyright (C) 2007 Yusuke Yamamoto
+ * Copyright (C) 2011 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,14 +23,7 @@
import twitter4j.auth.RequestToken;
import twitter4j.internal.util.z_T4JInternalStringUtil;
-import java.io.BufferedWriter;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
+import java.io.*;
import java.util.Properties;
/**
@@ -328,17 +322,8 @@ public void testConfigurationBuilder() throws Exception {
conf = builder.build();
Configuration t = (Configuration) serializeDeserialize(conf);
- System.out.println("-------");
- System.out.println(conf);
- System.out.println(t);
- System.out.println("-------");
- System.out.println(conf.hashCode());
- System.out.println(t.hashCode());
- System.out.println("-------");
- System.out.println(conf.equals(t));
- System.out.println(conf == t);
-
- assertSame(conf, (Configuration) serializeDeserialize(conf));
+
+ assertEquals(conf, (Configuration) serializeDeserialize(conf));
assertTrue(0 == conf.getRestBaseURL().indexOf("http://"));
assertTrue(0 == conf.getSearchBaseURL().indexOf("http://"));
@@ -351,7 +336,7 @@ public void testConfigurationBuilder() throws Exception {
builder.setUseSSL(true);
conf = builder.build();
assertTrue(0 == conf.getRestBaseURL().indexOf("https://"));
- assertTrue(0 == conf.getSearchBaseURL().indexOf("http://"));
+ assertTrue(0 == conf.getSearchBaseURL().indexOf("https://"));
assertTrue(0 == conf.getOAuthAuthenticationURL().indexOf("https://"));
assertTrue(0 == conf.getOAuthAuthorizationURL().indexOf("https://"));
assertTrue(0 == conf.getOAuthAccessTokenURL().indexOf("https://"));
@@ -412,7 +397,6 @@ private static Object serializeDeserialize(Object obj) throws Exception {
ByteArrayInputStream byteInputStream = new ByteArrayInputStream(byteOutputStream.toByteArray());
ObjectInputStream ois = new ObjectInputStream(byteInputStream);
Object that = ois.readObject();
- System.out.println(that);
byteInputStream.close();
ois.close();
return that;
2  twitter4j-examples/bin/account/getAccountSettings.sh
View
@@ -1,4 +1,4 @@
-#/bin/sh
+#!/bin/sh
cd ..
. ./setEnv.sh
2  twitter4j-examples/bin/account/getAccountTotals.sh
View
@@ -1,4 +1,4 @@
-#/bin/sh
+#!/bin/sh
cd ..
. ./setEnv.sh
2  twitter4j-examples/bin/account/getRateLimitStatus.sh
View
@@ -1,4 +1,4 @@
-#/bin/sh
+#!/bin/sh
cd ..
. ./setEnv.sh
2  twitter4j-examples/bin/account/updateProfile.sh
View
@@ -1,4 +1,4 @@
-#/bin/sh
+#!/bin/sh
cd ..
. ./setEnv.sh
2  twitter4j-examples/bin/account/updateProfileBackgroundImage.sh
View
@@ -1,4 +1,4 @@
-#/bin/sh
+#!/bin/sh
cd ..
. ./setEnv.sh
2  twitter4j-examples/bin/account/updateProfileColors.sh
View
@@ -1,4 +1,4 @@
-#/bin/sh
+#!/bin/sh
cd ..
. ./setEnv.sh
2  twitter4j-examples/bin/account/updateProfileImage.sh
View
@@ -1,4 +1,4 @@
-#/bin/sh
+#!/bin/sh
cd ..
. ./setEnv.sh
2  twitter4j-examples/bin/account/verifyCredentials.sh
View
@@ -1,4 +1,4 @@
-#/bin/sh
+#!/bin/sh
cd ..
. ./setEnv.sh
2  twitter4j-examples/bin/async/asyncUpdate.sh
View
@@ -1,4 +1,4 @@
-#/bin/sh
+#!/bin/sh
cd ..
. ./setEnv.sh
RUN_CMD="$JAVA_HOME/bin/java $MEM_ARGS -cp $CLASSPATH twitter4j.examples.async.AsyncUpdate"
2  twitter4j-examples/bin/block/createBlock.sh
View
@@ -1,4 +1,4 @@
-#/bin/sh
+#!/bin/sh
cd ..