use of org.springframework.social.twitter.api.impl.TwitterTemplate in project Gemma by PavlidisLab.
the class TwitterOutboundImpl method sendManualTweet.
@Override
@Secured({ "GROUP_ADMIN" })
public void sendManualTweet(String feed) {
TwitterOutboundImpl.log.debug("Checking if Twitter is enabled");
if (!Settings.getBoolean("gemma.twitter.enabled")) {
TwitterOutboundImpl.log.info("Twitter is disabled.");
return;
}
if (StringUtils.isNotBlank(feed)) {
TwitterOutboundImpl.log.info("Sending out tweet: '" + feed + "'");
String consumerKey = Settings.getString("twitter.consumer-key");
String consumerSecret = Settings.getString("twitter.consumer-secret");
String accessToken = Settings.getString("twitter.access-token");
String accessTokenSecret = Settings.getString("twitter.access-token-secret");
Twitter twitter = new TwitterTemplate(consumerKey, consumerSecret, accessToken, accessTokenSecret);
StatusDetails metadata = new StatusDetails();
metadata.setWrapLinks(true);
try {
Tweet tweet = twitter.timelineOperations().updateStatus(feed, metadata);
TwitterOutboundImpl.log.info("tweet info:" + tweet.toString());
} catch (Exception e) {
TwitterOutboundImpl.log.info(e.toString());
e.printStackTrace();
}
}
}
use of org.springframework.social.twitter.api.impl.TwitterTemplate in project spring-integration by spring-projects.
the class SearchReceivingMessageSourceTests method testSearchReceivingMessageSourceInit.
/**
* Unit Test ensuring some basic initialization properties being set.
*/
@Test
public void testSearchReceivingMessageSourceInit() {
final SearchReceivingMessageSource messageSource = new SearchReceivingMessageSource(new TwitterTemplate("test"), "foo");
messageSource.setComponentName("twitterSearchMessageSource");
final Object metadataStore = TestUtils.getPropertyValue(messageSource, "metadataStore");
final Object metadataKey = TestUtils.getPropertyValue(messageSource, "metadataKey");
assertNull(metadataStore);
assertNotNull(metadataKey);
messageSource.setBeanFactory(mock(BeanFactory.class));
messageSource.afterPropertiesSet();
final Object metadataStoreInitialized = TestUtils.getPropertyValue(messageSource, "metadataStore");
final Object metadataKeyInitialized = TestUtils.getPropertyValue(messageSource, "metadataKey");
assertNotNull(metadataStoreInitialized);
assertTrue(metadataStoreInitialized instanceof SimpleMetadataStore);
assertNotNull(metadataKeyInitialized);
assertEquals("foo", metadataKeyInitialized);
final Twitter twitter = TestUtils.getPropertyValue(messageSource, "twitter", Twitter.class);
assertFalse(twitter.isAuthorized());
assertNotNull(twitter.userOperations());
}
use of org.springframework.social.twitter.api.impl.TwitterTemplate in project spring-integration by spring-projects.
the class DirectMessageReceivingMessageSourceTests method demoReceiveDm.
@SuppressWarnings("unchecked")
@Test
@Ignore
public void demoReceiveDm() throws Exception {
PropertiesFactoryBean pf = new PropertiesFactoryBean();
pf.setLocation(new ClassPathResource("sample.properties"));
pf.afterPropertiesSet();
Properties prop = pf.getObject();
TwitterTemplate template = new TwitterTemplate(prop.getProperty("z_oleg.oauth.consumerKey"), prop.getProperty("z_oleg.oauth.consumerSecret"), prop.getProperty("z_oleg.oauth.accessToken"), prop.getProperty("z_oleg.oauth.accessTokenSecret"));
DirectMessageReceivingMessageSource tSource = new DirectMessageReceivingMessageSource(template, "foo");
tSource.afterPropertiesSet();
for (int i = 0; i < 50; i++) {
Message<DirectMessage> message = (Message<DirectMessage>) tSource.receive();
if (message != null) {
DirectMessage tweet = message.getPayload();
logger.info(tweet.getSender().getScreenName() + " - " + tweet.getText() + " - " + tweet.getCreatedAt());
}
}
}
use of org.springframework.social.twitter.api.impl.TwitterTemplate in project spring-integration by spring-projects.
the class DirectMessageSendingMessageHandlerTests method validateSendDirectMessage.
@Test
@Ignore
public void validateSendDirectMessage() throws Exception {
PropertiesFactoryBean pf = new PropertiesFactoryBean();
pf.setLocation(new ClassPathResource("sample.properties"));
pf.afterPropertiesSet();
Properties prop = pf.getObject();
TwitterTemplate template = new TwitterTemplate(prop.getProperty("spring_eip.oauth.consumerKey"), prop.getProperty("spring_eip.oauth.consumerSecret"), prop.getProperty("spring_eip.oauth.accessToken"), prop.getProperty("spring_eip.oauth.accessTokenSecret"));
Message<?> message1 = MessageBuilder.withPayload("Polsihing SI Twitter migration").setHeader(TwitterHeaders.DM_TARGET_USER_ID, "z_oleg").build();
DirectMessageSendingMessageHandler handler = new DirectMessageSendingMessageHandler(template);
handler.afterPropertiesSet();
handler.handleMessage(message1);
}
use of org.springframework.social.twitter.api.impl.TwitterTemplate in project Gemma by PavlidisLab.
the class TwitterOutboundImpl method sendDailyFeed.
@Override
@Secured({ "GROUP_AGENT" })
public void sendDailyFeed() {
TwitterOutboundImpl.log.debug("Checking if Twitter is enabled");
if (!TwitterOutboundImpl.enabled.get()) {
return;
}
String feed = this.generateDailyFeed();
TwitterOutboundImpl.log.info("Twitter is enabled. Checking if Twitter feed is empty.");
if (StringUtils.isNotBlank(feed)) {
TwitterOutboundImpl.log.info("Sending out tweet: '" + feed + "'");
String consumerKey = Settings.getString("twitter.consumer-key");
String consumerSecret = Settings.getString("twitter.consumer-secret");
String accessToken = Settings.getString("twitter.access-token");
String accessTokenSecret = Settings.getString("twitter.access-token-secret");
Twitter twitter = new TwitterTemplate(consumerKey, consumerSecret, accessToken, accessTokenSecret);
StatusDetails metadata = new StatusDetails();
metadata.setWrapLinks(true);
try {
Tweet tweet = twitter.timelineOperations().updateStatus(feed, metadata);
TwitterOutboundImpl.log.info("tweet info:" + tweet.toString());
} catch (Exception e) {
TwitterOutboundImpl.log.info(e.toString());
}
}
}
Aggregations