use of org.springframework.social.twitter.api.Twitter 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.Twitter 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.Twitter in project spring-integration by spring-projects.
the class TestSearchReceivingMessageSourceParserTests method testSearchReceivingDefaultTemplate.
@Test
public void testSearchReceivingDefaultTemplate() {
ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext("TestSearchReceivingMessageSourceParser-context.xml", this.getClass());
SourcePollingChannelAdapter spca = ac.getBean("searchAdapterWithTemplate", SourcePollingChannelAdapter.class);
SearchReceivingMessageSource ms = (SearchReceivingMessageSource) TestUtils.getPropertyValue(spca, "source");
assertEquals(Integer.valueOf(23), TestUtils.getPropertyValue(ms, "pageSize", Integer.class));
Twitter template = (Twitter) TestUtils.getPropertyValue(ms, "twitter");
assertNotNull(template);
ac.close();
}
use of org.springframework.social.twitter.api.Twitter 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