Changeset - 6cc7c334f3c4
[Not reviewed]
0 4 2
Sarang Bharadwaj - 13 years ago 2012-06-15 11:45:41
sarang.bh@gmail.com
Retweet
6 files changed with 109 insertions and 1 deletions:
0 comments (0 inline, 0 general)
backends/twitter/Requests/RetweetRequest.cpp
Show inline comments
 
new file 100644
 
#include "RetweetRequest.h"
 
DEFINE_LOGGER(logger, "RetweetRequest")
 
void RetweetRequest::run()
 
{
 
	LOG4CXX_INFO(logger, user << " Retweeting " << data)
 
	success = twitObj->retweetById( data );
 
}
 

	
 
void RetweetRequest::finalize()
 
{
 
	replyMsg = "";
 
	if(!success) {
 
		twitObj->getLastCurlError( replyMsg );
 
		LOG4CXX_ERROR(logger, user << " " << replyMsg)
 
		callBack(user, replyMsg);
 
	} else {
 
		twitObj->getLastWebResponse( replyMsg );
 
		std::string error = getErrorMessage( replyMsg );
 
		if(error.length()) LOG4CXX_ERROR(logger, user << " " << error)
 
		else LOG4CXX_INFO(logger, user << " " << replyMsg);
 
		callBack(user, error);
 
	}
 
}
backends/twitter/Requests/RetweetRequest.h
Show inline comments
 
new file 100644
 
#ifndef RETWEET_H
 
#define RETWEET_H
 

	
 
#include "../ThreadPool.h"
 
#include "../TwitterResponseParser.h"
 
#include "../libtwitcurl/twitcurl.h"
 
#include "transport/networkplugin.h"
 
#include "transport/logging.h"
 
#include <boost/function.hpp>
 
#include <string>
 
#include <iostream>
 

	
 
using namespace Transport;
 
class RetweetRequest : public Thread
 
{
 
	twitCurl *twitObj;
 
	std::string data;
 
	std::string user;
 
	std::string replyMsg;
 
	bool success;
 
	boost::function < void (std::string&, std::string &) > callBack;
 

	
 
	public:
 
	RetweetRequest(twitCurl *obj, const std::string &_user, const std::string &_data,
 
			       boost::function < void (std::string &, std::string &) > _cb) {
 
		twitObj = obj->clone();
 
		data = _data;
 
		user = _user;
 
		callBack = _cb;
 
	}
 

	
 
	~RetweetRequest() {
 
		delete twitObj;
 
	}
 

	
 
	void run();
 
	void finalize();
 
};
 

	
 
#endif
backends/twitter/TwitterPlugin.cpp
Show inline comments
 
@@ -8,6 +8,7 @@
 
#include "Requests/OAuthFlow.h"
 
#include "Requests/CreateFriendRequest.h"
 
#include "Requests/DestroyFriendRequest.h"
 
#include "Requests/RetweetRequest.h"
 

	
 
DEFINE_LOGGER(logger, "Twitter Backend");
 

	
 
@@ -162,6 +163,8 @@ void TwitterPlugin::handleMessageSendRequest(const std::string &user, const std:
 
													   boost::bind(&TwitterPlugin::createFriendResponse, this, _1, _2, _3)));
 
		else if(cmd == "#unfollow") tp->runAsThread(new DestroyFriendRequest(sessions[user], user, data,
 
													   boost::bind(&TwitterPlugin::deleteFriendResponse, this, _1, _2, _3)));
 
		else if(cmd == "#retweet") tp->runAsThread(new RetweetRequest(sessions[user], user, data,
 
													   boost::bind(&TwitterPlugin::RetweetResponse, this, _1, _2)));
 
		else handleMessage(user, "twitter-account", "Unknown command! Type #help for a list of available commands.");
 
	} 
 

	
 
@@ -365,7 +368,7 @@ void TwitterPlugin::displayTweets(std::string &user, std::string &userRequested,
 
		std::string timeline = "";
 

	
 
		for(int i=0 ; i<tweets.size() ; i++) {
 
			timeline += " - " + tweets[i].getUserData().getScreenName() + ": " + tweets[i].getTweet() + "\n";
 
			timeline += " - " + tweets[i].getUserData().getScreenName() + ": " + tweets[i].getTweet() + " (MsgId: " + tweets[i].getID() + ")\n";
 
		}
 

	
 
		if((userRequested == "" || userRequested == user) && tweets.size()) {
 
@@ -444,3 +447,12 @@ void TwitterPlugin::deleteFriendResponse(std::string &user, std::string &frnd, s
 
	} else if(twitterMode == MULTIPLECONTACT) {
 
	}
 
}
 

	
 

	
 
void TwitterPlugin::RetweetResponse(std::string &user, std::string &errMsg)
 
{
 
	if(errMsg.length()) {
 
		handleMessage(user, "twitter-account", errMsg);
 
		return;
 
	}
 
}
backends/twitter/TwitterPlugin.h
Show inline comments
 
@@ -102,6 +102,7 @@ class TwitterPlugin : public NetworkPlugin {
 
		void directMessageResponse(std::string &user, std::vector<DirectMessage> &messages, std::string &errMsg);
 
		void createFriendResponse(std::string &user, std::string &frnd, std::string &errMsg);
 
		void deleteFriendResponse(std::string &user, std::string &frnd, std::string &errMsg);
 
		void RetweetResponse(std::string &user, std::string &errMsg);
 
		/***********************************************************************************/
 

	
 
	private:
backends/twitter/libtwitcurl/twitcurl.cpp
Show inline comments
 
@@ -435,6 +435,36 @@ bool twitCurl::statusDestroyById( std::string& statusId )
 
    return retVal;
 
}
 
 
/*++
 
* @method: twitCurl::retweetById
 
*
 
* @description: method to retweet a status message by its id
 
*
 
* @input: statusId - a number in std::string format
 
*
 
* @output: true if RETWEET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::retweetById( std::string& statusId )
 
{
 
    bool retVal = false;
 
    if( statusId.length() )
 
    {
 
        /* Prepare URL */
 
        std::string buildUrl = twitterDefaults::TWITCURL_RETWEET_URL + statusId +
 
                               twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
 
        /* Send some dummy data in POST */
 
        std::string dummyData = twitCurlDefaults::TWITCURL_TEXTSTRING +
 
                                urlencode( std::string( "dummy" ) );
 
 
        /* Perform Retweet */
 
        retVal = performPost( buildUrl, dummyData );
 
    }
 
    return retVal;
 
}
 
 
/*++
 
* @method: twitCurl::timelinePublicGet
 
*
backends/twitter/libtwitcurl/twitcurl.h
Show inline comments
 
@@ -61,6 +61,7 @@ namespace twitterDefaults
 
    const std::string TWITCURL_STATUSUPDATE_URL = "http://api.twitter.com/1/statuses/update";
 
    const std::string TWITCURL_STATUSSHOW_URL = "http://api.twitter.com/1/statuses/show/";
 
    const std::string TWITCURL_STATUDESTROY_URL = "http://api.twitter.com/1/statuses/destroy/";
 
	const std::string TWITCURL_RETWEET_URL = "http://api.twitter.com/1/statuses/retweet/";
 
 
    /* Timeline URLs */
 
    const std::string TWITCURL_HOME_TIMELINE_URL = "http://api.twitter.com/1/statuses/home_timeline";
 
@@ -147,6 +148,7 @@ public:
 
    bool statusUpdate( std::string& newStatus /* in */ );
 
    bool statusShowById( std::string& statusId /* in */ );
 
    bool statusDestroyById( std::string& statusId /* in */ );
 
	bool retweetById( std::string& statusId /* in */);
 
 
    /* Twitter timeline APIs */
 
    bool timelineHomeGet(std::string sinceId = ""  /* in */);
0 comments (0 inline, 0 general)