Search in sources :

Example 1 with StatusDetails

use of org.springframework.social.twitter.api.StatusDetails 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 StatusDetails

use of org.springframework.social.twitter.api.StatusDetails 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

Secured (org.springframework.security.access.annotation.Secured)2 StatusDetails (org.springframework.social.twitter.api.StatusDetails)2 Tweet (org.springframework.social.twitter.api.Tweet)2 Twitter (org.springframework.social.twitter.api.Twitter)2 TwitterTemplate (org.springframework.social.twitter.api.impl.TwitterTemplate)2