INT-1553 Final modifications to align with Spring Social API, added tests for persistent metadatastore, tested every supported twiter function against the real twitter account

This commit is contained in:
Oleg Zhurakousky
2010-11-08 18:12:03 -05:00
parent 8a46cfc0e8
commit 2a8994d7b6
14 changed files with 370 additions and 89 deletions

View File

@@ -22,7 +22,6 @@ import org.springframework.util.Assert;
import twitter4j.DirectMessage;
import twitter4j.Paging;
import twitter4j.RateLimitStatus;
import twitter4j.ResponseList;
import twitter4j.Status;
import twitter4j.StatusUpdate;
@@ -204,12 +203,13 @@ public class Twitter4jTemplate implements TwitterOperations{
private Tweet buildTweetFromStatus(Status status){
Tweet tweet = new Tweet();
tweet.setCreatedAt(status.getCreatedAt());
tweet.setFromUser(status.getInReplyToScreenName());
tweet.setFromUserId(status.getInReplyToUserId());
if (status.getUser() != null){
tweet.setFromUser(status.getUser().getScreenName());
tweet.setFromUserId(status.getUser().getId());
}
tweet.setId(status.getId());
tweet.setSource(status.getSource());
tweet.setText(status.getText());
tweet.setToUserId((long)status.getUser().getId());
return tweet;
}
}

View File

@@ -34,14 +34,10 @@ import org.springframework.integration.store.MetadataStore;
import org.springframework.integration.store.SimpleMetadataStore;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.twitter.core.Tweet;
import org.springframework.integration.twitter.core.Twitter4jTemplate;
import org.springframework.integration.twitter.core.TwitterOperations;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import twitter4j.DirectMessage;
import twitter4j.Status;
/**
* Abstract class that defines common operations for receiving various types of
* messages when using the Twitter API. This class also handles keeping track of
@@ -125,6 +121,11 @@ public abstract class AbstractTwitterMessageSource<T> extends AbstractEndpoint
String profileId = twitter.getProfileId();
metadataKeyBuilder.append(profileId);
this.metadataKey = metadataKeyBuilder.toString();
String lastId = this.metadataStore.get(this.metadataKey);
// initialize the last status ID from the metadataStore
if (StringUtils.hasText(lastId)){
this.markLastStatusId(Long.parseLong(lastId));
}
}
@SuppressWarnings("unchecked")

View File

@@ -23,8 +23,6 @@ import org.springframework.integration.twitter.core.Tweet;
import org.springframework.integration.twitter.core.TwitterOperations;
import org.springframework.util.CollectionUtils;
import twitter4j.Paging;
/**
* This class handles support for receiving DMs (direct messages) using Twitter.
*

View File

@@ -21,8 +21,6 @@ import org.springframework.integration.MessagingException;
import org.springframework.integration.twitter.core.Tweet;
import org.springframework.integration.twitter.core.TwitterOperations;
import twitter4j.Paging;
/**
* Handles forwarding all new {@link twitter4j.Status} that are 'replies' or 'mentions' to some other tweet.
*

View File

@@ -21,8 +21,6 @@ import org.springframework.integration.MessagingException;
import org.springframework.integration.twitter.core.Tweet;
import org.springframework.integration.twitter.core.TwitterOperations;
import twitter4j.Paging;
/**
* This {@link org.springframework.integration.core.MessageSource} lets Spring Integration consume a given account's timeline

View File

@@ -45,30 +45,13 @@ public class OutboundTweetMessageMapper implements OutboundMessageMapper<Tweet>
Tweet tweet = null;
if (payload instanceof String) {
tweet = new Tweet();
tweet.setText((String) payload);
if (message.getHeaders().containsKey(TwitterHeaders.IN_REPLY_TO_STATUS_ID)) {
Long replyId = (Long) message.getHeaders().get(TwitterHeaders.IN_REPLY_TO_STATUS_ID);
if ((replyId != null) && (replyId > 0)) {
tweet.setToUserId(replyId);
}
}
// if (message.getHeaders().containsKey(TwitterHeaders.PLACE_ID)) {
// String placeId = (String) message.getHeaders().get(TwitterHeaders.PLACE_ID);
// if (StringUtils.hasText(placeId)) {
// statusUpdate.placeId(placeId);
// }
// }
// if (message.getHeaders().containsKey(TwitterHeaders.GEOLOCATION)) {
// GeoLocation geoLocation = (GeoLocation) message.getHeaders().get(TwitterHeaders.GEOLOCATION);
// if (null != geoLocation) {
// statusUpdate.location(geoLocation);
// }
// }
// if (message.getHeaders().containsKey(TwitterHeaders.DISPLAY_COORDINATES)) {
// Boolean displayCoords = (Boolean) message.getHeaders().get(TwitterHeaders.DISPLAY_COORDINATES);
// if (displayCoords != null) {
// statusUpdate.displayCoordinates(displayCoords);
// }
// }
}
else if (payload instanceof Tweet) {
tweet = (Tweet) payload;