update twitcurl dependency to latest revision

This commit is contained in:
vitalyster 2013-07-07 07:19:15 +00:00
parent 3a80854500
commit 40fb5c2d3f
10 changed files with 701 additions and 564 deletions

View file

@ -120,4 +120,4 @@ std::string base64_decode(std::string const& encoded_string) {
}
return ret;
}
}

View file

@ -1,4 +1,4 @@
#include <string>
std::string base64_encode(unsigned char const* , unsigned int len);
std::string base64_decode(std::string const& s);
std::string base64_decode(std::string const& s);

View file

@ -1,3 +1,4 @@
#include "twitcurlurls.h"
#include "oauthlib.h"
#include "HMAC_SHA1.h"
#include "base64.h"
@ -43,16 +44,16 @@ oAuth::~oAuth()
*--*/
oAuth oAuth::clone()
{
oAuth cloneObj;
cloneObj.m_consumerKey = m_consumerKey;
cloneObj.m_consumerSecret = m_consumerSecret;
cloneObj.m_oAuthTokenKey = m_oAuthTokenKey;
cloneObj.m_oAuthTokenSecret = m_oAuthTokenSecret;
cloneObj.m_oAuthPin = m_oAuthPin;
cloneObj.m_nonce = m_nonce;
cloneObj.m_timeStamp = m_timeStamp;
cloneObj.m_oAuthScreenName = m_oAuthScreenName;
return cloneObj;
oAuth cloneObj;
cloneObj.m_consumerKey = m_consumerKey;
cloneObj.m_consumerSecret = m_consumerSecret;
cloneObj.m_oAuthTokenKey = m_oAuthTokenKey;
cloneObj.m_oAuthTokenSecret = m_oAuthTokenSecret;
cloneObj.m_oAuthPin = m_oAuthPin;
cloneObj.m_nonce = m_nonce;
cloneObj.m_timeStamp = m_timeStamp;
cloneObj.m_oAuthScreenName = m_oAuthScreenName;
return cloneObj;
}
@ -254,7 +255,7 @@ void oAuth::generateNonceTimeStamp()
char szRand[oAuthLibDefaults::OAUTHLIB_BUFFSIZE];
memset( szTime, 0, oAuthLibDefaults::OAUTHLIB_BUFFSIZE );
memset( szRand, 0, oAuthLibDefaults::OAUTHLIB_BUFFSIZE );
srand( time( NULL ) );
srand( (unsigned int)time( NULL ) );
sprintf( szRand, "%x", rand()%1000 );
sprintf( szTime, "%ld", time( NULL ) );
@ -285,35 +286,22 @@ void oAuth::buildOAuthRawDataKeyValPairs( const std::string& rawData,
oAuthKeyValuePairs& rawDataKeyValuePairs )
{
/* Raw data if it's present. Data should already be urlencoded once */
if( rawData.length() )
if( rawData.empty() )
{
size_t nSep = std::string::npos;
size_t nPos = std::string::npos;
std::string dataKeyVal;
std::string dataKey;
std::string dataVal;
return;
}
/* This raw data part can contain many key value pairs: key1=value1&key2=value2&key3=value3 */
std::string dataPart = rawData;
while( std::string::npos != ( nSep = dataPart.find_first_of("&") ) )
{
/* Extract first key=value pair */
dataKeyVal = dataPart.substr( 0, nSep );
size_t nSep = std::string::npos;
size_t nPos = std::string::npos;
std::string dataKeyVal;
std::string dataKey;
std::string dataVal;
/* Split them */
nPos = dataKeyVal.find_first_of( "=" );
if( std::string::npos != nPos )
{
dataKey = dataKeyVal.substr( 0, nPos );
dataVal = dataKeyVal.substr( nPos + 1 );
/* Put this key=value pair in map */
rawDataKeyValuePairs[dataKey] = urlencodeData ? urlencode( dataVal ) : dataVal;
}
dataPart = dataPart.substr( nSep + 1 );
}
/* For the last key=value */
/* This raw data part can contain many key value pairs: key1=value1&key2=value2&key3=value3 */
std::string dataPart = rawData;
while( std::string::npos != ( nSep = dataPart.find_first_of("&") ) )
{
/* Extract first key=value pair */
dataKeyVal = dataPart.substr( 0, nSep );
/* Split them */
@ -326,6 +314,21 @@ void oAuth::buildOAuthRawDataKeyValPairs( const std::string& rawData,
/* Put this key=value pair in map */
rawDataKeyValuePairs[dataKey] = urlencodeData ? urlencode( dataVal ) : dataVal;
}
dataPart = dataPart.substr( nSep + 1 );
}
/* For the last key=value */
dataKeyVal = dataPart.substr( 0, nSep );
/* Split them */
nPos = dataKeyVal.find_first_of( "=" );
if( std::string::npos != nPos )
{
dataKey = dataKeyVal.substr( 0, nPos );
dataVal = dataKeyVal.substr( nPos + 1 );
/* Put this key=value pair in map */
rawDataKeyValuePairs[dataKey] = urlencodeData ? urlencode( dataVal ) : dataVal;
}
}
@ -390,7 +393,7 @@ bool oAuth::buildOAuthTokenKeyValuePairs( const bool includeOAuthVerifierPin,
/* Version */
keyValueMap[oAuthLibDefaults::OAUTHLIB_VERSION_KEY] = std::string( "1.0" );
return ( keyValueMap.size() ) ? true : false;
return !keyValueMap.empty();
}
/*++
@ -417,7 +420,7 @@ bool oAuth::getSignature( const eOAuthHttpRequestType eType,
std::string sigBase;
/* Initially empty signature */
oAuthSignature.assign( "" );
oAuthSignature = "";
/* Build a string using key-value pairs */
paramsSeperator = "&";
@ -481,7 +484,7 @@ bool oAuth::getSignature( const eOAuthHttpRequestType eType,
/* Do an url encode */
oAuthSignature = urlencode( base64Str );
return ( oAuthSignature.length() ) ? true : false;
return !oAuthSignature.empty();
}
/*++
@ -511,7 +514,7 @@ bool oAuth::getOAuthHeader( const eOAuthHttpRequestType eType,
std::string pureUrl( rawUrl );
/* Clear header string initially */
oAuthHttpHeader.assign( "" );
oAuthHttpHeader = "";
rawKeyValuePairs.clear();
/* If URL itself contains ?key=value, then extract and put them in map */
@ -551,7 +554,7 @@ bool oAuth::getOAuthHeader( const eOAuthHttpRequestType eType,
oAuthHttpHeader.assign( oAuthLibDefaults::OAUTHLIB_AUTHHEADER_STRING );
oAuthHttpHeader.append( rawParams );
return ( oAuthHttpHeader.length() ) ? true : false;
return !oAuthHttpHeader.empty();
}
/*++
@ -571,48 +574,50 @@ bool oAuth::getStringFromOAuthKeyValuePairs( const oAuthKeyValuePairs& rawParamM
std::string& rawParams,
const std::string& paramsSeperator )
{
rawParams.assign( "" );
if( rawParamMap.size() )
rawParams = "";
if( rawParamMap.empty() )
{
oAuthKeyValueList keyValueList;
std::string dummyStr;
/* Push key-value pairs to a list of strings */
keyValueList.clear();
oAuthKeyValuePairs::const_iterator itMap = rawParamMap.begin();
for( ; itMap != rawParamMap.end(); itMap++ )
{
dummyStr.assign( itMap->first );
dummyStr.append( "=" );
if( paramsSeperator == "," )
{
dummyStr.append( "\"" );
}
dummyStr.append( itMap->second );
if( paramsSeperator == "," )
{
dummyStr.append( "\"" );
}
keyValueList.push_back( dummyStr );
}
/* Sort key-value pairs based on key name */
keyValueList.sort();
/* Now, form a string */
dummyStr.assign( "" );
oAuthKeyValueList::iterator itKeyValue = keyValueList.begin();
for( ; itKeyValue != keyValueList.end(); itKeyValue++ )
{
if( dummyStr.length() )
{
dummyStr.append( paramsSeperator );
}
dummyStr.append( itKeyValue->c_str() );
}
rawParams.assign( dummyStr );
return false;
}
return ( rawParams.length() ) ? true : false;
oAuthKeyValueList keyValueList;
std::string dummyStr;
/* Push key-value pairs to a list of strings */
keyValueList.clear();
oAuthKeyValuePairs::const_iterator itMap = rawParamMap.begin();
for( ; itMap != rawParamMap.end(); itMap++ )
{
dummyStr.assign( itMap->first );
dummyStr.append( "=" );
if( paramsSeperator == "," )
{
dummyStr.append( "\"" );
}
dummyStr.append( itMap->second );
if( paramsSeperator == "," )
{
dummyStr.append( "\"" );
}
keyValueList.push_back( dummyStr );
}
/* Sort key-value pairs based on key name */
keyValueList.sort();
/* Now, form a string */
dummyStr = "";
oAuthKeyValueList::iterator itKeyValue = keyValueList.begin();
for( ; itKeyValue != keyValueList.end(); itKeyValue++ )
{
if( dummyStr.length() )
{
dummyStr.append( paramsSeperator );
}
dummyStr.append( itKeyValue->c_str() );
}
rawParams = dummyStr;
return !rawParams.empty();
}
/*++
@ -628,45 +633,49 @@ bool oAuth::getStringFromOAuthKeyValuePairs( const oAuthKeyValuePairs& rawParamM
*--*/
bool oAuth::extractOAuthTokenKeySecret( const std::string& requestTokenResponse )
{
if( requestTokenResponse.length() )
if( requestTokenResponse.empty() )
{
size_t nPos = std::string::npos;
std::string strDummy;
return false;
}
/* Get oauth_token key */
nPos = requestTokenResponse.find( oAuthLibDefaults::OAUTHLIB_TOKEN_KEY );
size_t nPos = std::string::npos;
std::string strDummy;
/* Get oauth_token key */
nPos = requestTokenResponse.find( oAuthLibDefaults::OAUTHLIB_TOKEN_KEY );
if( std::string::npos != nPos )
{
nPos = nPos + oAuthLibDefaults::OAUTHLIB_TOKEN_KEY.length() + strlen( "=" );
strDummy = requestTokenResponse.substr( nPos );
nPos = strDummy.find( "&" );
if( std::string::npos != nPos )
{
nPos = nPos + oAuthLibDefaults::OAUTHLIB_TOKEN_KEY.length() + strlen( "=" );
strDummy = requestTokenResponse.substr( nPos );
nPos = strDummy.find( "&" );
if( std::string::npos != nPos )
{
m_oAuthTokenKey = strDummy.substr( 0, nPos );
}
}
/* Get oauth_token_secret */
nPos = requestTokenResponse.find( oAuthLibDefaults::OAUTHLIB_TOKENSECRET_KEY );
if( std::string::npos != nPos )
{
nPos = nPos + oAuthLibDefaults::OAUTHLIB_TOKENSECRET_KEY.length() + strlen( "=" );
strDummy = requestTokenResponse.substr( nPos );
nPos = strDummy.find( "&" );
if( std::string::npos != nPos )
{
m_oAuthTokenSecret = strDummy.substr( 0, nPos );
}
}
/* Get screen_name */
nPos = requestTokenResponse.find( oAuthLibDefaults::OAUTHLIB_SCREENNAME_KEY );
if( std::string::npos != nPos )
{
nPos = nPos + oAuthLibDefaults::OAUTHLIB_SCREENNAME_KEY.length() + strlen( "=" );
strDummy = requestTokenResponse.substr( nPos );
m_oAuthScreenName = strDummy;
m_oAuthTokenKey = strDummy.substr( 0, nPos );
}
}
/* Get oauth_token_secret */
nPos = requestTokenResponse.find( oAuthLibDefaults::OAUTHLIB_TOKENSECRET_KEY );
if( std::string::npos != nPos )
{
nPos = nPos + oAuthLibDefaults::OAUTHLIB_TOKENSECRET_KEY.length() + strlen( "=" );
strDummy = requestTokenResponse.substr( nPos );
nPos = strDummy.find( "&" );
if( std::string::npos != nPos )
{
m_oAuthTokenSecret = strDummy.substr( 0, nPos );
}
}
/* Get screen_name */
nPos = requestTokenResponse.find( oAuthLibDefaults::OAUTHLIB_SCREENNAME_KEY );
if( std::string::npos != nPos )
{
nPos = nPos + oAuthLibDefaults::OAUTHLIB_SCREENNAME_KEY.length() + strlen( "=" );
strDummy = requestTokenResponse.substr( nPos );
m_oAuthScreenName = strDummy;
}
return true;
}

View file

@ -10,42 +10,6 @@
#include <list>
#include <map>
namespace oAuthLibDefaults
{
/* Constants */
const int OAUTHLIB_BUFFSIZE = 1024;
const int OAUTHLIB_BUFFSIZE_LARGE = 1024;
const std::string OAUTHLIB_CONSUMERKEY_KEY = "oauth_consumer_key";
const std::string OAUTHLIB_CALLBACK_KEY = "oauth_callback";
const std::string OAUTHLIB_VERSION_KEY = "oauth_version";
const std::string OAUTHLIB_SIGNATUREMETHOD_KEY = "oauth_signature_method";
const std::string OAUTHLIB_SIGNATURE_KEY = "oauth_signature";
const std::string OAUTHLIB_TIMESTAMP_KEY = "oauth_timestamp";
const std::string OAUTHLIB_NONCE_KEY = "oauth_nonce";
const std::string OAUTHLIB_TOKEN_KEY = "oauth_token";
const std::string OAUTHLIB_TOKENSECRET_KEY = "oauth_token_secret";
const std::string OAUTHLIB_VERIFIER_KEY = "oauth_verifier";
const std::string OAUTHLIB_SCREENNAME_KEY = "screen_name";
const std::string OAUTHLIB_AUTHENTICITY_TOKEN_KEY = "authenticity_token";
const std::string OAUTHLIB_SESSIONUSERNAME_KEY = "session[username_or_email]";
const std::string OAUTHLIB_SESSIONPASSWORD_KEY = "session[password]";
const std::string OAUTHLIB_AUTHENTICITY_TOKEN_TWITTER_RESP_KEY = "authenticity_token\" type=\"hidden\" value=\"";
const std::string OAUTHLIB_TOKEN_TWITTER_RESP_KEY = "oauth_token\" type=\"hidden\" value=\"";
const std::string OAUTHLIB_PIN_TWITTER_RESP_KEY = "code-desc\"><code>";
const std::string OAUTHLIB_TOKEN_END_TAG_TWITTER_RESP = "\" />";
const std::string OAUTHLIB_PIN_END_TAG_TWITTER_RESP = "</code>";
const std::string OAUTHLIB_AUTHHEADER_STRING = "Authorization: OAuth ";
};
namespace oAuthTwitterApiUrls
{
/* Twitter OAuth API URLs */
const std::string OAUTHLIB_TWITTER_REQUEST_TOKEN_URL = "api.twitter.com/oauth/request_token";
const std::string OAUTHLIB_TWITTER_AUTHORIZE_URL = "api.twitter.com/oauth/authorize?oauth_token=";
const std::string OAUTHLIB_TWITTER_ACCESS_TOKEN_URL = "api.twitter.com/oauth/access_token";
};
typedef enum _eOAuthHttpRequestType
{
eOAuthHttpInvalid = 0,

View file

@ -1,17 +1,9 @@
#define NOMINMAX
#include <memory.h>
#include "twitcurlurls.h"
#include "twitcurl.h"
#include "urlencode.h"
static int myDebugCallback(CURL *,
curl_infotype type,
char *data,
size_t size,
void *handle)
{
std::cerr << std::string(data, size);
return 0;
};
/*++
* @method: twitCurl::twitCurl
*
@ -27,9 +19,12 @@ m_curlHandle( NULL ),
m_curlProxyParamsSet( false ),
m_curlLoginParamsSet( false ),
m_curlCallbackParamsSet( false ),
m_eApiFormatType( twitCurlTypes::eTwitCurlApiFormatXml ),
m_eApiFormatType( twitCurlTypes::eTwitCurlApiFormatJson ),
m_eProtocolType( twitCurlTypes::eTwitCurlProtocolHttps )
{
/* Alloc memory for cURL error responses */
m_errorBuffer = (char*)malloc( twitCurlDefaults::TWITCURL_DEFAULT_BUFFSIZE );
/* Clear callback buffers */
clearCurlCallbackBuffers();
@ -40,9 +35,7 @@ m_eProtocolType( twitCurlTypes::eTwitCurlProtocolHttps )
std::string dummyStr;
getLastCurlError( dummyStr );
}
curl_easy_setopt(m_curlHandle, CURLOPT_VERBOSE, 1);
curl_easy_setopt(m_curlHandle, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(m_curlHandle, CURLOPT_DEBUGFUNCTION, myDebugCallback);
curl_easy_setopt(m_curlHandle, CURLOPT_SSL_VERIFYPEER, 0);
}
/*++
@ -63,6 +56,11 @@ twitCurl::~twitCurl()
curl_easy_cleanup( m_curlHandle );
m_curlHandle = NULL;
}
if( m_errorBuffer )
{
free( m_errorBuffer );
m_errorBuffer = NULL;
}
}
/*++
@ -77,57 +75,22 @@ twitCurl::~twitCurl()
*--*/
twitCurl* twitCurl::clone()
{
twitCurl *cloneObj = new twitCurl();
twitCurl *cloneObj = new twitCurl();
/* cURL proxy data */
cloneObj->setProxyServerIp(m_proxyServerIp);
cloneObj->setProxyServerPort(m_proxyServerPort);
cloneObj->setProxyUserName(m_proxyUserName);
cloneObj->setProxyPassword(m_proxyPassword);
/* cURL proxy data */
cloneObj->setProxyServerIp(m_proxyServerIp);
cloneObj->setProxyServerPort(m_proxyServerPort);
cloneObj->setProxyUserName(m_proxyUserName);
cloneObj->setProxyPassword(m_proxyPassword);
/* Twitter data */
cloneObj->setTwitterUsername(m_twitterUsername);
cloneObj->setTwitterPassword(m_twitterPassword);
/* Twitter data */
cloneObj->setTwitterUsername(m_twitterUsername);
cloneObj->setTwitterPassword(m_twitterPassword);
/* Twitter API type */
cloneObj->setTwitterApiType(m_eApiFormatType);
/* OAuth data */
cloneObj->m_oAuth = m_oAuth.clone();
/* OAuth data */
cloneObj->m_oAuth = m_oAuth.clone();
return cloneObj;
}
/*++
* @method: twitCurl::setTwitterApiType
*
* @description: method to set API type
*
* @input: none
*
* @output: none
*
*--*/
void twitCurl::setTwitterApiType( twitCurlTypes::eTwitCurlApiFormatType eType )
{
m_eApiFormatType = ( eType < twitCurlTypes::eTwitCurlApiFormatMax ) ?
eType : twitCurlTypes::eTwitCurlApiFormatXml;
}
/*++
* @method: twitCurl::setTwitterProcotolType
*
* @description: method to set protocol
*
* @input: none
*
* @output: none
*
*--*/
void twitCurl::setTwitterProcotolType( twitCurlTypes::eTwitCurlProtocolType eType )
{
m_eProtocolType = ( eType < twitCurlTypes::eTwitCurlProtocolMax ) ?
eType : twitCurlTypes::eTwitCurlProtocolHttp;
return cloneObj;
}
/*++
@ -371,6 +334,7 @@ void twitCurl::setProxyPassword( std::string& proxyPassword )
* @description: method to return tweets that match a specified query.
*
* @input: searchQuery - search query in string format
* resultCount - optional search result count
*
* @output: true if GET is success, otherwise false. This does not check http
* response by twitter. Use getLastWebResponse() for that.
@ -378,15 +342,22 @@ void twitCurl::setProxyPassword( std::string& proxyPassword )
* @note: Only ATOM and JSON format supported.
*
*--*/
bool twitCurl::search( std::string& searchQuery )
bool twitCurl::search( std::string& searchQuery, std::string resultCount )
{
/* Prepare URL */
std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_SEARCH_URL +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[twitCurlTypes::eTwitCurlApiFormatJson] +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] +
twitCurlDefaults::TWITCURL_URL_SEP_QUES + twitCurlDefaults::TWITCURL_SEARCHQUERYSTRING +
searchQuery;
/* Add number of results count if provided */
if( resultCount.size() )
{
buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_AMP +
twitCurlDefaults::TWITCURL_COUNT + urlencode( resultCount );
}
/* Perform GET */
return performGet( buildUrl );
}
@ -396,27 +367,36 @@ bool twitCurl::search( std::string& searchQuery )
*
* @description: method to update new status message in twitter profile
*
* @input: newStatus
* @input: newStatus - status message text
* inReplyToStatusId - optional status id to we're replying to
*
* @output: true if POST is success, otherwise false. This does not check http
* response by twitter. Use getLastWebResponse() for that.
*
*--*/
bool twitCurl::statusUpdate( std::string& newStatus )
bool twitCurl::statusUpdate( std::string& newStatus, std::string inReplyToStatusId )
{
bool retVal = false;
if( newStatus.length() )
if( newStatus.empty() )
{
/* Prepare new status message */
std::string newStatusMsg = twitCurlDefaults::TWITCURL_STATUSSTRING + urlencode( newStatus );
/* Perform POST */
retVal = performPost( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_STATUSUPDATE_URL +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
newStatusMsg );
return false;
}
return retVal;
/* Prepare new status message */
std::string newStatusMsg = twitCurlDefaults::TWITCURL_STATUSSTRING + urlencode( newStatus );
/* Append status id to which we're replying to */
if( inReplyToStatusId.size() )
{
newStatusMsg += twitCurlDefaults::TWITCURL_URL_SEP_AMP +
twitCurlDefaults::TWITCURL_INREPLYTOSTATUSID +
urlencode( inReplyToStatusId );
}
/* Perform POST */
return performPost( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_STATUSUPDATE_URL +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
newStatusMsg );
}
/*++
@ -432,18 +412,18 @@ bool twitCurl::statusUpdate( std::string& newStatus )
*--*/
bool twitCurl::statusShowById( std::string& statusId )
{
bool retVal = false;
if( statusId.length() )
if( statusId.empty() )
{
/* Prepare URL */
std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_STATUSSHOW_URL + statusId +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
/* Perform GET */
retVal = performGet( buildUrl );
return false;
}
return retVal;
/* Prepare URL */
std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_STATUSSHOW_URL + statusId +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
/* Perform GET */
return performGet( buildUrl );
}
/*++
@ -459,18 +439,18 @@ bool twitCurl::statusShowById( std::string& statusId )
*--*/
bool twitCurl::statusDestroyById( std::string& statusId )
{
bool retVal = false;
if( statusId.length() )
if( statusId.empty() )
{
/* Prepare URL */
std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_STATUDESTROY_URL + statusId +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
/* Perform DELETE */
retVal = performDelete( buildUrl );
return false;
}
return retVal;
/* Prepare URL */
std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_STATUDESTROY_URL + statusId +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
/* Perform DELETE */
return performDelete( buildUrl );
}
/*++
@ -486,22 +466,22 @@ bool twitCurl::statusDestroyById( std::string& statusId )
*--*/
bool twitCurl::retweetById( std::string& statusId )
{
bool retVal = false;
if( statusId.length() )
{
/* Prepare URL */
std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_RETWEET_URL + statusId +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
if( statusId.empty() )
{
return false;
}
/* Send some dummy data in POST */
std::string dummyData = twitCurlDefaults::TWITCURL_TEXTSTRING +
urlencode( std::string( "dummy" ) );
/* Prepare URL */
std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_RETWEET_URL + statusId +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
/* Perform Retweet */
retVal = performPost( buildUrl, dummyData );
}
return retVal;
/* Send some dummy data in POST */
std::string dummyData = twitCurlDefaults::TWITCURL_TEXTSTRING +
urlencode( std::string( "dummy" ) );
/* Perform Retweet */
return performPost( buildUrl, dummyData );
}
/*++
@ -518,12 +498,13 @@ bool twitCurl::retweetById( std::string& statusId )
bool twitCurl::timelineHomeGet( std::string sinceId )
{
std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_HOME_TIMELINE_URL +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
twitterDefaults::TWITCURL_HOME_TIMELINE_URL +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
if( sinceId.length() )
{
buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES + twitCurlDefaults::TWITCURL_SINCEID + sinceId;
}
/* Perform GET */
return performGet( buildUrl );
}
@ -605,6 +586,7 @@ bool twitCurl::mentionsGet( std::string sinceId )
{
buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES + twitCurlDefaults::TWITCURL_SINCEID + sinceId;
}
/* Perform GET */
return performGet( buildUrl );
}
@ -623,7 +605,8 @@ bool twitCurl::mentionsGet( std::string sinceId )
* response by twitter. Use getLastWebResponse() for that.
*
*--*/
bool twitCurl::timelineUserGet( bool trimUser, bool includeRetweets, unsigned int tweetCount, std::string userInfo, bool isUserId )
bool twitCurl::timelineUserGet( bool trimUser, bool includeRetweets, unsigned int tweetCount,
std::string userInfo, bool isUserId )
{
/* Prepare URL */
std::string buildUrl;
@ -633,7 +616,7 @@ bool twitCurl::timelineUserGet( bool trimUser, bool includeRetweets, unsigned in
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
userInfo, isUserId );
if( !userInfo.length() )
if( userInfo.empty() )
{
buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES;
}
@ -678,26 +661,27 @@ bool twitCurl::timelineUserGet( bool trimUser, bool includeRetweets, unsigned in
*--*/
bool twitCurl::userLookup( std::vector<std::string> &userInfo, bool isUserId )
{
bool retVal = false;
if( userInfo.size() )
if( userInfo.empty() )
{
std::string userIds = "";
std::string sep = "";
for(int i=0 ; i<std::min(100U,(unsigned int) userInfo.size()) ; i++, sep = ",")
userIds += sep + userInfo[i];
userIds = (isUserId?twitCurlDefaults::TWITCURL_USERID : twitCurlDefaults::TWITCURL_SCREENNAME) + urlencode(userIds);
std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_LOOKUPUSERS_URL +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
/* Perform POST */
retVal = performPost( buildUrl, userIds);
return false;
}
return retVal;
std::string userIds = "";
std::string sep = "";
for( unsigned int i = 0 ; i < std::min((size_t)100, userInfo.size()); i++, sep = "," )
{
userIds += sep + userInfo[i];
}
userIds = ( isUserId ? twitCurlDefaults::TWITCURL_USERID : twitCurlDefaults::TWITCURL_SCREENNAME ) +
urlencode( userIds );
std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_LOOKUPUSERS_URL +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
/* Perform POST */
return performPost( buildUrl, userIds);
}
/*++
@ -714,20 +698,20 @@ bool twitCurl::userLookup( std::vector<std::string> &userInfo, bool isUserId )
*--*/
bool twitCurl::userGet( std::string& userInfo, bool isUserId )
{
bool retVal = false;
if( userInfo.length() )
if( userInfo.empty() )
{
/* Set URL */
std::string buildUrl;
utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_SHOWUSERS_URL +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
userInfo, isUserId );
/* Perform GET */
retVal = performGet( buildUrl );
return false;
}
return retVal;
/* Set URL */
std::string buildUrl;
utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_SHOWUSERS_URL +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
userInfo, isUserId );
/* Perform GET */
return performGet( buildUrl );
}
/*++
@ -793,14 +777,14 @@ bool twitCurl::followersGet( std::string userInfo, bool isUserId )
*--*/
bool twitCurl::directMessageGet( std::string sinceId )
{
std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_DIRECTMESSAGES_URL +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
if(sinceId.length())
{
buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES + twitCurlDefaults::TWITCURL_SINCEID + sinceId;
}
std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_DIRECTMESSAGES_URL +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
if( sinceId.length() )
{
buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES + twitCurlDefaults::TWITCURL_SINCEID + sinceId;
}
/* Perform GET */
return performGet( buildUrl );
@ -821,23 +805,23 @@ bool twitCurl::directMessageGet( std::string sinceId )
*--*/
bool twitCurl::directMessageSend( std::string& userInfo, std::string& dMsg, bool isUserId )
{
bool retVal = false;
if( userInfo.length() && dMsg.length() )
if( userInfo.empty() || dMsg.empty() )
{
/* Prepare new direct message */
std::string newDm = twitCurlDefaults::TWITCURL_TEXTSTRING + urlencode( dMsg );
/* Prepare URL */
std::string buildUrl;
utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_DIRECTMESSAGENEW_URL +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
userInfo, isUserId );
/* Perform POST */
retVal = performPost( buildUrl, newDm );
return false;
}
return retVal;
/* Prepare new direct message */
std::string newDm = twitCurlDefaults::TWITCURL_TEXTSTRING + urlencode( dMsg );
/* Prepare URL */
std::string buildUrl;
utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_DIRECTMESSAGENEW_URL +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
userInfo, isUserId );
/* Perform POST */
return performPost( buildUrl, newDm );
}
/*++
@ -872,18 +856,18 @@ bool twitCurl::directMessageGetSent()
*--*/
bool twitCurl::directMessageDestroyById( std::string& dMsgId )
{
bool retVal = false;
if( dMsgId.length() )
if( dMsgId.empty() )
{
/* Prepare URL */
std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_DIRECTMESSAGEDESTROY_URL + dMsgId +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
/* Perform DELETE */
retVal = performDelete( buildUrl );
return false;
}
return retVal;
/* Prepare URL */
std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_DIRECTMESSAGEDESTROY_URL + dMsgId +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
/* Perform DELETE */
return performDelete( buildUrl );
}
/*++
@ -900,24 +884,24 @@ bool twitCurl::directMessageDestroyById( std::string& dMsgId )
*--*/
bool twitCurl::friendshipCreate( std::string& userInfo, bool isUserId )
{
bool retVal = false;
if( userInfo.length() )
if( userInfo.empty() )
{
/* Prepare URL */
std::string buildUrl;
utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_FRIENDSHIPSCREATE_URL +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
userInfo, isUserId );
/* Send some dummy data in POST */
std::string dummyData = twitCurlDefaults::TWITCURL_TEXTSTRING +
urlencode( std::string( "dummy" ) );
/* Perform POST */
retVal = performPost( buildUrl, dummyData );
return false;
}
return retVal;
/* Prepare URL */
std::string buildUrl;
utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_FRIENDSHIPSCREATE_URL +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
userInfo, isUserId );
/* Send some dummy data in POST */
std::string dummyData = twitCurlDefaults::TWITCURL_TEXTSTRING +
urlencode( std::string( "dummy" ) );
/* Perform POST */
return performPost( buildUrl, dummyData );
}
/*++
@ -934,20 +918,20 @@ bool twitCurl::friendshipCreate( std::string& userInfo, bool isUserId )
*--*/
bool twitCurl::friendshipDestroy( std::string& userInfo, bool isUserId )
{
bool retVal = false;
if( userInfo.length() )
if( userInfo.empty() )
{
/* Prepare URL */
std::string buildUrl;
utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_FRIENDSHIPSDESTROY_URL +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
userInfo, isUserId );
/* Perform DELETE */
retVal = performDelete( buildUrl );
return false;
}
return retVal;
/* Prepare URL */
std::string buildUrl;
utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_FRIENDSHIPSDESTROY_URL +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
userInfo, isUserId );
/* Perform DELETE */
return performDelete( buildUrl );
}
/*++
@ -994,12 +978,14 @@ bool twitCurl::friendshipShow( std::string& userInfo, bool isUserId )
*
* @input: userInfo - user id or screen name of a user
* isUserId - true if userInfo contains a user id instead of screen name
* nextCursor - next cursor string returned from a previous call
* to this API, otherwise an empty string
*
* @output: true if GET is success, otherwise false. This does not check http
* response by twitter. Use getLastWebResponse() for that.
*
*--*/
bool twitCurl::friendsIdsGet( std::string& userInfo, bool isUserId )
bool twitCurl::friendsIdsGet( std::string& nextCursor, std::string& userInfo, bool isUserId )
{
/* Prepare URL */
std::string buildUrl;
@ -1008,6 +994,13 @@ bool twitCurl::friendsIdsGet( std::string& userInfo, bool isUserId )
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
userInfo, isUserId );
if( buildUrl.length() && nextCursor.length() )
{
buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_AMP +
twitCurlDefaults::TWITCURL_NEXT_CURSOR +
nextCursor;
}
/* Perform GET */
return performGet( buildUrl );
}
@ -1019,12 +1012,14 @@ bool twitCurl::friendsIdsGet( std::string& userInfo, bool isUserId )
*
* @input: userInfo - user id or screen name of a user
* isUserId - true if userInfo contains a user id instead of screen name
* nextCursor - next cursor string returned from a previous call
* to this API, otherwise an empty string
*
* @output: true if GET is success, otherwise false. This does not check http
* response by twitter. Use getLastWebResponse() for that.
*
*--*/
bool twitCurl::followersIdsGet( std::string& userInfo, bool isUserId )
bool twitCurl::followersIdsGet( std::string& nextCursor, std::string& userInfo, bool isUserId )
{
/* Prepare URL */
std::string buildUrl;
@ -1033,6 +1028,13 @@ bool twitCurl::followersIdsGet( std::string& userInfo, bool isUserId )
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
userInfo, isUserId );
if( buildUrl.length() && nextCursor.length() )
{
buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_AMP +
twitCurlDefaults::TWITCURL_NEXT_CURSOR +
nextCursor;
}
/* Perform GET */
return performGet( buildUrl );
}
@ -1147,7 +1149,7 @@ bool twitCurl::favoriteDestroy( std::string& statusId )
*
* @description: method to block a user
*
* @input: userInfo - user id or screen name
* @input: userInfo - user id or screen name who needs to be blocked
*
* @output: true if POST is success, otherwise false. This does not check http
* response by twitter. Use getLastWebResponse() for that.
@ -1173,7 +1175,7 @@ bool twitCurl::blockCreate( std::string& userInfo )
*
* @description: method to unblock a user
*
* @input: userInfo - user id or screen name
* @input: userInfo - user id or screen name who need to unblocked
*
* @output: true if DELETE is success, otherwise false. This does not check http
* response by twitter. Use getLastWebResponse() for that.
@ -1190,6 +1192,100 @@ bool twitCurl::blockDestroy( std::string& userInfo )
return performDelete( buildUrl );
}
/*++
* @method: twitCurl::blockListGet
*
* @description: method to get list of users blocked by authenticated user
*
* @input: includeEntities - indicates whether or not to include 'entities' node
* skipStatus - indicates whether or not to include status for returned users
* nextCursor - next cursor string returned from a previous call
* to this API, otherwise an empty string
*
* @output: true if GET is success, otherwise false. This does not check http
* response by twitter. Use getLastWebResponse() for that.
*
*--*/
bool twitCurl::blockListGet( std::string& nextCursor, bool includeEntities, bool skipStatus )
{
/* Prepare URL */
std::string buildUrl, urlParams;
buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_BLOCKSLIST_URL +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
if( includeEntities )
{
urlParams += twitCurlDefaults::TWITCURL_INCLUDE_ENTITIES + std::string("true");
}
if( skipStatus )
{
if( urlParams.length() )
{
urlParams += twitCurlDefaults::TWITCURL_URL_SEP_AMP;
}
urlParams += twitCurlDefaults::TWITCURL_SKIP_STATUS + std::string("true");
}
if( nextCursor.length() )
{
if( urlParams.length() )
{
urlParams += twitCurlDefaults::TWITCURL_URL_SEP_AMP;
}
urlParams += twitCurlDefaults::TWITCURL_NEXT_CURSOR + nextCursor;
}
if( urlParams.length() )
{
buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES + urlParams;
}
/* Perform GET */
return performGet( buildUrl );
}
/*++
* @method: twitCurl::blockIdsGet
*
* @description: method to get list of IDs blocked by authenticated user
*
* @input: stringifyIds - indicates whether or not returned ids should
* be in string format
* nextCursor - next cursor string returned from a previous call
* to this API, otherwise an empty string
*
* @output: true if GET is success, otherwise false. This does not check http
* response by twitter. Use getLastWebResponse() for that.
*
*--*/
bool twitCurl::blockIdsGet( std::string& nextCursor, bool stringifyIds )
{
/* Prepare URL */
std::string buildUrl, urlParams;
buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
twitterDefaults::TWITCURL_BLOCKSIDS_URL +
twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
if( stringifyIds )
{
urlParams += twitCurlDefaults::TWITCURL_STRINGIFY_IDS + std::string("true");
}
if( nextCursor.length() )
{
if( urlParams.length() )
{
urlParams += twitCurlDefaults::TWITCURL_URL_SEP_AMP;
}
urlParams += twitCurlDefaults::TWITCURL_NEXT_CURSOR + nextCursor;
}
if( urlParams.length() )
{
buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES + urlParams;
}
/* Perform GET */
return performGet( buildUrl );
}
/*++
* @method: twitCurl::savedSearchGet
*
@ -1433,13 +1529,12 @@ void twitCurl::getLastCurlError( std::string& outErrResp )
*--*/
int twitCurl::curlCallback( char* data, size_t size, size_t nmemb, twitCurl* pTwitCurlObj )
{
int writtenSize = 0;
if( ( NULL != pTwitCurlObj ) && ( NULL != data ) )
if( pTwitCurlObj && data )
{
/* Save http response in twitcurl object's buffer */
writtenSize = pTwitCurlObj->saveLastWebResponse( data, ( size*nmemb ) );
return pTwitCurlObj->saveLastWebResponse( data, ( size*nmemb ) );
}
return writtenSize;
return 0;
}
/*++
@ -1458,14 +1553,13 @@ int twitCurl::curlCallback( char* data, size_t size, size_t nmemb, twitCurl* pTw
*--*/
int twitCurl::saveLastWebResponse( char*& data, size_t size )
{
int bytesWritten = 0;
if( data && size )
{
/* Append data in our internal buffer */
m_callbackData.append( data, size );
bytesWritten = (int)size;
return (int)size;
}
return bytesWritten;
return 0;
}
/*++
@ -1503,32 +1597,34 @@ void twitCurl::clearCurlCallbackBuffers()
*--*/
void twitCurl::prepareCurlProxy()
{
if( !m_curlProxyParamsSet )
if( m_curlProxyParamsSet )
{
/* Reset existing proxy details in cURL */
curl_easy_setopt( m_curlHandle, CURLOPT_PROXY, NULL );
curl_easy_setopt( m_curlHandle, CURLOPT_PROXYUSERPWD, NULL );
curl_easy_setopt( m_curlHandle, CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY );
/* Set proxy details in cURL */
std::string proxyIpPort("");
if( getProxyServerIp().size() )
{
utilMakeCurlParams( proxyIpPort, getProxyServerIp(), getProxyServerPort() );
}
curl_easy_setopt( m_curlHandle, CURLOPT_PROXY, proxyIpPort.c_str() );
/* Prepare username and password for proxy server */
if( m_proxyUserName.length() && m_proxyPassword.length() )
{
std::string proxyUserPass;
utilMakeCurlParams( proxyUserPass, getProxyUserName(), getProxyPassword() );
curl_easy_setopt( m_curlHandle, CURLOPT_PROXYUSERPWD, proxyUserPass.c_str() );
}
/* Set the flag to true indicating that proxy info is set in cURL */
m_curlProxyParamsSet = true;
return;
}
/* Reset existing proxy details in cURL */
curl_easy_setopt( m_curlHandle, CURLOPT_PROXY, NULL );
curl_easy_setopt( m_curlHandle, CURLOPT_PROXYUSERPWD, NULL );
curl_easy_setopt( m_curlHandle, CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY );
/* Set proxy details in cURL */
std::string proxyIpPort("");
if( getProxyServerIp().size() )
{
utilMakeCurlParams( proxyIpPort, getProxyServerIp(), getProxyServerPort() );
}
curl_easy_setopt( m_curlHandle, CURLOPT_PROXY, proxyIpPort.c_str() );
/* Prepare username and password for proxy server */
if( m_proxyUserName.length() && m_proxyPassword.length() )
{
std::string proxyUserPass;
utilMakeCurlParams( proxyUserPass, getProxyUserName(), getProxyPassword() );
curl_easy_setopt( m_curlHandle, CURLOPT_PROXYUSERPWD, proxyUserPass.c_str() );
}
/* Set the flag to true indicating that proxy info is set in cURL */
m_curlProxyParamsSet = true;
}
/*++
@ -1546,18 +1642,20 @@ void twitCurl::prepareCurlProxy()
*--*/
void twitCurl::prepareCurlCallback()
{
if( !m_curlCallbackParamsSet )
if( m_curlCallbackParamsSet )
{
/* Set buffer to get error */
curl_easy_setopt( m_curlHandle, CURLOPT_ERRORBUFFER, m_errorBuffer );
/* Set callback function to get response */
curl_easy_setopt( m_curlHandle, CURLOPT_WRITEFUNCTION, curlCallback );
curl_easy_setopt( m_curlHandle, CURLOPT_WRITEDATA, this );
/* Set the flag to true indicating that callback info is set in cURL */
m_curlCallbackParamsSet = true;
return;
}
/* Set buffer to get error */
curl_easy_setopt( m_curlHandle, CURLOPT_ERRORBUFFER, m_errorBuffer );
/* Set callback function to get response */
curl_easy_setopt( m_curlHandle, CURLOPT_WRITEFUNCTION, curlCallback );
curl_easy_setopt( m_curlHandle, CURLOPT_WRITEDATA, this );
/* Set the flag to true indicating that callback info is set in cURL */
m_curlCallbackParamsSet = true;
}
/*++
@ -1576,24 +1674,26 @@ void twitCurl::prepareCurlCallback()
*--*/
void twitCurl::prepareCurlUserPass()
{
if( !m_curlLoginParamsSet )
if( m_curlLoginParamsSet )
{
/* Reset existing username and password stored in cURL */
curl_easy_setopt( m_curlHandle, CURLOPT_USERPWD, "" );
if( getTwitterUsername().size() )
{
/* Prepare username:password */
std::string userNamePassword;
utilMakeCurlParams( userNamePassword, getTwitterUsername(), getTwitterPassword() );
/* Set username and password */
curl_easy_setopt( m_curlHandle, CURLOPT_USERPWD, userNamePassword.c_str() );
}
/* Set the flag to true indicating that twitter credentials are set in cURL */
m_curlLoginParamsSet = true;
return;
}
/* Reset existing username and password stored in cURL */
curl_easy_setopt( m_curlHandle, CURLOPT_USERPWD, "" );
if( getTwitterUsername().size() )
{
/* Prepare username:password */
std::string userNamePassword;
utilMakeCurlParams( userNamePassword, getTwitterUsername(), getTwitterPassword() );
/* Set username and password */
curl_easy_setopt( m_curlHandle, CURLOPT_USERPWD, userNamePassword.c_str() );
}
/* Set the flag to true indicating that twitter credentials are set in cURL */
m_curlLoginParamsSet = true;
}
/*++
@ -1614,8 +1714,8 @@ void twitCurl::prepareStandardParams()
/* Restore any custom request we may have */
curl_easy_setopt( m_curlHandle, CURLOPT_CUSTOMREQUEST, NULL );
/* All supported encodings */
curl_easy_setopt( m_curlHandle, CURLOPT_ENCODING, "" );
/* All supported encodings */
curl_easy_setopt( m_curlHandle, CURLOPT_ENCODING, "" );
/* Clear callback and error buffers */
clearCurlCallbackBuffers();
@ -1690,7 +1790,7 @@ bool twitCurl::performGet( const std::string& getUrl )
}
/*++
* @method: twitCurl::performGet
* @method: twitCurl::performGetInternal
*
* @description: method to send http GET request. this is an internal method.
* twitcurl users should not use this method.
@ -1702,7 +1802,8 @@ bool twitCurl::performGet( const std::string& getUrl )
* @remarks: internal method
*
*--*/
bool twitCurl::performGet( const std::string& getUrl, const std::string& oAuthHttpHeader )
bool twitCurl::performGetInternal( const std::string& getUrl,
const std::string& oAuthHttpHeader )
{
/* Return if cURL is not initialized */
if( !isCurlInit() )
@ -1963,7 +2064,6 @@ bool twitCurl::oAuthRequestToken( std::string& authorizeUrl /* out */ )
}
/* Get OAuth header for request token */
bool retVal = false;
std::string oAuthHeader;
authorizeUrl = "";
if( m_oAuth.getOAuthHeader( eOAuthHttpGet,
@ -1972,8 +2072,9 @@ bool twitCurl::oAuthRequestToken( std::string& authorizeUrl /* out */ )
std::string( "" ),
oAuthHeader ) )
{
if( performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
oAuthTwitterApiUrls::OAUTHLIB_TWITTER_REQUEST_TOKEN_URL, oAuthHeader ) )
if( performGetInternal( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
oAuthTwitterApiUrls::OAUTHLIB_TWITTER_REQUEST_TOKEN_URL,
oAuthHeader ) )
{
/* Tell OAuth object to save access token and secret from web response */
std::string twitterResp;
@ -1989,10 +2090,10 @@ bool twitCurl::oAuthRequestToken( std::string& authorizeUrl /* out */ )
oAuthTwitterApiUrls::OAUTHLIB_TWITTER_AUTHORIZE_URL );
authorizeUrl.append( oAuthTokenKey.c_str() );
retVal = true;
return true;
}
}
return retVal;
return false;
}
/*++
@ -2013,7 +2114,6 @@ bool twitCurl::oAuthAccessToken()
return false;
}
/* Get OAuth header for access token */
bool retVal = false;
std::string oAuthHeader;
if( m_oAuth.getOAuthHeader( eOAuthHttpGet,
twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
@ -2021,18 +2121,19 @@ bool twitCurl::oAuthAccessToken()
std::string( "" ),
oAuthHeader, true ) )
{
if( performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
oAuthTwitterApiUrls::OAUTHLIB_TWITTER_ACCESS_TOKEN_URL, oAuthHeader ) )
if( performGetInternal( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
oAuthTwitterApiUrls::OAUTHLIB_TWITTER_ACCESS_TOKEN_URL,
oAuthHeader ) )
{
/* Tell OAuth object to save access token and secret from web response */
std::string twitterResp;
getLastWebResponse( twitterResp );
m_oAuth.extractOAuthTokenKeySecret( twitterResp );
retVal = true;
return true;
}
}
return retVal;
return false;
}
/*++
@ -2187,3 +2288,4 @@ bool twitCurl::oAuthHandlePIN( const std::string& authorizeUrl /* in */ )
}
return false;
}

View file

@ -1,8 +1,6 @@
#ifndef _TWITCURL_H_
#define _TWITCURL_H_
#ifdef _WIN32
#define NOMINMAX 1
#endif
#include <string>
#include <sstream>
#include <cstring>
@ -10,127 +8,24 @@
#include "oauthlib.h"
#include "curl/curl.h"
/* Few common types used by twitCurl */
namespace twitCurlTypes
{
typedef enum _eTwitCurlApiFormatType
{
eTwitCurlApiFormatXml = 0,
eTwitCurlApiFormatJson,
eTwitCurlApiFormatJson = 0,
eTwitCurlApiFormatXml,
eTwitCurlApiFormatMax
} eTwitCurlApiFormatType;
typedef enum _eTwitCurlProtocolType
{
eTwitCurlProtocolHttp = 0,
eTwitCurlProtocolHttps,
eTwitCurlProtocolHttps = 0,
eTwitCurlProtocolHttp,
eTwitCurlProtocolMax
} eTwitCurlProtocolType;
};
/* Default values used in twitcurl */
namespace twitCurlDefaults
{
/* Constants */
const int TWITCURL_DEFAULT_BUFFSIZE = 1024;
const std::string TWITCURL_COLON = ":";
const char TWITCURL_EOS = '\0';
const unsigned int MAX_TIMELINE_TWEET_COUNT = 200;
/* Miscellaneous data used to build twitter URLs*/
const std::string TWITCURL_STATUSSTRING = "status=";
const std::string TWITCURL_TEXTSTRING = "text=";
const std::string TWITCURL_QUERYSTRING = "query=";
const std::string TWITCURL_SEARCHQUERYSTRING = "q=";
const std::string TWITCURL_SCREENNAME = "screen_name=";
const std::string TWITCURL_USERID = "user_id=";
const std::string TWITCURL_EXTENSIONFORMATS[2] = { ".xml",
".json"
};
const std::string TWITCURL_PROTOCOLS[2] = { "http://",
"https://"
};
const std::string TWITCURL_TARGETSCREENNAME = "target_screen_name=";
const std::string TWITCURL_TARGETUSERID = "target_id=";
const std::string TWITCURL_SINCEID = "since_id=";
const std::string TWITCURL_TRIMUSER = "trim_user=true";
const std::string TWITCURL_INCRETWEETS = "include_rts=true";
const std::string TWITCURL_COUNT = "count=";
/* URL separators */
const std::string TWITCURL_URL_SEP_AMP = "&";
const std::string TWITCURL_URL_SEP_QUES = "?";
};
/* Default twitter URLs */
namespace twitterDefaults
{
/* Search URLs */
const std::string TWITCURL_SEARCH_URL = "search.twitter.com/search";
/* Status URLs */
const std::string TWITCURL_STATUSUPDATE_URL = "api.twitter.com/1.1/statuses/update";
const std::string TWITCURL_STATUSSHOW_URL = "api.twitter.com/1.1/statuses/show/";
const std::string TWITCURL_STATUDESTROY_URL = "api.twitter.com/1.1/statuses/destroy/";
const std::string TWITCURL_RETWEET_URL = "api.twitter.com/1.1/statuses/retweet/";
/* Timeline URLs */
const std::string TWITCURL_HOME_TIMELINE_URL = "api.twitter.com/1.1/statuses/home_timeline";
const std::string TWITCURL_PUBLIC_TIMELINE_URL = "api.twitter.com/1.1/statuses/public_timeline";
const std::string TWITCURL_FEATURED_USERS_URL = "api.twitter.com/1.1/statuses/featured";
const std::string TWITCURL_FRIENDS_TIMELINE_URL = "api.twitter.com/1.1/statuses/friends_timeline";
const std::string TWITCURL_MENTIONS_URL = "api.twitter.com/1.1/statuses/mentions";
const std::string TWITCURL_USERTIMELINE_URL = "api.twitter.com/1.1/statuses/user_timeline";
/* Users URLs */
const std::string TWITCURL_LOOKUPUSERS_URL = "api.twitter.com/1.1/users/lookup";
const std::string TWITCURL_SHOWUSERS_URL = "api.twitter.com/1.1/users/show";
const std::string TWITCURL_SHOWFRIENDS_URL = "api.twitter.com/1.1/statuses/friends";
const std::string TWITCURL_SHOWFOLLOWERS_URL = "api.twitter.com/1.1/statuses/followers";
/* Direct messages URLs */
const std::string TWITCURL_DIRECTMESSAGES_URL = "api.twitter.com/1.1/direct_messages";
const std::string TWITCURL_DIRECTMESSAGENEW_URL = "api.twitter.com/1.1/direct_messages/new";
const std::string TWITCURL_DIRECTMESSAGESSENT_URL = "api.twitter.com/1.1/direct_messages/sent";
const std::string TWITCURL_DIRECTMESSAGEDESTROY_URL = "api.twitter.com/1.1/direct_messages/destroy/";
/* Friendships URLs */
const std::string TWITCURL_FRIENDSHIPSCREATE_URL = "api.twitter.com/1.1/friendships/create";
const std::string TWITCURL_FRIENDSHIPSDESTROY_URL = "api.twitter.com/1.1/friendships/destroy";
const std::string TWITCURL_FRIENDSHIPSSHOW_URL = "api.twitter.com/1.1/friendships/show";
/* Social graphs URLs */
const std::string TWITCURL_FRIENDSIDS_URL = "api.twitter.com/1.1/friends/ids";
const std::string TWITCURL_FOLLOWERSIDS_URL = "api.twitter.com/1.1/followers/ids";
/* Account URLs */
const std::string TWITCURL_ACCOUNTRATELIMIT_URL = "api.twitter.com/1.1/account/rate_limit_status";
const std::string TWITCURL_ACCOUNTVERIFYCRED_URL = "api.twitter.com/1.1/account/verify_credentials";
/* Favorites URLs */
const std::string TWITCURL_FAVORITESGET_URL = "api.twitter.com/1.1/favorites";
const std::string TWITCURL_FAVORITECREATE_URL = "api.twitter.com/1.1/favorites/create/";
const std::string TWITCURL_FAVORITEDESTROY_URL = "api.twitter.com/1.1/favorites/destroy/";
/* Block URLs */
const std::string TWITCURL_BLOCKSCREATE_URL = "api.twitter.com/1.1/blocks/create/";
const std::string TWITCURL_BLOCKSDESTROY_URL = "api.twitter.com/1.1/blocks/destroy/";
/* Saved Search URLs */
const std::string TWITCURL_SAVEDSEARCHGET_URL = "api.twitter.com/1.1/saved_searches";
const std::string TWITCURL_SAVEDSEARCHSHOW_URL = "api.twitter.com/1.1/saved_searches/show/";
const std::string TWITCURL_SAVEDSEARCHCREATE_URL = "api.twitter.com/1.1/saved_searches/create";
const std::string TWITCURL_SAVEDSEARCHDESTROY_URL = "api.twitter.com/1.1/saved_searches/destroy/";
/* Trends URLs */
const std::string TWITCURL_TRENDS_URL = "api.twitter.com/1.1/trends";
const std::string TWITCURL_TRENDSDAILY_URL = "api.twitter.com/1.1/trends/daily";
const std::string TWITCURL_TRENDSCURRENT_URL = "api.twitter.com/1.1/trends/current";
const std::string TWITCURL_TRENDSWEEKLY_URL = "api.twitter.com/1.1/trends/weekly";
const std::string TWITCURL_TRENDSAVAILABLE_URL = "api.twitter.com/1.1/trends/available";
};
/* twitCurl class */
class twitCurl
{
@ -150,15 +45,11 @@ public:
void setTwitterUsername( std::string& userName /* in */ );
void setTwitterPassword( std::string& passWord /* in */ );
/* Twitter API type */
void setTwitterApiType( twitCurlTypes::eTwitCurlApiFormatType eType );
void setTwitterProcotolType( twitCurlTypes::eTwitCurlProtocolType eType );
/* Twitter search APIs */
bool search( std::string& searchQuery /* in */ );
bool search( std::string& searchQuery /* in */, std::string resultCount = "" /* in */ );
/* Twitter status APIs */
bool statusUpdate( std::string& newStatus /* in */ );
bool statusUpdate( std::string& newStatus /* in */, std::string inReplyToStatusId = "" /* in */ );
bool statusShowById( std::string& statusId /* in */ );
bool statusDestroyById( std::string& statusId /* in */ );
bool retweetById( std::string& statusId /* in */ );
@ -167,18 +58,21 @@ public:
bool timelineHomeGet( std::string sinceId = "" /* in */ );
bool timelinePublicGet();
bool timelineFriendsGet();
bool timelineUserGet( bool trimUser /* in */, bool includeRetweets /* in */, unsigned int tweetCount /* in */, std::string userInfo = "" /* in */, bool isUserId = false /* in */ );
bool timelineUserGet( bool trimUser /* in */, bool includeRetweets /* in */,
unsigned int tweetCount /* in */,
std::string userInfo = "" /* in */,
bool isUserId = false /* in */ );
bool featuredUsersGet();
bool mentionsGet( std::string sinceId = "" /* in */ );
/* Twitter user APIs */
bool userLookup( std::vector<std::string> &userInfo /* in */, bool isUserId = false /* in */ );
bool userLookup( std::vector<std::string> &userInfo /* in */, bool isUserId = false /* in */ );
bool userGet( std::string& userInfo /* in */, bool isUserId = false /* in */ );
bool friendsGet( std::string userInfo = "" /* in */, bool isUserId = false /* in */ );
bool followersGet( std::string userInfo = "" /* in */, bool isUserId = false /* in */ );
/* Twitter direct message APIs */
bool directMessageGet( std::string sinceId /* in */ );
bool directMessageGet( std::string sinceId = "" /* in */ );
bool directMessageSend( std::string& userInfo /* in */, std::string& dMsg /* in */, bool isUserId = false /* in */ );
bool directMessageGetSent();
bool directMessageDestroyById( std::string& dMsgId /* in */ );
@ -189,12 +83,15 @@ public:
bool friendshipShow( std::string& userInfo /* in */, bool isUserId = false /* in */ );
/* Twitter social graphs APIs */
bool friendsIdsGet( std::string& userInfo /* in */, bool isUserId = false /* in */ );
bool followersIdsGet( std::string& userInfo /* in */, bool isUserId = false /* in */ );
bool friendsIdsGet( std::string& nextCursor /* in */,
std::string& userInfo /* in */, bool isUserId = false /* in */ );
bool followersIdsGet( std::string& nextCursor /* in */,
std::string& userInfo /* in */, bool isUserId = false /* in */ );
/* Twitter account APIs */
bool accountRateLimitGet();
bool accountVerifyCredGet();
/* Twitter favorites APIs */
bool favoriteGet();
bool favoriteCreate( std::string& statusId /* in */ );
@ -203,6 +100,9 @@ public:
/* Twitter block APIs */
bool blockCreate( std::string& userInfo /* in */ );
bool blockDestroy( std::string& userInfo /* in */ );
bool blockListGet( std::string& nextCursor /* in */,
bool includeEntities /* in */, bool skipStatus /* in */ );
bool blockIdsGet( std::string& nextCursor /* in */, bool stringifyIds /* in */ );
/* Twitter search APIs */
bool savedSearchGet();
@ -234,13 +134,14 @@ public:
void setProxyServerPort( std::string& proxyServerPort /* in */ );
void setProxyUserName( std::string& proxyUserName /* in */ );
void setProxyPassword( std::string& proxyPassword /* in */ );
twitCurl* clone();
/* Clones this object */
twitCurl* clone();
private:
/* cURL data */
CURL* m_curlHandle;
char m_errorBuffer[twitCurlDefaults::TWITCURL_DEFAULT_BUFFSIZE];
char* m_errorBuffer;
std::string m_callbackData;
/* cURL flags */
@ -272,7 +173,8 @@ private:
void prepareCurlUserPass();
void prepareStandardParams();
bool performGet( const std::string& getUrl );
bool performGet( const std::string& getUrl, const std::string& oAuthHttpHeader );
bool performGetInternal( const std::string& getUrl,
const std::string& oAuthHttpHeader );
bool performDelete( const std::string& deleteUrl );
bool performPost( const std::string& postUrl, std::string dataStr = "" );

View file

@ -118,7 +118,7 @@
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="./curl"
AdditionalIncludeDirectories="./include"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;CURL_STATICLIB"
StringPooling="true"
RuntimeLibrary="2"
@ -144,7 +144,7 @@
<Tool
Name="VCLibrarianTool"
LinkLibraryDependencies="true"
AdditionalDependencies="libcurl.lib ws2_32.lib wldap32.lib"
AdditionalDependencies="libcurl.lib"
OutputFile=".\Release\twitcurl.lib"
AdditionalLibraryDirectories="./lib"
SuppressStartupBanner="true"
@ -332,6 +332,10 @@
RelativePath="twitcurl.h"
>
</File>
<File
RelativePath=".\twitcurlurls.h"
>
</File>
<File
RelativePath="urlencode.h"
>

View file

@ -0,0 +1,156 @@
#ifndef _TWITCURLURLS_H_
#define _TWITCURLURLS_H_
#include <string>
#include <cstring>
/* Default values used in twitcurl */
namespace twitCurlDefaults
{
/* Constants */
const int TWITCURL_DEFAULT_BUFFSIZE = 1024;
const std::string TWITCURL_COLON = ":";
const char TWITCURL_EOS = '\0';
const unsigned int MAX_TIMELINE_TWEET_COUNT = 200;
/* Miscellaneous data used to build twitter URLs*/
const std::string TWITCURL_STATUSSTRING = "status=";
const std::string TWITCURL_TEXTSTRING = "text=";
const std::string TWITCURL_QUERYSTRING = "query=";
const std::string TWITCURL_SEARCHQUERYSTRING = "q=";
const std::string TWITCURL_SCREENNAME = "screen_name=";
const std::string TWITCURL_USERID = "user_id=";
const std::string TWITCURL_EXTENSIONFORMATS[2] = { ".json",
".xml"
};
const std::string TWITCURL_PROTOCOLS[2] = { "https://",
"http://"
};
const std::string TWITCURL_TARGETSCREENNAME = "target_screen_name=";
const std::string TWITCURL_TARGETUSERID = "target_id=";
const std::string TWITCURL_SINCEID = "since_id=";
const std::string TWITCURL_TRIMUSER = "trim_user=true";
const std::string TWITCURL_INCRETWEETS = "include_rts=true";
const std::string TWITCURL_COUNT = "count=";
const std::string TWITCURL_NEXT_CURSOR = "cursor=";
const std::string TWITCURL_SKIP_STATUS = "skip_status=";
const std::string TWITCURL_INCLUDE_ENTITIES = "include_entities=";
const std::string TWITCURL_STRINGIFY_IDS = "stringify_ids=";
const std::string TWITCURL_INREPLYTOSTATUSID = "in_reply_to_status_id=";
/* URL separators */
const std::string TWITCURL_URL_SEP_AMP = "&";
const std::string TWITCURL_URL_SEP_QUES = "?";
};
/* Default twitter URLs */
namespace twitterDefaults
{
/* Base URL */
const std::string TWITCURL_BASE_URL = "api.twitter.com/1.1/";
/* Search URLs */
const std::string TWITCURL_SEARCH_URL = TWITCURL_BASE_URL + "search/tweets";
/* Status URLs */
const std::string TWITCURL_STATUSUPDATE_URL = TWITCURL_BASE_URL + "statuses/update";
const std::string TWITCURL_STATUSSHOW_URL = TWITCURL_BASE_URL + "statuses/show/";
const std::string TWITCURL_STATUDESTROY_URL = TWITCURL_BASE_URL + "statuses/destroy/";
const std::string TWITCURL_RETWEET_URL = TWITCURL_BASE_URL + "statuses/retweet/";
/* Timeline URLs */
const std::string TWITCURL_HOME_TIMELINE_URL = TWITCURL_BASE_URL + "statuses/home_timeline";
const std::string TWITCURL_PUBLIC_TIMELINE_URL = TWITCURL_BASE_URL + "statuses/public_timeline";
const std::string TWITCURL_FEATURED_USERS_URL = TWITCURL_BASE_URL + "statuses/featured";
const std::string TWITCURL_FRIENDS_TIMELINE_URL = TWITCURL_BASE_URL + "statuses/friends_timeline";
const std::string TWITCURL_MENTIONS_URL = TWITCURL_BASE_URL + "statuses/mentions";
const std::string TWITCURL_USERTIMELINE_URL = TWITCURL_BASE_URL + "statuses/user_timeline";
/* Users URLs */
const std::string TWITCURL_LOOKUPUSERS_URL = TWITCURL_BASE_URL + "users/lookup";
const std::string TWITCURL_SHOWUSERS_URL = TWITCURL_BASE_URL + "users/show";
const std::string TWITCURL_SHOWFRIENDS_URL = TWITCURL_BASE_URL + "statuses/friends";
const std::string TWITCURL_SHOWFOLLOWERS_URL = TWITCURL_BASE_URL + "statuses/followers";
/* Direct messages URLs */
const std::string TWITCURL_DIRECTMESSAGES_URL = TWITCURL_BASE_URL + "direct_messages";
const std::string TWITCURL_DIRECTMESSAGENEW_URL = TWITCURL_BASE_URL + "direct_messages/new";
const std::string TWITCURL_DIRECTMESSAGESSENT_URL = TWITCURL_BASE_URL + "direct_messages/sent";
const std::string TWITCURL_DIRECTMESSAGEDESTROY_URL = TWITCURL_BASE_URL + "direct_messages/destroy/";
/* Friendships URLs */
const std::string TWITCURL_FRIENDSHIPSCREATE_URL = TWITCURL_BASE_URL + "friendships/create";
const std::string TWITCURL_FRIENDSHIPSDESTROY_URL = TWITCURL_BASE_URL + "friendships/destroy";
const std::string TWITCURL_FRIENDSHIPSSHOW_URL = TWITCURL_BASE_URL + "friendships/show";
/* Social graphs URLs */
const std::string TWITCURL_FRIENDSIDS_URL = TWITCURL_BASE_URL + "friends/ids";
const std::string TWITCURL_FOLLOWERSIDS_URL = TWITCURL_BASE_URL + "followers/ids";
/* Account URLs */
const std::string TWITCURL_ACCOUNTRATELIMIT_URL = TWITCURL_BASE_URL + "account/rate_limit_status";
const std::string TWITCURL_ACCOUNTVERIFYCRED_URL = TWITCURL_BASE_URL + "account/verify_credentials";
/* Favorites URLs */
const std::string TWITCURL_FAVORITESGET_URL = TWITCURL_BASE_URL + "favorites";
const std::string TWITCURL_FAVORITECREATE_URL = TWITCURL_BASE_URL + "favorites/create/";
const std::string TWITCURL_FAVORITEDESTROY_URL = TWITCURL_BASE_URL + "favorites/destroy/";
/* Block URLs */
const std::string TWITCURL_BLOCKSCREATE_URL = TWITCURL_BASE_URL + "blocks/create/";
const std::string TWITCURL_BLOCKSDESTROY_URL = TWITCURL_BASE_URL + "blocks/destroy/";
const std::string TWITCURL_BLOCKSLIST_URL = TWITCURL_BASE_URL + "blocks/list";
const std::string TWITCURL_BLOCKSIDS_URL = TWITCURL_BASE_URL + "blocks/ids";
/* Saved Search URLs */
const std::string TWITCURL_SAVEDSEARCHGET_URL = TWITCURL_BASE_URL + "saved_searches";
const std::string TWITCURL_SAVEDSEARCHSHOW_URL = TWITCURL_BASE_URL + "saved_searches/show/";
const std::string TWITCURL_SAVEDSEARCHCREATE_URL = TWITCURL_BASE_URL + "saved_searches/create";
const std::string TWITCURL_SAVEDSEARCHDESTROY_URL = TWITCURL_BASE_URL + "saved_searches/destroy/";
/* Trends URLs */
const std::string TWITCURL_TRENDS_URL = TWITCURL_BASE_URL + "trends";
const std::string TWITCURL_TRENDSDAILY_URL = TWITCURL_BASE_URL + "trends/daily";
const std::string TWITCURL_TRENDSCURRENT_URL = TWITCURL_BASE_URL + "trends/current";
const std::string TWITCURL_TRENDSWEEKLY_URL = TWITCURL_BASE_URL + "trends/weekly";
const std::string TWITCURL_TRENDSAVAILABLE_URL = TWITCURL_BASE_URL + "trends/available";
};
namespace oAuthLibDefaults
{
/* Constants */
const int OAUTHLIB_BUFFSIZE = 1024;
const int OAUTHLIB_BUFFSIZE_LARGE = 1024;
const std::string OAUTHLIB_CONSUMERKEY_KEY = "oauth_consumer_key";
const std::string OAUTHLIB_CALLBACK_KEY = "oauth_callback";
const std::string OAUTHLIB_VERSION_KEY = "oauth_version";
const std::string OAUTHLIB_SIGNATUREMETHOD_KEY = "oauth_signature_method";
const std::string OAUTHLIB_SIGNATURE_KEY = "oauth_signature";
const std::string OAUTHLIB_TIMESTAMP_KEY = "oauth_timestamp";
const std::string OAUTHLIB_NONCE_KEY = "oauth_nonce";
const std::string OAUTHLIB_TOKEN_KEY = "oauth_token";
const std::string OAUTHLIB_TOKENSECRET_KEY = "oauth_token_secret";
const std::string OAUTHLIB_VERIFIER_KEY = "oauth_verifier";
const std::string OAUTHLIB_SCREENNAME_KEY = "screen_name";
const std::string OAUTHLIB_AUTHENTICITY_TOKEN_KEY = "authenticity_token";
const std::string OAUTHLIB_SESSIONUSERNAME_KEY = "session[username_or_email]";
const std::string OAUTHLIB_SESSIONPASSWORD_KEY = "session[password]";
const std::string OAUTHLIB_AUTHENTICITY_TOKEN_TWITTER_RESP_KEY = "authenticity_token\" type=\"hidden\" value=\"";
const std::string OAUTHLIB_TOKEN_TWITTER_RESP_KEY = "oauth_token\" type=\"hidden\" value=\"";
const std::string OAUTHLIB_PIN_TWITTER_RESP_KEY = "code-desc\"><code>";
const std::string OAUTHLIB_TOKEN_END_TAG_TWITTER_RESP = "\" />";
const std::string OAUTHLIB_PIN_END_TAG_TWITTER_RESP = "</code>";
const std::string OAUTHLIB_AUTHHEADER_STRING = "Authorization: OAuth ";
};
namespace oAuthTwitterApiUrls
{
/* Twitter OAuth API URLs */
const std::string OAUTHLIB_TWITTER_REQUEST_TOKEN_URL = "api.twitter.com/oauth/request_token";
const std::string OAUTHLIB_TWITTER_AUTHORIZE_URL = "api.twitter.com/oauth/authorize?oauth_token=";
const std::string OAUTHLIB_TWITTER_ACCESS_TOKEN_URL = "api.twitter.com/oauth/access_token";
};
#endif // _TWITCURLURLS_H_

View file

@ -37,4 +37,4 @@ std::string urlencode( const std::string &c )
}
}
return escaped;
}
}

View file

@ -7,4 +7,4 @@
std::string char2hex( char dec );
std::string urlencode( const std::string &c );
#endif // __URLENCODE_H__
#endif // __URLENCODE_H__