Changeset - 1c07b23da64e
[Not reviewed]
0 5 0
Vitaly Takmazov - 12 years ago 2013-06-14 10:48:21
vitalyster@gmail.com
Twitter backend: json parsing
5 files changed with 170 insertions and 188 deletions:
0 comments (0 inline, 0 general)
backends/twitter/CMakeLists.txt
Show inline comments
 
@@ -6,7 +6,7 @@ if (NOT WIN32)
 
target_link_libraries(spectrum2_twitter_backend curl transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 
else ()
 
include_directories("${CMAKE_SOURCE_DIR}/msvc-deps/curl/include")
 
target_link_libraries(spectrum2_twitter_backend libcurl_imp transport ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 
target_link_libraries(spectrum2_twitter_backend libcurl transport ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 
endif()
 

	
 
INSTALL(TARGETS spectrum2_twitter_backend RUNTIME DESTINATION bin)
backends/twitter/TwitterPlugin.cpp
Show inline comments
 
@@ -489,6 +489,7 @@ void TwitterPlugin::initUserSession(const std::string user, const std::string le
 
	userdb[user].legacyName = username;	
 
	userdb[user].sessions->setTwitterUsername(username);
 
	userdb[user].sessions->setTwitterPassword(passwd);
 
	userdb[user].sessions->setTwitterApiType(twitCurlTypes::eTwitCurlApiFormatType::eTwitCurlApiFormatJson);
 

	
 
	if(!userdb[user].spectrum1User) {
 
		userdb[user].sessions->getOAuth().setConsumerKey(consumerKey);
 
@@ -594,6 +595,7 @@ std::string TwitterPlugin::getMostRecentDMIDUnsafe(const std::string user) {
 
			}
 
		}
 
	}
 
	return ID;
 
}
 

	
 
std::string TwitterPlugin::getMostRecentDMID(const std::string user)
backends/twitter/TwitterResponseParser.cpp
Show inline comments
 
@@ -4,7 +4,6 @@
 
#include <cctype>
 
#include "boost/date_time/local_time/local_time.hpp"
 
#include "boost/date_time/time_facet.hpp"
 
#include "Swiften/Parser/Tree/NullParserElement.h"
 

	
 
DEFINE_LOGGER(logger, "TwitterResponseParser")
 

	
 
@@ -39,246 +38,226 @@ static std::string toIsoTime(std::string in) {
 
	return ss.str();
 
}
 

	
 
EmbeddedStatus getEmbeddedStatus(const Swift::ParserElement::ref &element, const std::string xmlns)
 
EmbeddedStatus getEmbeddedStatus(const rapidjson::Value &element)
 
{
 
	EmbeddedStatus status;
 
	if(element->getName() != TwitterReponseTypes::status) {
 
	if(!element.IsObject()) {
 
		LOG4CXX_ERROR(logger, "Not a status element!")
 
		return status;
 
	}
 

	
 
	status.setCreationTime( toIsoTime(std::string( element->getChild(TwitterReponseTypes::created_at, xmlns)->getText() ) ) );
 

	
 
	status.setID( std::string( element->getChild(TwitterReponseTypes::id, xmlns)->getText() ) );
 
	status.setTweet( unescape (std::string( element->getChild(TwitterReponseTypes::text, xmlns)->getText() ) ) );
 
	status.setTruncated( std::string( element->getChild(TwitterReponseTypes::truncated, xmlns)->getText() )=="true" );
 
	status.setReplyToStatusID( std::string( element->getChild(TwitterReponseTypes::in_reply_to_status_id, xmlns)->getText() ) );
 
	status.setReplyToUserID( std::string( element->getChild(TwitterReponseTypes::in_reply_to_user_id, xmlns)->getText() ) );
 
	status.setReplyToScreenName( std::string( element->getChild(TwitterReponseTypes::in_reply_to_screen_name, xmlns)->getText() ) );
 
	status.setRetweetCount( atoi( element->getChild(TwitterReponseTypes::retweet_count, xmlns)->getText().c_str() ) );
 
	status.setFavorited( std::string( element->getChild(TwitterReponseTypes::favorited, xmlns)->getText() )=="true" );
 
	status.setRetweeted( std::string( element->getChild(TwitterReponseTypes::retweeted, xmlns)->getText() )=="true" );	
 
	status.setCreationTime( toIsoTime ( std::string( element[TwitterReponseTypes::created_at.c_str()].GetString() ) ) );
 
	status.setID( std::to_string( element[TwitterReponseTypes::id.c_str()].GetInt64() ) ); 
 
	status.setTweet( unescape ( std::string( element[TwitterReponseTypes::text.c_str()].GetString() ) ) );
 
	status.setTruncated( element[TwitterReponseTypes::truncated.c_str()].GetBool());
 
	status.setReplyToStatusID( element[TwitterReponseTypes::in_reply_to_status_id.c_str()].IsNull() ?
 
NULL : std::string(element[TwitterReponseTypes::in_reply_to_status_id.c_str()].GetString()) );
 
	status.setReplyToUserID( element[TwitterReponseTypes::in_reply_to_user_id.c_str()].IsNull() ?
 
NULL : std::string(element[TwitterReponseTypes::in_reply_to_user_id.c_str()].GetString())  );
 
	status.setReplyToScreenName( element[TwitterReponseTypes::in_reply_to_screen_name.c_str()].IsNull() ?
 
NULL : std::string(element[TwitterReponseTypes::in_reply_to_screen_name.c_str()].GetString()) );
 
	status.setRetweetCount( element[TwitterReponseTypes::retweet_count.c_str()].GetInt64() );
 
	status.setFavorited( element[TwitterReponseTypes::favorited.c_str()].GetBool() );
 
	status.setRetweeted( element[TwitterReponseTypes::retweeted.c_str()].GetBool());	
 
	return status;
 
}
 

	
 
User getUser(const Swift::ParserElement::ref &element, const std::string xmlns) 
 
User getUser(const rapidjson::Value &element) 
 
{
 
	User user;
 
	if(element->getName() != TwitterReponseTypes::user 
 
	   && element->getName() != TwitterReponseTypes::sender
 
	   && element->getName() != TwitterReponseTypes::recipient) {
 
	if(!element.IsObject()) {
 
		LOG4CXX_ERROR(logger, "Not a user element!")
 
		return user;
 
	}
 

	
 
	user.setUserID( std::string( element->getChild(TwitterReponseTypes::id, xmlns)->getText() ) );
 
	user.setScreenName( tolowercase( std::string( element->getChild(TwitterReponseTypes::screen_name, xmlns)->getText() ) ) );
 
	user.setUserName( std::string( element->getChild(TwitterReponseTypes::name, xmlns)->getText() ) );
 
	user.setProfileImgURL( std::string( element->getChild(TwitterReponseTypes::profile_image_url, xmlns)->getText() ) );
 
	user.setNumberOfTweets( atoi(element->getChild(TwitterReponseTypes::statuses_count, xmlns)->getText().c_str()) );
 
	if(element->getChild(TwitterReponseTypes::status, xmlns)) 
 
		user.setLastStatus(getEmbeddedStatus(element->getChild(TwitterReponseTypes::status, xmlns),  xmlns));
 
	user.setUserID( std::to_string( element[TwitterReponseTypes::id.c_str()].GetInt64() ) );
 
	user.setScreenName( tolowercase( std::string( element[TwitterReponseTypes::screen_name.c_str()].GetString() ) ) );
 
	user.setUserName( std::string( element[TwitterReponseTypes::name.c_str()].GetString() ) );
 
	user.setProfileImgURL( std::string( element[TwitterReponseTypes::profile_image_url.c_str()].GetString() ) );
 
	user.setNumberOfTweets( element[TwitterReponseTypes::statuses_count.c_str()].GetInt64() );
 
	if(element[TwitterReponseTypes::status.c_str()].IsObject()) 
 
		user.setLastStatus(getEmbeddedStatus(element[TwitterReponseTypes::status.c_str()]));
 
	return user;
 
}
 

	
 
Status getStatus(const Swift::ParserElement::ref &element, const std::string xmlns) 
 
Status getStatus(const rapidjson::Value &element) 
 
{
 
	Status status;
 
	if(element->getName() != "status") {
 
		LOG4CXX_ERROR(logger, "Not a status element!")
 
		return status;
 
	}
 

	
 
	status.setCreationTime( toIsoTime ( std::string( element->getChild(TwitterReponseTypes::created_at, xmlns)->getText() ) ) );
 
	status.setID( std::string( element->getChild(TwitterReponseTypes::id, xmlns)->getText() ) );
 
	status.setTweet( unescape ( std::string( element->getChild(TwitterReponseTypes::text, xmlns)->getText() ) ) );
 
	status.setTruncated( std::string( element->getChild(TwitterReponseTypes::truncated, xmlns)->getText() )=="true" );
 
	status.setReplyToStatusID( std::string( element->getChild(TwitterReponseTypes::in_reply_to_status_id, xmlns)->getText() ) );
 
	status.setReplyToUserID( std::string( element->getChild(TwitterReponseTypes::in_reply_to_user_id, xmlns)->getText() ) );
 
	status.setReplyToScreenName( std::string( element->getChild(TwitterReponseTypes::in_reply_to_screen_name, xmlns)->getText() ) );
 
	status.setUserData( getUser(element->getChild(TwitterReponseTypes::user, xmlns), xmlns) );
 
	status.setRetweetCount( atoi( element->getChild(TwitterReponseTypes::retweet_count, xmlns)->getText().c_str() ) );
 
	status.setFavorited( std::string( element->getChild(TwitterReponseTypes::favorited, xmlns)->getText() )=="true" );
 
	status.setRetweeted( std::string( element->getChild(TwitterReponseTypes::retweeted, xmlns)->getText() )=="true" );
 
	Swift::ParserElement::ref rt = element->getChild(TwitterReponseTypes::retweeted_status, xmlns);
 
	if (rt != Swift::NullParserElement::element) {
 
		status.setTweet(unescape( std::string( rt->getChild(TwitterReponseTypes::text, xmlns)->getText() + " (RT by @" + status.getUserData().getScreenName() + ")") ) );
 
		status.setRetweetID( std::string ( rt->getChild(TwitterReponseTypes::id, xmlns)->getText() ) );
 
		status.setCreationTime( toIsoTime ( std::string (rt->getChild(TwitterReponseTypes::created_at, xmlns)->getText() ) ) );
 
		status.setUserData( getUser ( rt->getChild(TwitterReponseTypes::user, xmlns), xmlns ) );
 
	
 
	status.setCreationTime( toIsoTime ( std::string( element[TwitterReponseTypes::created_at.c_str()].GetString() ) ) );
 
	status.setID( std::to_string( element[TwitterReponseTypes::id.c_str()].GetInt64()  )); 
 
	status.setTweet( unescape ( std::string( element[TwitterReponseTypes::text.c_str()].GetString() ) ) );
 
	status.setTruncated( element[TwitterReponseTypes::truncated.c_str()].GetBool());
 
	status.setReplyToStatusID( element[TwitterReponseTypes::in_reply_to_status_id.c_str()].IsNull() ?
 
"" : std::string(element[TwitterReponseTypes::in_reply_to_status_id.c_str()].GetString()) );
 
	status.setReplyToUserID( element[TwitterReponseTypes::in_reply_to_user_id.c_str()].IsNull() ?
 
"" : std::string(element[TwitterReponseTypes::in_reply_to_user_id.c_str()].GetString())  );
 
	status.setReplyToScreenName( element[TwitterReponseTypes::in_reply_to_screen_name.c_str()].IsNull() ?
 
"" : std::string(element[TwitterReponseTypes::in_reply_to_screen_name.c_str()].GetString()) );
 
	status.setUserData( getUser(element[TwitterReponseTypes::user.c_str()]) );
 
	status.setRetweetCount( element[TwitterReponseTypes::retweet_count.c_str()].GetInt64() );
 
	status.setFavorited( element[TwitterReponseTypes::favorited.c_str()].GetBool() );
 
	status.setRetweeted( element[TwitterReponseTypes::retweeted.c_str()].GetBool());
 
	const rapidjson::Value &rt = element[TwitterReponseTypes::retweeted_status.c_str()];
 
	if (rt.IsObject()) {
 
		status.setTweet(unescape( std::string( rt[TwitterReponseTypes::text.c_str()].GetString()) + " (RT by @" + status.getUserData().getScreenName() + ")") );
 
		status.setRetweetID( std::to_string(rt[TwitterReponseTypes::id.c_str()].GetInt64()) );
 
		status.setCreationTime( toIsoTime ( std::string (rt[TwitterReponseTypes::created_at.c_str()].GetString() ) ) );
 
		status.setUserData( getUser ( rt[TwitterReponseTypes::user.c_str()]) );
 
	}
 
	return status;
 
}
 

	
 
DirectMessage getDirectMessage(const Swift::ParserElement::ref &element, const std::string xmlns) 
 
DirectMessage getDirectMessage(const rapidjson::Value &element) 
 
{
 
	DirectMessage DM;
 
	if(element->getName() != TwitterReponseTypes::direct_message) {
 
		LOG4CXX_ERROR(logger, "Not a direct_message element!")
 
		return DM;
 
	}
 

	
 
	DM.setCreationTime( toIsoTime ( std::string( element->getChild(TwitterReponseTypes::created_at, xmlns)->getText() ) ) );
 
	DM.setID( std::string( element->getChild(TwitterReponseTypes::id, xmlns)->getText() ) );
 
	DM.setMessage( unescape ( std::string( element->getChild(TwitterReponseTypes::text, xmlns)->getText() ) ) );
 
	DM.setSenderID( std::string( element->getChild(TwitterReponseTypes::sender_id, xmlns)->getText() ) );
 
	DM.setRecipientID( std::string( element->getChild(TwitterReponseTypes::recipient_id, xmlns)->getText() ) );
 
	DM.setSenderScreenName( std::string( element->getChild(TwitterReponseTypes::sender_screen_name, xmlns)->getText() ) );
 
	DM.setRecipientScreenName( std::string( element->getChild(TwitterReponseTypes::recipient_screen_name, xmlns)->getText() ) );
 
	DM.setSenderData( getUser(element->getChild(TwitterReponseTypes::sender, xmlns), xmlns) );
 
	DM.setRecipientData( getUser(element->getChild(TwitterReponseTypes::recipient, xmlns), xmlns) );
 
	
 
	DM.setCreationTime( toIsoTime ( std::string( element[TwitterReponseTypes::created_at.c_str()].GetString() ) ) );
 
	DM.setID( std::to_string( element[TwitterReponseTypes::id.c_str()].GetInt64() ) );
 
	DM.setMessage( unescape ( std::string( element[TwitterReponseTypes::text.c_str()].GetString() ) ) );
 
	DM.setSenderID( std::to_string( element[TwitterReponseTypes::sender_id.c_str()].GetInt64())  );
 
	DM.setRecipientID( std::to_string( element[TwitterReponseTypes::recipient_id.c_str()].GetInt64() ) );
 
	DM.setSenderScreenName( std::string( element[TwitterReponseTypes::sender_screen_name.c_str()].GetString() ) );
 
	DM.setRecipientScreenName( std::string( element[TwitterReponseTypes::recipient_screen_name.c_str()].GetString() ) );
 
	DM.setSenderData( getUser(element[TwitterReponseTypes::sender.c_str()] ));
 
	DM.setRecipientData( getUser(element[TwitterReponseTypes::recipient.c_str()]) );
 
	return DM;
 
}
 

	
 
std::vector<Status> getTimeline(std::string &xml)
 
std::vector<Status> getTimeline(std::string &json)
 
{
 
	std::vector<Status> statuses;
 
	Swift::ParserElement::ref rootElement = Swift::StringTreeParser::parse(xml);
 
	rapidjson::Document rootElement;
 
	
 
	if(rootElement == NULL) {
 
		LOG4CXX_ERROR(logger, "Error while parsing XML")
 
        LOG4CXX_ERROR(logger, xml)
 
	if(rootElement.Parse<0>(json.c_str()).HasParseError()) {
 
		LOG4CXX_ERROR(logger, "Error while parsing JSON")
 
        LOG4CXX_ERROR(logger, json)
 
		return statuses;
 
	}
 

	
 
	if(rootElement->getName() != "statuses") {
 
		LOG4CXX_ERROR(logger, "XML doesn't correspond to timeline:")
 
        LOG4CXX_ERROR(logger, xml)
 
	if(!rootElement.IsArray()) {
 
		LOG4CXX_ERROR(logger, "JSON doesn't correspond to timeline:")
 
        LOG4CXX_ERROR(logger, json)
 
		return statuses;
 
	}
 

	
 
	const std::string xmlns = rootElement->getNamespace();
 
	const std::vector<Swift::ParserElement::ref> children = rootElement->getChildren(TwitterReponseTypes::status, xmlns);
 

	
 
	for(int i = 0; i <  children.size() ; i++) {
 
		const Swift::ParserElement::ref status = children[i];
 
		statuses.push_back(getStatus(status, xmlns));
 
	for(rapidjson::SizeType i = 0; i < rootElement.Size(); i++) {
 
		statuses.push_back(getStatus(rootElement[i]));
 
	}
 
	return statuses;
 
}
 

	
 
std::vector<DirectMessage> getDirectMessages(std::string &xml)
 
std::vector<DirectMessage> getDirectMessages(std::string &json)
 
{
 
	std::vector<DirectMessage> DMs;
 
	Swift::ParserElement::ref rootElement = Swift::StringTreeParser::parse(xml);
 
	rapidjson::Document rootElement;
 
	
 
	if(rootElement == NULL) {
 
		LOG4CXX_ERROR(logger, "Error while parsing XML")
 
        LOG4CXX_ERROR(logger, xml)
 
		return DMs;
 
	}
 
	
 
	if(rootElement->getName() != TwitterReponseTypes::directmessages) {
 
		LOG4CXX_ERROR(logger, "XML doesn't correspond to direct-messages:")
 
        LOG4CXX_ERROR(logger, xml)
 
	if(rootElement.Parse<0>(json.c_str()).HasParseError()) {
 
		LOG4CXX_ERROR(logger, "Error while parsing JSON")
 
        LOG4CXX_ERROR(logger, json)
 
		return DMs;
 
	}
 

	
 
	const std::string xmlns = rootElement->getNamespace();
 
	const std::vector<Swift::ParserElement::ref> children = rootElement->getChildren(TwitterReponseTypes::direct_message, xmlns);
 
	if(!rootElement.IsArray()) {
 
		LOG4CXX_ERROR(logger, "JSON doesn't correspond to direct messages:")
 
        LOG4CXX_ERROR(logger, json)
 
		return DMs;
 
	}
 

	
 
	for(int i = 0; i <  children.size() ; i++) {
 
		const Swift::ParserElement::ref dm = children[i];
 
		DMs.push_back(getDirectMessage(dm, xmlns));
 
	for(rapidjson::SizeType i = 0; i < rootElement.Size(); i++) {
 
		DMs.push_back(getDirectMessage(rootElement[i]));
 
	}
 
	return DMs;
 
}
 

	
 
std::vector<User> getUsers(std::string &xml)
 
std::vector<User> getUsers(std::string &json)
 
{
 
	std::vector<User> users;
 
	Swift::ParserElement::ref rootElement = Swift::StringTreeParser::parse(xml);
 
	rapidjson::Document rootElement;
 
	
 
	
 
	if(rootElement == NULL) {
 
		LOG4CXX_ERROR(logger, "Error while parsing XML")
 
        LOG4CXX_ERROR(logger, xml)
 
	if(rootElement.Parse<0>(json.c_str()).HasParseError()) {
 
		LOG4CXX_ERROR(logger, "Error while parsing JSON")
 
        LOG4CXX_ERROR(logger, json)
 
		return users;
 
	}
 

	
 
	if(rootElement->getName() != TwitterReponseTypes::users) {
 
		LOG4CXX_ERROR(logger, "XML doesn't correspond to user list:")
 
        LOG4CXX_ERROR(logger, xml)
 
	if(!rootElement.IsArray()) {
 
		LOG4CXX_ERROR(logger, "JSON doesn't correspond to user list:")
 
        LOG4CXX_ERROR(logger, json)
 
		return users;
 
	}
 

	
 
	const std::string xmlns = rootElement->getNamespace();
 
	const std::vector<Swift::ParserElement::ref> children = rootElement->getChildren(TwitterReponseTypes::user, xmlns);
 

	
 
	for(int i = 0 ; i < children.size() ; i++) {
 
		const Swift::ParserElement::ref user = children[i];
 
		users.push_back(getUser(user, xmlns));
 
	for(rapidjson::SizeType i = 0; i < rootElement.Size(); i++) {
 
		users.push_back(getUser(rootElement[i]));
 
	}
 
	return users;
 
	return users;	
 
}
 

	
 
User getUser(std::string &xml)
 
User getUser(std::string &json)
 
{
 
	User user;
 
	Swift::ParserElement::ref rootElement = Swift::StringTreeParser::parse(xml);
 
	rapidjson::Document rootElement;
 
	
 
	if(rootElement == NULL) {
 
		LOG4CXX_ERROR(logger, "Error while parsing XML")
 
        LOG4CXX_ERROR(logger, xml)
 
	if(rootElement.Parse<0>(json.c_str()).HasParseError()) {
 
		LOG4CXX_ERROR(logger, "Error while parsing JSON")
 
        LOG4CXX_ERROR(logger, json)
 
		return user;
 
	}
 

	
 
	if(rootElement->getName() != TwitterReponseTypes::user) {
 
		LOG4CXX_ERROR(logger, "XML doesn't correspond to user object")
 
        LOG4CXX_ERROR(logger, xml)
 
	if(!rootElement.IsObject()) {
 
		LOG4CXX_ERROR(logger, "JSON doesn't correspond to user object")
 
        LOG4CXX_ERROR(logger, json)
 
		return user;
 
	}
 

	
 
	const std::string xmlns = rootElement->getNamespace();
 
	return user = getUser(rootElement, xmlns);
 
	return user = getUser(rootElement);
 
}
 

	
 
std::vector<std::string> getIDs(std::string &xml)
 
std::vector<std::string> getIDs(std::string &json)
 
{
 
	std::vector<std::string> IDs;
 
	Swift::ParserElement::ref rootElement = Swift::StringTreeParser::parse(xml);
 

	
 
	if(rootElement == NULL) {
 
		LOG4CXX_ERROR(logger, "Error while parsing XML")
 
        LOG4CXX_ERROR(logger, xml)
 
	rapidjson::Document rootElement;
 
	
 
	if(rootElement.Parse<0>(json.c_str()).HasParseError()) {
 
		LOG4CXX_ERROR(logger, "Error while parsing JSON")
 
        LOG4CXX_ERROR(logger, json)
 
		return IDs;
 
	}
 

	
 
	if(rootElement->getName() != TwitterReponseTypes::id_list) {
 
		LOG4CXX_ERROR(logger, "XML doesn't correspond to id_list");
 
        LOG4CXX_ERROR(logger, xml)
 
	if(!rootElement.IsObject()) {
 
		LOG4CXX_ERROR(logger, "JSON doesn't correspond to id_list");
 
        LOG4CXX_ERROR(logger, json)
 
		return IDs;
 
	}
 

	
 
	const std::string xmlns = rootElement->getNamespace();
 
	const std::vector<Swift::ParserElement::ref> ids = rootElement->getChild(TwitterReponseTypes::ids, xmlns)->getChildren(TwitterReponseTypes::id, xmlns);
 
	const rapidjson::Value & ids = rootElement[TwitterReponseTypes::ids.c_str()];
 
	
 
	for(int i=0 ; i<ids.size() ; i++) {
 
		IDs.push_back(std::string( ids[i]->getText() ));
 
	for(int i=0 ; i<ids.Size() ; i++) {
 
		IDs.push_back(std::to_string( ids[i].GetInt64()) );
 
	}
 
	return IDs;
 
}
 

	
 
Error getErrorMessage(std::string &xml)
 
Error getErrorMessage(std::string &json)
 
{
 
	std::string error = "";
 
	std::string code = "0";
 
	Error resp;
 

	
 
	Swift::ParserElement::ref rootElement = Swift::StringTreeParser::parse(xml);
 

	
 
	if(rootElement == NULL) {
 
		LOG4CXX_ERROR(logger, "Error while parsing XML");
 
        LOG4CXX_ERROR(logger, xml)
 
	rapidjson::Document rootElement;
 
	
 
	if(rootElement.Parse<0>(json.c_str()).HasParseError()) {
 
		LOG4CXX_ERROR(logger, "Error while parsing JSON")
 
        LOG4CXX_ERROR(logger, json)
 
		return resp;
 
	}
 

	
 
	const std::string xmlns = rootElement->getNamespace();
 
	const Swift::ParserElement::ref errorElement = rootElement->getChild(TwitterReponseTypes::error, xmlns);
 
	Swift::AttributeMap attributes = errorElement->getAttributes();
 
		
 
	const rapidjson::Value &errorElement = rootElement[TwitterReponseTypes::error.c_str()];
 
	
 
	if(errorElement != NULL) {
 
		error = errorElement->getText();
 
		code = (errorElement->getAttributes()).getAttribute("code");
 
	if(errorElement.IsArray()) {
 
		error = std::string(errorElement["message"].GetString());
 
		code = std::to_string(errorElement["code"].GetInt64());
 
	}
 

	
 
	resp.setCode(code);
backends/twitter/TwitterResponseParser.h
Show inline comments
 
#ifndef TWITTERRESPOSNSEPARSER_H
 
#define TWITTERRESPOSNSEPARSER_H
 

	
 
#include "Swiften/Parser/StringTreeParser.h"
 
#include "rapidjson/document.h"
 
#include <iostream>
 
#include <vector>
 
#include <string>
 

	
 
namespace TwitterReponseTypes
 
{
 
@@ -217,7 +218,7 @@ std::vector<User> getUsers(std::string &xml);
 
User getUser(std::string &xml);
 
Error getErrorMessage(std::string &xml);
 

	
 
Status getStatus(const Swift::ParserElement::ref &element, const std::string xmlns);
 
DirectMessage getDirectMessage(const Swift::ParserElement::ref &element, const std::string xmlns);
 
User getUser(const Swift::ParserElement::ref &element, const std::string xmlns);
 
Status getStatus(const rapidjson::Value &element);
 
DirectMessage getDirectMessage(const rapidjson::Value &element);
 
User getUser(const rapidjson::Value &element);
 
#endif
backends/twitter/libtwitcurl/twitcurl.h
Show inline comments
 
@@ -69,65 +69,65 @@ namespace twitterDefaults
 
    const std::string TWITCURL_SEARCH_URL = "search.twitter.com/search";
 
 
    /* Status URLs */
 
    const std::string TWITCURL_STATUSUPDATE_URL = "api.twitter.com/1/statuses/update";
 
    const std::string TWITCURL_STATUSSHOW_URL = "api.twitter.com/1/statuses/show/";
 
    const std::string TWITCURL_STATUDESTROY_URL = "api.twitter.com/1/statuses/destroy/";
 
	const std::string TWITCURL_RETWEET_URL = "api.twitter.com/1/statuses/retweet/";
 
    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/statuses/home_timeline";
 
    const std::string TWITCURL_PUBLIC_TIMELINE_URL = "api.twitter.com/1/statuses/public_timeline";
 
    const std::string TWITCURL_FEATURED_USERS_URL = "api.twitter.com/1/statuses/featured";
 
    const std::string TWITCURL_FRIENDS_TIMELINE_URL = "api.twitter.com/1/statuses/friends_timeline";
 
    const std::string TWITCURL_MENTIONS_URL = "api.twitter.com/1/statuses/mentions";
 
    const std::string TWITCURL_USERTIMELINE_URL = "api.twitter.com/1/statuses/user_timeline";
 
    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/users/lookup";
 
    const std::string TWITCURL_SHOWUSERS_URL = "api.twitter.com/1/users/show";
 
    const std::string TWITCURL_SHOWFRIENDS_URL = "api.twitter.com/1/statuses/friends";
 
    const std::string TWITCURL_SHOWFOLLOWERS_URL = "api.twitter.com/1/statuses/followers";
 
	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/direct_messages";
 
    const std::string TWITCURL_DIRECTMESSAGENEW_URL = "api.twitter.com/1/direct_messages/new";
 
    const std::string TWITCURL_DIRECTMESSAGESSENT_URL = "api.twitter.com/1/direct_messages/sent";
 
    const std::string TWITCURL_DIRECTMESSAGEDESTROY_URL = "api.twitter.com/1/direct_messages/destroy/";
 
    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/friendships/create";
 
    const std::string TWITCURL_FRIENDSHIPSDESTROY_URL = "api.twitter.com/1/friendships/destroy";
 
    const std::string TWITCURL_FRIENDSHIPSSHOW_URL = "api.twitter.com/1/friendships/show";
 
    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/friends/ids";
 
    const std::string TWITCURL_FOLLOWERSIDS_URL = "api.twitter.com/1/followers/ids";
 
    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/account/rate_limit_status";
 
    const std::string TWITCURL_ACCOUNTVERIFYCRED_URL = "api.twitter.com/1/account/verify_credentials";
 
    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/favorites";
 
    const std::string TWITCURL_FAVORITECREATE_URL = "api.twitter.com/1/favorites/create/";
 
    const std::string TWITCURL_FAVORITEDESTROY_URL = "api.twitter.com/1/favorites/destroy/";
 
    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/blocks/create/";
 
    const std::string TWITCURL_BLOCKSDESTROY_URL = "api.twitter.com/1/blocks/destroy/";
 
    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/saved_searches";
 
    const std::string TWITCURL_SAVEDSEARCHSHOW_URL = "api.twitter.com/1/saved_searches/show/";
 
    const std::string TWITCURL_SAVEDSEARCHCREATE_URL = "api.twitter.com/1/saved_searches/create";
 
    const std::string TWITCURL_SAVEDSEARCHDESTROY_URL = "api.twitter.com/1/saved_searches/destroy/";
 
    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/trends";
 
    const std::string TWITCURL_TRENDSDAILY_URL = "api.twitter.com/1/trends/daily";
 
    const std::string TWITCURL_TRENDSCURRENT_URL = "api.twitter.com/1/trends/current";
 
    const std::string TWITCURL_TRENDSWEEKLY_URL = "api.twitter.com/1/trends/weekly";
 
    const std::string TWITCURL_TRENDSAVAILABLE_URL = "api.twitter.com/1/trends/available";
 
    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";
 
 
};
 
0 comments (0 inline, 0 general)