Skip to content

Commit

Permalink
TFJ-529 added SiteStreamsListener#unfollow()
Browse files Browse the repository at this point in the history
  • Loading branch information
yusuke committed Jan 18, 2011
1 parent bafabb4 commit 6507c91
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ public void run() {
onRetweet(json.getJSONObject("source"), json.getJSONObject("target"), json.getJSONObject("target_object"));
} else if (JSONObjectType.FOLLOW == jsonObjectType) {
onFollow(json.getJSONObject("source"), json.getJSONObject("target"));
} else if (JSONObjectType.UNFOLLOW == jsonObjectType) {
onUnfollow(json.getJSONObject("source"), json.getJSONObject("target"));
} else if (JSONObjectType.USER_LIST_MEMBER_ADDED == jsonObjectType) {
onUserListMemberAddition(json.getJSONObject("target"), json.getJSONObject("source"), json.getJSONObject("target_object"));
} else if (JSONObjectType.USER_LIST_MEMBER_DELETED == jsonObjectType) {
Expand Down Expand Up @@ -171,70 +173,95 @@ public void run() {
}

protected void onSender(JSONObject json) throws TwitterException {
logger.warn("Unhandled event: onSender");
}

protected void onStatus(JSONObject json) throws TwitterException {
logger.warn("Unhandled event: onStatus");
}

protected void onDirectMessage(JSONObject json) throws TwitterException, JSONException {
logger.warn("Unhandled event: onDirectMessage");
}

protected void onDelete(JSONObject json) throws TwitterException, JSONException {
logger.warn("Unhandled event: onDelete");
}

protected void onLimit(JSONObject json) throws TwitterException, JSONException {
logger.warn("Unhandled event: onLimit");
}

protected void onScrubGeo(JSONObject json) throws TwitterException, JSONException {
logger.warn("Unhandled event: onScrubGeo");
}

protected void onFriends(JSONObject json) throws TwitterException, JSONException {
logger.warn("Unhandled event: onFriends");
}

protected void onFavorite(JSONObject source, JSONObject target, JSONObject targetObject) throws TwitterException {
logger.warn("Unhandled event: onFavorite");
}

protected void onUnfavorite(JSONObject source, JSONObject target, JSONObject targetObject) throws TwitterException {
logger.warn("Unhandled event: onUnfavorite");
}

protected void onRetweet(JSONObject source, JSONObject target, JSONObject targetObject) throws TwitterException {
logger.warn("Unhandled event: onRetweet");
}

protected void onFollow(JSONObject source, JSONObject target) throws TwitterException {
logger.warn("Unhandled event: onFollow");
}

protected void onUnfollow(JSONObject source, JSONObject target) throws TwitterException {
logger.warn("Unhandled event: onUnfollow");
}

protected void onUserListMemberAddition(JSONObject addedMember, JSONObject owner, JSONObject userList) throws TwitterException, JSONException {
logger.warn("Unhandled event: onUserListMemberAddition");
}

protected void onUserListMemberDeletion(JSONObject deletedMember, JSONObject owner, JSONObject userList) throws TwitterException, JSONException {
logger.warn("Unhandled event: onUserListMemberDeletion");
}


protected void onUserListSubscription(JSONObject source, JSONObject owner, JSONObject userList) throws TwitterException, JSONException {
logger.warn("Unhandled event: onUserListSubscription");
}

protected void onUserListUnsubscription(JSONObject source, JSONObject owner, JSONObject userList) throws TwitterException, JSONException {
logger.warn("Unhandled event: onUserListUnsubscription");
}

protected void onUserListCreation(JSONObject source, JSONObject userList) throws TwitterException, JSONException {
logger.warn("Unhandled event: onUserListCreation");
}

protected void onUserListUpdated(JSONObject source, JSONObject userList) throws TwitterException, JSONException {
logger.warn("Unhandled event: onUserListUpdated");
}

protected void onUserListDestroyed(JSONObject source, JSONObject userList) throws TwitterException {
logger.warn("Unhandled event: onUserListDestroyed");
}

protected void onUserUpdate(JSONObject source, JSONObject target) throws TwitterException {
logger.warn("Unhandled event: onUserUpdate");
}

protected void onBlock(JSONObject source, JSONObject target) throws TwitterException {
logger.warn("Unhandled event: onBlock");
}

protected void onUnblock(JSONObject source, JSONObject target) throws TwitterException {
logger.warn("Unhandled event: onUnblock");
}

protected void onException(Exception e) {
logger.warn("Unhandled event: ", e.getMessage());
}

public void close() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public void onUnfavorite(int forUser, User source, User target, Status unfavorit
public void onFollow(int forUser, User source, User followedUser) {
}

public void onUnfollow(int forUser, User source, User followedUser) {
}

public void onDirectMessage(int forUser, DirectMessage directMessage) {
}

Expand Down
4 changes: 4 additions & 0 deletions twitter4j-core/src/main/java/twitter4j/SiteStreamsImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ protected void onFollow(final JSONObject source, final JSONObject target) throws
listener.onFollow(forUser.get(), asUser(source), asUser(target));
}

protected void onUnfollow(final JSONObject source, final JSONObject target) throws TwitterException {
listener.onUnfollow(forUser.get(), asUser(source), asUser(target));
}

protected void onUserListMemberAddition(final JSONObject addedMember, final JSONObject owner, final JSONObject userList) throws TwitterException, JSONException {
listener.onUserListMemberAddition(forUser.get(), asUser(addedMember)
, asUser(owner), asUserList(userList));
Expand Down
23 changes: 22 additions & 1 deletion twitter4j-core/src/main/java/twitter4j/SiteStreamsListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,97 +36,118 @@ public interface SiteStreamsListener extends StreamListener {
void onDeletionNotice(int forUser, StatusDeletionNotice statusDeletionNotice);

/**
* @param forUser the user id to whom sent the event
* @param friendIds
*/
void onFriendList(int forUser, int[] friendIds);

/**
* @param forUser the user id to whom sent the event
* @param source
* @param target
* @param favoritedStatus
*/
void onFavorite(int forUser, User source, User target, Status favoritedStatus);

/**
* @param source
* @param forUser the user id to whom sent the event
* @param target
* @param unfavoritedStatus
*/
void onUnfavorite(int forUser, User source, User target, Status unfavoritedStatus);

/**
* @param forUser the user id to whom sent the event
* @param source
* @param followedUser
*/
void onFollow(int forUser, User source, User followedUser);

/**
* @param forUser the user id to whom sent the event
* @param source
* @param unfollowedUser
* @since Twitter4J 2.1.11
*/
void onUnfollow(int forUser, User source, User unfollowedUser);

/**
* @param forUser the user id to whom sent the event
* @param directMessage
*/
void onDirectMessage(int forUser, DirectMessage directMessage);

void onDeletionNotice(int forUser, int directMessageId, int userId);

/**
* @param forUser the user id to whom sent the event
* @param addedMember
* @param listOwner
* @param list
*/
void onUserListMemberAddition(int forUser, User addedMember, User listOwner, UserList list);

/**
* @param forUser the user id to whom sent the event
* @param deletedMember
* @param listOwner
* @param list
*/
void onUserListMemberDeletion(int forUser, User deletedMember, User listOwner, UserList list);

/**
* @param forUser the user id to whom sent the event
* @param subscriber
* @param listOwner
* @param list
*/
void onUserListSubscription(int forUser, User subscriber, User listOwner, UserList list);

/**
* @param forUser the user id to whom sent the event
* @param subscriber
* @param listOwner
* @param list
*/
void onUserListUnsubscription(int forUser, User subscriber, User listOwner, UserList list);

/**
* @param forUser the user id to whom sent the event
* @param listOwner
* @param list
*/
void onUserListCreation(int forUser, User listOwner, UserList list);

/**
* @param forUser the user id to whom sent the event
* @param listOwner
* @param list
*/
void onUserListUpdate(int forUser, User listOwner, UserList list);

/**
* @param forUser the user id to whom sent the event
* @param listOwner
* @param list
*/
void onUserListDeletion(int forUser, User listOwner, UserList list);

/**
* @param forUser the user id to whom sent the event
* @param updatedUser updated user
* @since Twitter4J 2.1.9
*/
void onUserProfileUpdate(int forUser, User updatedUser);

/**
* @param forUser the user id to whom sent the event
* @param source
* @param blockedUser
*/
void onBlock(int forUser, User source, User blockedUser);

/**
* @param forUser the user id to whom sent the event
* @param source
* @param unblockedUser
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public final class JSONObjectType implements java.io.Serializable {
public static final JSONObjectType UNFAVORITE = new JSONObjectType("UNFAVORITE");
public static final JSONObjectType RETWEET = new JSONObjectType("RETWEET");
public static final JSONObjectType FOLLOW = new JSONObjectType("FOLLOW");
public static final JSONObjectType UNFOLLOW = new JSONObjectType("UNFOLLOW");
public static final JSONObjectType USER_LIST_MEMBER_ADDED = new JSONObjectType("USER_LIST_MEMBER_ADDED");
public static final JSONObjectType USER_LIST_MEMBER_DELETED = new JSONObjectType("USER_LIST_MEMBER_DELETED");
public static final JSONObjectType USER_LIST_SUBSCRIBED = new JSONObjectType("USER_LIST_SUBSCRIBED");
Expand Down Expand Up @@ -115,6 +116,8 @@ public static JSONObjectType determine(JSONObject json) {
return RETWEET;
} else if ("follow".equals(event)) {
return FOLLOW;
} else if ("unfollow".equals(event)) {
return UNFOLLOW;
} else if (event.startsWith("list")) {
if ("list_member_added".equals(event)) {
return USER_LIST_MEMBER_ADDED;
Expand Down
9 changes: 9 additions & 0 deletions twitter4j-core/src/test/java/twitter4j/SiteStreamsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public void testSiteStream() throws Exception {

// unfollow twit4j
twit4j2.destroyFriendship(6358482);
waitForStatus();

// follow twit4j
twit4j2.createFriendship(6358482);
Expand Down Expand Up @@ -198,6 +199,7 @@ public void testSiteStream() throws Exception {
assertReceived("onFavorite", TwitterMethod.CREATE_FAVORITE);
assertReceived("onUnfavorite", TwitterMethod.DESTROY_FAVORITE);
assertReceived("onFollow", TwitterMethod.CREATE_FRIENDSHIP);
assertReceived("onUnfollow", TwitterMethod.DESTROY_FRIENDSHIP);
// assertReceived(TwitterMethod.RETWEET_STATUS);
assertReceived("onDirectMessage", TwitterMethod.SEND_DIRECT_MESSAGE);

Expand Down Expand Up @@ -310,6 +312,13 @@ public void onFollow(int forUser, User source, User followedUser) {
notifyResponse();
}

public void onUnfollow(int forUser, User source, User followedUser) {
received.add(new Object[]{TwitterMethod.DESTROY_FRIENDSHIP, forUser, source, followedUser});
assertNotNull(DataObjectFactory.getRawJSON(source));
assertNotNull(DataObjectFactory.getRawJSON(followedUser));
notifyResponse();
}

public void onDirectMessage(int forUser, DirectMessage directMessage) {
received.add(new Object[]{TwitterMethod.SEND_DIRECT_MESSAGE, forUser, directMessage});
assertNotNull(DataObjectFactory.getRawJSON(directMessage));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ public void onFollow(int forUser, User source, User followedUser) {
+ followedUser.getScreenName());
}

public void onUnfollow(int forUser, User source, User followedUser) {
System.out.println("onUnfollow for_user:" + forUser + " source:@"
+ source.getScreenName() + " target:@"
+ followedUser.getScreenName());
}

public void onDirectMessage(int forUser, DirectMessage directMessage) {
System.out.println("onDirectMessage for_user:" + forUser + " text:"
+ directMessage.getText());
Expand Down

0 comments on commit 6507c91

Please sign in to comment.