refactored the twitter package to use interface types for the domain model, which gives us wiggle room to move to Spring Social
This commit is contained in:
@@ -41,12 +41,13 @@ abstract public class AbstractInboundTwitterStatusEndpointSupport
|
||||
return status.getCreatedAt().compareTo(status1.getCreatedAt());
|
||||
}
|
||||
};
|
||||
protected List<Status> fromTwitter4jStatus(List<twitter4j.Status> stats) {
|
||||
List<Status> fwd = new ArrayList<Status>();
|
||||
for (twitter4j.Status s : stats)
|
||||
fwd.add(new Twitter4jStatusImpl(s));
|
||||
return fwd;
|
||||
}
|
||||
|
||||
protected List<Status> fromTwitter4jStatuses(List<twitter4j.Status> stats) {
|
||||
List<Status> fwd = new ArrayList<Status>();
|
||||
for (twitter4j.Status s : stats)
|
||||
fwd.add(new Twitter4jStatusImpl(s));
|
||||
return fwd;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void markLastStatusId(Status statusId) {
|
||||
|
||||
@@ -40,7 +40,7 @@ public class InboundMentionStatusEndpoint
|
||||
: twitter.getMentions(new Paging(ctx.getMarkerId()));
|
||||
|
||||
|
||||
forwardAll( fromTwitter4jStatus( stats));
|
||||
forwardAll( fromTwitter4jStatuses( stats));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class InboundUpdatedStatusEndpoint extends AbstractInboundTwitterStatusEn
|
||||
this.runAsAPIRateLimitsPermit(new ApiCallback<InboundUpdatedStatusEndpoint>() {
|
||||
public void run(InboundUpdatedStatusEndpoint t, Twitter twitter)
|
||||
throws Exception {
|
||||
forwardAll( fromTwitter4jStatus(!t.hasMarkedStatus()
|
||||
forwardAll( fromTwitter4jStatuses(!t.hasMarkedStatus()
|
||||
? twitter.getFriendsTimeline() :
|
||||
twitter.getFriendsTimeline(new Paging(t.getMarkerId()))));
|
||||
}
|
||||
|
||||
@@ -33,6 +33,16 @@ import twitter4j.StatusUpdate;
|
||||
* @since 2.0
|
||||
*/
|
||||
public class StatusUpdateSupport {
|
||||
|
||||
/**
|
||||
* convenient, interf-ace-oriented way of obtaining a reference to a {@link org.springframework.integration.twitter.model.Twitter4jGeoLocationImpl}
|
||||
* @param lat the latitude
|
||||
* @param lon the longitude
|
||||
* @return a {@link org.springframework.integration.twitter.model.GeoLocation} instance
|
||||
*/
|
||||
public GeoLocation fromLatitudeLongitudePair ( double lat, double lon){
|
||||
return new Twitter4jGeoLocationImpl(lat, lon);
|
||||
}
|
||||
/**
|
||||
* {@link StatusUpdate} instances are used to drive status updates.
|
||||
*
|
||||
@@ -67,18 +77,18 @@ public class StatusUpdateSupport {
|
||||
}
|
||||
}
|
||||
|
||||
if (message.getHeaders()
|
||||
.containsKey(TwitterHeaders.TWITTER_GEOLOCATION)) {
|
||||
GeoLocation geoLocation = (GeoLocation) message.getHeaders()
|
||||
.get(TwitterHeaders.TWITTER_GEOLOCATION);
|
||||
if (message.getHeaders().containsKey(TwitterHeaders.TWITTER_GEOLOCATION)) {
|
||||
|
||||
GeoLocation geoLocation = (GeoLocation) message.getHeaders()
|
||||
.get(TwitterHeaders.TWITTER_GEOLOCATION);
|
||||
twitter4j.GeoLocation gl = null;
|
||||
|
||||
if (geoLocation instanceof Twitter4jGeoLocationImpl) {
|
||||
gl = ((Twitter4jGeoLocationImpl) geoLocation).getGeoLocation();
|
||||
}
|
||||
|
||||
if (null != gl) {
|
||||
statusUpdate.location(gl);
|
||||
if (null != gl) {
|
||||
statusUpdate.location(gl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,9 @@ import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* implementation of the {@link org.springframework.integration.twitter.model.DirectMessage} interface
|
||||
* that wraps, and works with, a {@link twitter4j.DirectMessage} instance.
|
||||
*
|
||||
* @author Josh Long
|
||||
*/
|
||||
public class Twitter4jDirectMessageImpl implements org.springframework.integration.twitter.model.DirectMessage {
|
||||
|
||||
@@ -12,7 +12,9 @@ public class Twitter4jGeoLocationImpl implements GeoLocation {
|
||||
public twitter4j.GeoLocation getGeoLocation() {
|
||||
return this.geoLocation;
|
||||
}
|
||||
|
||||
public Twitter4jGeoLocationImpl(double lat, double lon){
|
||||
this.geoLocation = new twitter4j.GeoLocation(lat,lon);
|
||||
}
|
||||
public Twitter4jGeoLocationImpl(twitter4j.GeoLocation gl) {
|
||||
this.geoLocation = gl;
|
||||
}
|
||||
|
||||
@@ -24,11 +24,11 @@ import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.core.MessagingTemplate;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.twitter.model.Twitter4jGeoLocationImpl;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import twitter4j.GeoLocation;
|
||||
|
||||
/**
|
||||
* @author Josh Long
|
||||
@@ -49,7 +49,7 @@ public class TestSendingDMsUsingNamespace extends AbstractJUnit4SpringContextTes
|
||||
String dmUsr = System.getProperties().getProperty("twitter.dm.user");
|
||||
|
||||
MessageBuilder<String> mb = MessageBuilder.withPayload("'Hello world!', from the Spring Integration outbound Twitter adapter")
|
||||
.setHeader(TwitterHeaders.TWITTER_GEOLOCATION, new GeoLocation(-76.226823, 23.642465)) // antarctica
|
||||
.setHeader(TwitterHeaders.TWITTER_GEOLOCATION, new Twitter4jGeoLocationImpl(-76.226823, 23.642465)) // antarctica
|
||||
.setHeader(TwitterHeaders.TWITTER_DISPLAY_COORDINATES, true);
|
||||
|
||||
if (StringUtils.hasText(dmUsr)) {
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.integration.twitter;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
@@ -27,8 +26,6 @@ import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
||||
|
||||
import twitter4j.GeoLocation;
|
||||
|
||||
/**
|
||||
* @author Josh Long
|
||||
*/
|
||||
@@ -37,6 +34,8 @@ import twitter4j.GeoLocation;
|
||||
)
|
||||
public class TestSendingUpdatesUsingNamespace extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
private StatusUpdateSupport statusUpdateSupport = new StatusUpdateSupport();
|
||||
|
||||
private MessagingTemplate messagingTemplate = new MessagingTemplate();
|
||||
|
||||
@Value("#{out}") private MessageChannel channel;
|
||||
@@ -46,7 +45,8 @@ public class TestSendingUpdatesUsingNamespace extends AbstractJUnit4SpringContex
|
||||
public void testSendingATweet() throws Throwable {
|
||||
MessageBuilder<String> mb = MessageBuilder.withPayload("'Hello world!', from the Spring Integration outbound Twitter adapter")
|
||||
.setHeader(TwitterHeaders.TWITTER_IN_REPLY_TO_STATUS_ID, 21927437001L)
|
||||
.setHeader(TwitterHeaders.TWITTER_GEOLOCATION, new GeoLocation(-76.226823, 23.642465)) // antarctica
|
||||
.setHeader(TwitterHeaders.TWITTER_GEOLOCATION,
|
||||
this.statusUpdateSupport.fromLatitudeLongitudePair(-76.226823, 23.642465)) // antarctica
|
||||
.setHeader(TwitterHeaders.TWITTER_DISPLAY_COORDINATES, true);
|
||||
Message<String> m = mb.build();
|
||||
this.messagingTemplate.send(this.channel, m);
|
||||
|
||||
Reference in New Issue
Block a user