Changeset - 00248dfbc0df
[Not reviewed]
0 3 0
Vitaly Takmazov - 7 years ago 2018-04-28 10:31:36
vitalyster@gmail.com
Twitter backend: 280 characters support
3 files changed with 18 insertions and 14 deletions:
0 comments (0 inline, 0 general)
backends/twitter/TwitterResponseParser.h
Show inline comments
 
@@ -8,25 +8,25 @@
 
#include <string>
 
#include <utility>
 

	
 
namespace TwitterReponseTypes
 
{
 
	const std::string id = "id";
 
	const std::string id_list = "id_list";
 
	const std::string ids = "ids";
 
	const std::string name = "name";
 
	const std::string screen_name = "screen_name";
 
	const std::string statuses_count = "statuses_count";
 
	const std::string created_at = "created_at";
 
	const std::string text = "text";
 
	const std::string text = "full_text";
 
	const std::string truncated = "truncated";
 
	const std::string in_reply_to_status_id = "in_reply_to_user_id";
 
	const std::string in_reply_to_user_id = "in_reply_to_user_id";
 
	const std::string in_reply_to_screen_name = "in_reply_to_screen_name";
 
	const std::string retweet_count = "retweet_count";
 
	const std::string retweeted_status = "retweeted_status";
 
	const std::string favorited = "favorited";
 
	const std::string retweeted = "retweeted";
 
	const std::string user = "user";
 
	const std::string users = "users";
 
	const std::string status = "status";
 
	const std::string error = "error";
backends/twitter/libtwitcurl/twitcurl.cpp
Show inline comments
 
@@ -340,25 +340,25 @@ void twitCurl::setProxyPassword( std::string& proxyPassword )
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
* @note: Only ATOM and JSON format supported.
 
*
 
*--*/
 
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[m_eApiFormatType] +
 
                           twitCurlDefaults::TWITCURL_URL_SEP_QUES + twitCurlDefaults::TWITCURL_SEARCHQUERYSTRING +
 
                           searchQuery;
 
                           searchQuery + twitCurlDefaults::TWITCURL_URL_SEP_AMP + twitCurlDefaults::TWITCURL_TWEET_MODE_EXTENDED;
 

	
 
    /* 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 );
 
}
 

	
 
@@ -411,25 +411,26 @@ bool twitCurl::statusUpdate( std::string& newStatus, std::string inReplyToStatus
 
*
 
*--*/
 
bool twitCurl::statusShowById( std::string& statusId )
 
{
 
    if( statusId.empty() )
 
    {
 
        return false;
 
    }
 

	
 
    /* Prepare URL */
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                           twitterDefaults::TWITCURL_STATUSSHOW_URL + statusId +
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] +
 
			twitCurlDefaults::TWITCURL_URL_SEP_QUES + twitCurlDefaults::TWITCURL_TWEET_MODE_EXTENDED;
 

	
 
    /* Perform GET */
 
    return performGet( buildUrl );
 
}
 

	
 
/*++
 
* @method: twitCurl::statusDestroyById
 
*
 
* @description: method to delete a status message by its id
 
*
 
* @input: statusId - a number in std::string format
 
*
 
@@ -490,51 +491,53 @@ bool twitCurl::retweetById( std::string& statusId )
 
* @description: method to get home timeline
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::timelineHomeGet( std::string sinceId )
 
{
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                           twitterDefaults::TWITCURL_HOME_TIMELINE_URL +
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] +
 
				twitCurlDefaults::TWITCURL_URL_SEP_QUES + twitCurlDefaults::TWITCURL_TWEET_MODE_EXTENDED;
 
    if( sinceId.length() )
 
    {
 
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES + twitCurlDefaults::TWITCURL_SINCEID + sinceId;
 
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_AMP + twitCurlDefaults::TWITCURL_SINCEID + sinceId;
 
    }
 

	
 
    /* Perform GET */
 
    return performGet( buildUrl );
 
}
 

	
 
/*++
 
* @method: twitCurl::timelinePublicGet
 
*
 
* @description: method to get public timeline
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::timelinePublicGet()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       twitterDefaults::TWITCURL_PUBLIC_TIMELINE_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] +
 
			twitCurlDefaults::TWITCURL_URL_SEP_QUES + twitCurlDefaults::TWITCURL_TWEET_MODE_EXTENDED);
 
}
 

	
 
/*++
 
* @method: twitCurl::featuredUsersGet
 
*
 
* @description: method to get featured users
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
@@ -554,46 +557,48 @@ bool twitCurl::featuredUsersGet()
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::timelineFriendsGet()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       twitterDefaults::TWITCURL_FRIENDS_TIMELINE_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] +
 
			twitCurlDefaults::TWITCURL_URL_SEP_QUES + twitCurlDefaults::TWITCURL_TWEET_MODE_EXTENDED);
 
}
 

	
 
/*++
 
* @method: twitCurl::mentionsGet
 
*
 
* @description: method to get mentions
 
*
 
* @input: sinceId - String specifying since id parameter
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::mentionsGet( std::string sinceId )
 
{
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                           twitterDefaults::TWITCURL_MENTIONS_URL +
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] +
 
			twitCurlDefaults::TWITCURL_URL_SEP_QUES + twitCurlDefaults::TWITCURL_TWEET_MODE_EXTENDED;
 
    if( sinceId.length() )
 
    {
 
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES + twitCurlDefaults::TWITCURL_SINCEID + sinceId;
 
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_AMP + twitCurlDefaults::TWITCURL_SINCEID + sinceId;
 
    }
 

	
 
    /* Perform GET */
 
    return performGet( buildUrl );
 
}
 

	
 
/*++
 
* @method: twitCurl::timelineUserGet
 
*
 
* @description: method to get mentions
 
*
 
* @input: trimUser - Trim user name if true
 
@@ -607,28 +612,25 @@ bool twitCurl::mentionsGet( std::string sinceId )
 
*--*/
 
bool twitCurl::timelineUserGet( bool trimUser, bool includeRetweets, unsigned int tweetCount,
 
                                std::string userInfo, bool isUserId )
 
{
 
    /* Prepare URL */
 
    std::string buildUrl;
 

	
 
    utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                        twitterDefaults::TWITCURL_USERTIMELINE_URL +
 
                        twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
 
                        userInfo, isUserId );
 

	
 
    if( userInfo.empty() )
 
    {
 
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES;
 
    }
 
    buildUrl += userInfo.empty() ? twitCurlDefaults::TWITCURL_URL_SEP_QUES : twitCurlDefaults::TWITCURL_URL_SEP_AMP + twitCurlDefaults::TWITCURL_TWEET_MODE_EXTENDED;
 

	
 
    if( tweetCount )
 
    {
 
        if( tweetCount > twitCurlDefaults::MAX_TIMELINE_TWEET_COUNT )
 
        {
 
            tweetCount = twitCurlDefaults::MAX_TIMELINE_TWEET_COUNT;
 
        }
 
        std::stringstream tmpStrm;
 
        tmpStrm << twitCurlDefaults::TWITCURL_URL_SEP_AMP + twitCurlDefaults::TWITCURL_COUNT << tweetCount;
 
        buildUrl += tmpStrm.str();
 
        tmpStrm.str().clear();
 
    }
 
@@ -1084,25 +1086,26 @@ bool twitCurl::accountVerifyCredGet()
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::favoriteGet()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       twitterDefaults::TWITCURL_FAVORITESGET_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] +
 
			twitCurlDefaults::TWITCURL_URL_SEP_QUES + twitCurlDefaults::TWITCURL_TWEET_MODE_EXTENDED);
 
}
 

	
 
/*++
 
* @method: twitCurl::favoriteCreate
 
*
 
* @description: method to favorite a status message
 
*
 
* @input: statusId - id in string format of the status to be favorited
 
*
 
* @output: true if POST is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
backends/twitter/libtwitcurl/twitcurlurls.h
Show inline comments
 
@@ -28,24 +28,25 @@ namespace twitCurlDefaults
 
                                                     };
 
    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=";
 
    const std::string TWITCURL_TWEET_MODE_EXTENDED = "tweet_mode=extended";
 

	
 
    /* 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/";
 

	
0 comments (0 inline, 0 general)