Skip to content

Commit

Permalink
stream event add
Browse files Browse the repository at this point in the history
  • Loading branch information
mumei committed Jun 2, 2015
1 parent fb51685 commit 812b8ca
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 6 deletions.
2 changes: 1 addition & 1 deletion twitter4j-async/src/main/java/twitter4j/TwitterMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public enum TwitterMethod {
USER_TIMELINE,
HOME_TIMELINE,
RETWEETS_OF_ME,
RETWEETED_RETWEET,


/* Tweets Resources */
RETWEETS,
Expand Down
3 changes: 3 additions & 0 deletions twitter4j-core/src/main/java/twitter4j/JSONObjectType.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public enum Type {
UNBLOCK,
DISCONNECTION,
RETWEETED_RETWEET,
FAVORITED_RETWEET,
UNKNOWN
}

Expand Down Expand Up @@ -124,6 +125,8 @@ public static Type determine(JSONObject json) {
return Type.UNBLOCK;
} else if("retweeted_retweet".equals(event)){
return Type.RETWEETED_RETWEET;
} else if("favorited_retweet".equals(event)){
return Type.FAVORITED_RETWEET;
}
} catch (JSONException jsone) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public void onUnblock(long forUser, User source, User unblockedUser) {
public void onRetweetedRetweet(User source, User target, Status retweetedStatus) {
}

@Override
public void onFavoritedRetweet(User source, User target, Status favoritedStatus) {
}

@Override
public void onDisconnectionNotice(String screenName) {
}
Expand Down
7 changes: 7 additions & 0 deletions twitter4j-stream/src/main/java/twitter4j/SiteStreamsImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ void onRetweetedRetweet(JSONObject source, JSONObject target, JSONObject targetO
}
}

@Override
void onFavoritedRetweet(JSONObject source, JSONObject target, JSONObject targetObject, StreamListener[] listeners) throws TwitterException {
for (StreamListener listener : listeners) {
((SiteStreamsListener) listener).onFavoritedRetweet(asUser(source), asUser(target), asStatus(targetObject));
}
}

@Override
public void onException(final Exception ex, StreamListener[] listeners) {
for (StreamListener listener : listeners) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ public interface SiteStreamsListener extends StreamListener {
*/
void onRetweetedRetweet(User source,User target, Status retweetedStatus);

/**
* @param source source user of the event
* @param target target user of the event
* @param favoritedStatus status favorited retweet
* @since Twitter4J 4.0.x
*/
void onFavoritedRetweet(User source,User target, Status favoritedStatus);

/**
* callback method for {@link StreamController#removeUsers(long[])}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ public void run() {
onUnblock(json.getJSONObject("source"), json.getJSONObject("target"), listeners);
break;
case RETWEETED_RETWEET:
onRetweetedRetweet(json.getJSONObject("source"),json.getJSONObject("target"),json.getJSONObject("target_object"),listeners);
onRetweetedRetweet(json.getJSONObject("source"), json.getJSONObject("target"), json.getJSONObject("target_object"), listeners);
break;
case FAVORITED_RETWEET:
onFavoritedRetweet(json.getJSONObject("source"), json.getJSONObject("target"), json.getJSONObject("target_object"), listeners);
break;
case DISCONNECTION:
onDisconnectionNotice(line, listeners);
Expand Down Expand Up @@ -305,6 +308,9 @@ void onUnblock(JSONObject source, JSONObject target, StreamListener[] listeners)
void onRetweetedRetweet(JSONObject source, JSONObject target, JSONObject targetObject,StreamListener[] listeners) throws TwitterException {
logger.warn("Unhandled event: onRetweetedRetweet");
}
void onFavoritedRetweet(JSONObject source, JSONObject target, JSONObject targetObject,StreamListener[] listeners) throws TwitterException {
logger.warn("Unhandled event: onFavoritedRetweet");
}

void onDisconnectionNotice(String line, StreamListener[] listeners) {
logger.warn("Unhandled event: ", line);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ public void onUnblock(User source, User unblockedUser) {

@Override
public void onRetweetedRetweet(User source, User target, Status retweetedStatus) {
}

@Override
public void onFavoritedRetweet(User source, User target, Status favoritedStatus) {
}

@Override
Expand Down
7 changes: 7 additions & 0 deletions twitter4j-stream/src/main/java/twitter4j/UserStreamImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,11 @@ void onRetweetedRetweet(JSONObject source, JSONObject target, JSONObject targetO
((UserStreamListener) listener).onRetweetedRetweet(asUser(source), asUser(target), asStatus(targetObject));
}
}

@Override
void onFavoritedRetweet(JSONObject source, JSONObject target, JSONObject targetObject, StreamListener[] listeners) throws TwitterException {
for (StreamListener listener : listeners) {
((UserStreamListener) listener).onFavoritedRetweet(asUser(source), asUser(target), asStatus(targetObject));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,12 @@ public interface UserStreamListener extends StatusListener {
* @since Twitter4J 4.0.x
*/
void onRetweetedRetweet(User source,User target, Status retweetedStatus);

/**
* @param source source user of the event
* @param target target user of the event
* @param retweetedStatus status favorited retweet
* @since Twitter4J 4.0.x
*/
void onFavoritedRetweet(User source,User target, Status retweetedStatus);
}
13 changes: 10 additions & 3 deletions twitter4j-stream/src/test/java/twitter4j/SiteStreamsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -407,15 +407,22 @@ public void onUnblock(long forUser, User source, User unblockedUser) {

@Override
public void onRetweetedRetweet(User source, User target, Status retweetedStatus) {

System.out.println("onRetweetedRetweet");
received.add(new Object[]{TwitterMethod.RETWEETED_RETWEET, source, target, retweetedStatus});
received.add(new Object[]{"retweeted_retweet", source, target, retweetedStatus});
Assert.assertNotNull(TwitterObjectFactory.getRawJSON(source));
Assert.assertNotNull(TwitterObjectFactory.getRawJSON(target));
Assert.assertNotNull(TwitterObjectFactory.getRawJSON(retweetedStatus));
notifyResponse();
}

@Override
public void onFavoritedRetweet(User source, User target, Status favoritedStatus) {
received.add(new Object[]{"favorited_retweet", source, target, favoritedStatus});
Assert.assertNotNull(TwitterObjectFactory.getRawJSON(source));
Assert.assertNotNull(TwitterObjectFactory.getRawJSON(target));
Assert.assertNotNull(TwitterObjectFactory.getRawJSON(favoritedStatus));
notifyResponse();
}

@Override
public void onDisconnectionNotice(String screenName) {
received.add(new Object[]{"Disconnect"});
Expand Down
11 changes: 10 additions & 1 deletion twitter4j-stream/src/test/java/twitter4j/UserStreamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,22 @@ public void onUnblock(User source, User unblockedUser) {
@Override
public void onRetweetedRetweet(User source, User target, Status retweetedStatus) {
System.out.println("onRetweetedRetweet");
received.add(new Object[]{RETWEETED_RETWEET, source, target, retweetedStatus});
received.add(new Object[]{"retweeted_retweet", source, target, retweetedStatus});
Assert.assertNotNull(TwitterObjectFactory.getRawJSON(source));
Assert.assertNotNull(TwitterObjectFactory.getRawJSON(target));
Assert.assertNotNull(TwitterObjectFactory.getRawJSON(retweetedStatus));
notifyResponse();
}

@Override
public void onFavoritedRetweet(User source, User target, Status favoritedStatus) {
received.add(new Object[]{"favorited_retweet", source, target, favoritedStatus});
Assert.assertNotNull(TwitterObjectFactory.getRawJSON(source));
Assert.assertNotNull(TwitterObjectFactory.getRawJSON(target));
Assert.assertNotNull(TwitterObjectFactory.getRawJSON(favoritedStatus));
notifyResponse();
}

@Override
public void onException(Exception ex) {
System.out.println("onException");
Expand Down

0 comments on commit 812b8ca

Please sign in to comment.