Search in sources :

Example 1 with Twitter

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();
        }
    }
}
Also used : TwitterTemplate(org.springframework.social.twitter.api.impl.TwitterTemplate) Tweet(org.springframework.social.twitter.api.Tweet) StatusDetails(org.springframework.social.twitter.api.StatusDetails) Twitter(org.springframework.social.twitter.api.Twitter) Secured(org.springframework.security.access.annotation.Secured)

Example 2 with Twitter

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());
}
Also used : TwitterTemplate(org.springframework.social.twitter.api.impl.TwitterTemplate) BeanFactory(org.springframework.beans.factory.BeanFactory) Twitter(org.springframework.social.twitter.api.Twitter) SimpleMetadataStore(org.springframework.integration.metadata.SimpleMetadataStore) Test(org.junit.Test)

Example 3 with Twitter

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();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SearchReceivingMessageSource(org.springframework.integration.twitter.inbound.SearchReceivingMessageSource) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Twitter(org.springframework.social.twitter.api.Twitter) Test(org.junit.Test)

Example 4 with Twitter

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());
        }
    }
}
Also used : TwitterTemplate(org.springframework.social.twitter.api.impl.TwitterTemplate) Tweet(org.springframework.social.twitter.api.Tweet) StatusDetails(org.springframework.social.twitter.api.StatusDetails) Twitter(org.springframework.social.twitter.api.Twitter) Secured(org.springframework.security.access.annotation.Secured)

Aggregations

Twitter (org.springframework.social.twitter.api.Twitter)4 TwitterTemplate (org.springframework.social.twitter.api.impl.TwitterTemplate)3 Test (org.junit.Test)2 Secured (org.springframework.security.access.annotation.Secured)2 StatusDetails (org.springframework.social.twitter.api.StatusDetails)2 Tweet (org.springframework.social.twitter.api.Tweet)2 BeanFactory (org.springframework.beans.factory.BeanFactory)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1 SourcePollingChannelAdapter (org.springframework.integration.endpoint.SourcePollingChannelAdapter)1 SimpleMetadataStore (org.springframework.integration.metadata.SimpleMetadataStore)1 SearchReceivingMessageSource (org.springframework.integration.twitter.inbound.SearchReceivingMessageSource)1