Package org.encuestame.utils

Examples of org.encuestame.utils.TweetPublishedMetadata


        tweetParams.add("state","published");       
        tweetParams.add("body",status);
        final ResponseEntity<Map> response = getRestTemplate().postForEntity(PUT_STATUS.replace("{username}", account.getSocialAccountName()), tweetParams, Map.class);
        final Map body = response.getBody();
        //Responses table: http://www.tumblr.com/docs/en/api/v2#common-fields
        final TweetPublishedMetadata metadata = createStatus(status);
        final Map response_body = (Map) body.get("response");
        metadata.setTweetId(response_body.get("id").toString());
    return metadata;
  }
View Full Code Here


    public TweetPublishedMetadata updateTwitterStatus(final String tweet) throws TwitterException{
        log.debug("twitter update status 2--> "+tweet);
        final Twitter twitter = this.getTwitterInstance();
        final Status twitterStatus = twitter.updateStatus(tweet);
        log.debug("twitter update status "+twitterStatus);
        TweetPublishedMetadata status = createStatus(tweet);
        status.setTweetId(String.valueOf(twitterStatus.getId()));
        //statusTweet.set status.g
        status.setDatePublished(twitterStatus.getCreatedAt());
        status.setProvider(this.socialAccount.getAccounType().name());
        status.setSocialAccountId(this.socialAccount.getId());
        status.setSocialAccountName(this.socialAccount.getSocialAccountName());
        //statusTweet.setProvider(SocialProvider.TWITTER);
        log.debug("twitter update statusTweet "+status);
        return status;
    }
View Full Code Here

        log.debug("Identica updateStatus "+response.getBody());
        log.debug("Identica updateStatus "+response.getHeaders());
        log.debug("Identica updateStatus "+response.getStatusCode());
        final Map body = response.getBody();
        //this.handleIdentiCaResponseErrors(response);
        final TweetPublishedMetadata status = createStatus(message);
        status.setTweetId(body.get("id").toString());
        return status;
    }
View Full Code Here

    /**
     *
     * @return
     */
    public TweetPublishedMetadata createStatus(final String tweetText) {
        final TweetPublishedMetadata published = new TweetPublishedMetadata();
        published.setDatePublished(Calendar.getInstance().getTime()); //TODO: should be offial time of tweet.
        published.setTextTweeted(tweetText);
        return published;
    }
View Full Code Here

    public TweetPublishedMetadata publish(String object, String connection, MultiValueMap<String, String> data) {
        final MultiValueMap<String, String> requestData = new LinkedMultiValueMap<String, String>(data);
        log.debug("before facebookResponse:{"+requestData);
        final Map facebookResponse = getRestTemplate().postForObject(CONNECTION_URL, requestData, Map.class, object, connection);
        log.debug("facebookResponse:{"+facebookResponse);
        final TweetPublishedMetadata status = createStatus(data.get("message").toString());
        status.setTweetId(facebookResponse.get("id").toString());
        return status;
    }
View Full Code Here

    //        "content": "juan test",
    //        "replurker_id": null,
    //        "posted": "Sun, 15 Dec 2013 12:04:00 GMT",
    //        "owner_id": 10210418
    //    }
        final TweetPublishedMetadata metadata = createStatus(status);
        //final Map response_body = (Map) body.get("plurk_id");
        metadata.setTweetId(body.get("plurk_id").toString());
    return metadata;
  }
View Full Code Here

     * @return status of tweet
     * @throws EnMeExpcetion exception
     */
    public TweetPublishedMetadata publicTweetPoll(final String tweetText, final SocialAccount socialAccount,  final Set<HashTag> hashtags)
           throws EnMeExpcetion {
        TweetPublishedMetadata published = new TweetPublishedMetadata();
        log.debug("publicTweetPoll:{ "+tweetText);
        if (socialAccount.getAccounType().equals(SocialProvider.TWITTER)) {
            log.debug("Publish on TWITTER");
            final TwitterAPIOperations twitterAPIOperations = new TwitterAPITemplate(
                    EnMePlaceHolderConfigurer.getProperty("twitter.oauth.consumerSecret"),
                    EnMePlaceHolderConfigurer.getProperty("twitter.oauth.consumerKey"),
                    socialAccount);
            try {
                published = twitterAPIOperations.updateStatus(tweetText);
            } catch (Exception e) {
                log.error(e);
                e.printStackTrace();
            }
        } else if (socialAccount.getAccounType().equals(SocialProvider.IDENTICA)) {
            log.debug("Publish on IDENTICA");
            final IdenticaAPIOperations identicaAPIOperations = new IdenticaAPITemplate(
                    EnMePlaceHolderConfigurer.getProperty("identica.consumer.key"),
                    EnMePlaceHolderConfigurer.getProperty("identica.consumer.secret"),
                    socialAccount.getAccessToken(),
                    socialAccount.getSecretToken());
            try {
                log.debug("Publish on Identica............>");
                published = identicaAPIOperations.updateStatus(tweetText);
                log.debug("Publish on Identica...... "+published);
            } catch (Exception e) {
                published.setDatePublished(Calendar.getInstance().getTime());
                log.error(e);
                e.printStackTrace();
            }
        } else if (socialAccount.getAccounType().equals(SocialProvider.PLURK)) {
            log.debug("Publish on PLURK");
            final PlurkAPIOperations tumblrAPIOperations = new PlurkAPITemplate(
                    EnMePlaceHolderConfigurer.getProperty("plurk.consumer.key"),
                    EnMePlaceHolderConfigurer.getProperty("plurk.consumer.secret"),
                    socialAccount.getAccessToken(),
                    socialAccount.getSecretToken());
            try {
                log.debug("Publish on Identica............>");
                published = tumblrAPIOperations.updateStatus(tweetText);
                log.debug("Publish on Identica...... "+published);
            } catch (Exception e) {
                published.setDatePublished(Calendar.getInstance().getTime());
                log.error(e);
                e.printStackTrace();
            }                   
        } else if (socialAccount.getAccounType().equals(SocialProvider.TUMBLR)) {
            log.debug("Publish on TUMBLR");
            final TumblrAPIOperations tumblrAPIOperations = new TumblrAPITemplate(
                    EnMePlaceHolderConfigurer.getProperty("tumblr.consumer.key"),
                    EnMePlaceHolderConfigurer.getProperty("tumblr.consumer.secret"),
                    socialAccount.getAccessToken(),
                    socialAccount.getSecretToken());
            try {
                log.debug("Publish on TUMBLR............>");
                published = tumblrAPIOperations.updateStatus(tweetText, socialAccount, hashtags);
                log.debug("Publish on TUMBLR...... "+published);
            } catch (Exception e) {
                published.setDatePublished(Calendar.getInstance().getTime());
                log.error(e);
                e.printStackTrace();
            }
        } else if (socialAccount.getAccounType().equals(SocialProvider.FACEBOOK)) {
            log.debug("Publish on FACEBOOK");
            FacebookAPIOperations facebookAPIOperations = new FacebookAPITemplate(socialAccount.getAccessToken());
            try {
                log.debug("Publish on FACEBOOK............>");
                published = facebookAPIOperations.updateStatus(tweetText);
                log.debug("Publish on FACEBOOK...... "+published);
                published.setDatePublished(Calendar.getInstance().getTime());
            } catch (HttpClientErrorException e) {
                log.error("-----------------------FACEBOOK EXPIRED TOKEN----------------------- 1");
                log.error(e.getStatusCode());
                log.error(e.getResponseBodyAsString());
                log.error(e.getStatusText());
                published.setDatePublished(Calendar.getInstance().getTime());
                // refresh token point.
                //offline_access scope permission is enabled by default . In this case
                //https://developers.facebook.com/docs/authentication/permissions/
                log.error("-----------------------FACEBOOK EXPIRED TOKEN----------------------- 2");
                e.printStackTrace();
            } catch (Exception e) {
                published.setDatePublished(Calendar.getInstance().getTime());
                log.error(e);
                e.printStackTrace();
            }
        } else if (socialAccount.getAccounType().equals(SocialProvider.LINKEDIN)) {
            log.debug("Publish on LinkedIn");
            LinkedInAPIOperations linkedInAPIOperations = new LinkedInAPITemplate(
                    EnMePlaceHolderConfigurer.getProperty("linkedIn.oauth.api.key"),
                    EnMePlaceHolderConfigurer.getProperty("linkedIn.oauth.api.secret"),
                    socialAccount.getAccessToken(),
                    socialAccount.getSecretToken());
            try {
                log.debug("Publish on LinkedIn 1............>");
                published = linkedInAPIOperations.updateStatus(tweetText);
                published.setTextTweeted(tweetText);
                published.setDatePublished(Calendar.getInstance().getTime());
                published.setTweetId(RandomStringUtils.randomAscii(15));
                log.debug("Publish on LinkedIn 2...... "+published);
            } catch (Exception e) {
                published.setDatePublished(Calendar.getInstance().getTime());
                log.error(e);
                e.printStackTrace();
            }
        } else if (socialAccount.getAccounType().equals(SocialProvider.GOOGLE_BUZZ)) {
            BuzzAPIOperations buzzInAPIOperations = new GoogleBuzzAPITemplate(socialAccount);
            try {
                log.debug("Publish on LinkedIn............>");
                published = buzzInAPIOperations.updateStatus(tweetText);
                published.setTextTweeted(tweetText);
                published.setDatePublished(Calendar.getInstance().getTime());
                published.setTweetId(RandomStringUtils.randomAscii(15));
                log.debug("Publish on LinkedIn...... "+published);
            } catch (Exception e) {
                published.setDatePublished(Calendar.getInstance().getTime());
                log.error(e);
                e.printStackTrace();
            }
        }
        if (published != null) {
            log.debug("publicTweetPoll:s "+published.toString());
        }
        return published;
    }
View Full Code Here

             log.debug("socialAccount Account NAME:{"+socialAccount.getSocialAccountName());
             //adding social account
             publishedStatus.setSocialAccount(socialAccount);
             try {
                 log.debug("publishTweetPoll Publishing... "+tweetText.length());
                 final TweetPublishedMetadata metadata = publicTweetPoll(tweetText, socialAccount, hashTags);
                 if (metadata == null || metadata.getTweetId() == null) {
                     throw new EnMeFailSendSocialTweetException("status not valid");
                 }//getMessageProperties(propertieId)
                 if (metadata.getTweetId() == null) {
                     log.warn("tweet id is empty");
                 }
                 //store original tweet id.
                 publishedStatus.setTweetId(metadata.getTweetId());
                 //store original publication date.
                 publishedStatus.setPublicationDateTweet(metadata.getDatePublished());
                 //success publish state..
                 publishedStatus.setStatus(Status.SUCCESS);
                 //store original tweet content.
                 publishedStatus.setTweetContent(metadata.getTextTweeted());
                 //create notification
                 //createNotification(NotificationEnum.TWEETPOLL_PUBLISHED, "tweet published", socialAccount.getAccount());
                 createNotification(NotificationEnum.SOCIAL_MESSAGE_PUBLISHED, tweetText, SocialUtils.getSocialTweetPublishedUrl(
                         metadata.getTweetId(), socialAccount.getSocialAccountName(), socialAccount.getAccounType()), Boolean.TRUE);
             } catch (Exception e) {
                 e.printStackTrace();
                 log.error("Error publish tweet:{"+e);
                 //change status to failed
                 publishedStatus.setStatus(Status.FAILED);
View Full Code Here

TOP

Related Classes of org.encuestame.utils.TweetPublishedMetadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.