Commit e22372b1 authored by Daniel Kreuter's avatar Daniel Kreuter
Browse files

Favorites switched to new twitter api version

Changed api version for favorites.

CCBUG: 264091
parent c7336ed2
......@@ -93,7 +93,7 @@ TwitterApiMicroBlog::TwitterApiMicroBlog ( const KComponentData &instance, QObje
timelineApiPath["Reply"] = "/statuses/replies.%1";
timelineApiPath["Inbox"] = "/direct_messages.%1";
timelineApiPath["Outbox"] = "/direct_messages/sent.%1";
timelineApiPath["Favorite"] = "/favorites.%1";
timelineApiPath["Favorite"] = "/favorites/list.%1";
timelineApiPath["ReTweets"] = "/statuses/retweets_of_me.%1";
timelineApiPath["Public"] = "/statuses/public_timeline.%1";
setTimelineInfos();
......@@ -569,8 +569,12 @@ void TwitterApiMicroBlog::createFavorite ( Choqok::Account* theAccount, const QS
kDebug();
TwitterApiAccount* account = qobject_cast<TwitterApiAccount*>(theAccount);
KUrl url = account->apiUrl();
url.addPath ( "/favorites/create/" + postId + ".xml" );
KIO::StoredTransferJob *job = KIO::storedHttpPost ( QByteArray(), url, KIO::HideProgressInfo ) ;
//url.addPath ( QString("/favorites/create.json?id=%1").arg(postId));
url.addPath ( "/favorites/create.json" );
QByteArray data;
data = "id=";
data += postId.toLocal8Bit();
KIO::StoredTransferJob *job = KIO::storedHttpPost ( data, url, KIO::HideProgressInfo ) ;
if ( !job ) {
kDebug() << "Cannot create an http POST request!";
// QString errMsg = i18n ( "The Favorite creation failed. Cannot create an http POST request. "
......@@ -614,8 +618,11 @@ void TwitterApiMicroBlog::removeFavorite ( Choqok::Account* theAccount, const QS
kDebug();
TwitterApiAccount* account = qobject_cast<TwitterApiAccount*>(theAccount);
KUrl url = account->apiUrl();
url.addPath ( "/favorites/destroy/" + postId + ".xml" );
KIO::StoredTransferJob *job = KIO::storedHttpPost ( QByteArray(), url, KIO::HideProgressInfo ) ;
url.addPath ( "/favorites/destroy.json" );
QByteArray data;
data = "id=";
data += postId.toLocal8Bit();
KIO::StoredTransferJob *job = KIO::storedHttpPost ( data, url, KIO::HideProgressInfo ) ;
if ( !job ) {
kDebug() << "Cannot create an http POST request!";
// QString errMsg = i18n ( "Removing the favorite failed. Cannot create an http POST request. "
......@@ -667,7 +674,7 @@ void TwitterApiMicroBlog::requestFriendsScreenName(TwitterApiAccount* theAccount
kDebug();
TwitterApiAccount* account = qobject_cast<TwitterApiAccount*>(theAccount);
KUrl url = account->apiUrl();
url.addPath( QString("/statuses/friends.xml") );
url.addPath( QString("/statuses/friends.json") );
KUrl tmpUrl(url);
url.addQueryItem( "cursor", d->friendsCursor );
QOAuth::ParamMap params;
......@@ -815,302 +822,6 @@ QByteArray TwitterApiMicroBlog::authorizationHeader(TwitterApiAccount* theAccoun
return auth;
}
/*Choqok::Post * TwitterApiMicroBlog::readPostFromXml ( Choqok::Account* theAccount,
const QByteArray& buffer, Choqok::Post* post )
{
QDomDocument document;
document.setContent ( buffer );
QDomElement root = document.documentElement();
if ( !root.isNull() ) {
return readPostFromDomElement ( theAccount, root.toElement(), post );
} else {
if(!post){
kError()<<"TwitterApiMicroBlog::readPostFromXml: post is NULL!";
post = new Choqok::Post;
}
QString err = checkXmlForError(buffer);
if(!err.isEmpty())
Q_EMIT error(theAccount, ServerError, err);
post->isError = true;
return post;
}
}*/
/*Choqok::Post * TwitterApiMicroBlog::readPostFromDomElement ( Choqok::Account* theAccount,
const QDomElement &root, Choqok::Post* post )
{
if(!post){
kError()<<"TwitterApiMicroBlog::readPostFromDomElement: post is NULL!";
return 0;
}
if ( root.tagName() != "status" ) {
kDebug() << "there's no status tag in XML, Error!!\t"
<<"Tag is: "<<root.tagName();
post->isError = true ;
return post;
}
QDomNode node2 = root.firstChild();
return readPostFromDomNode(theAccount, node2, post);;
}*/
/*Choqok::Post* TwitterApiMicroBlog::readPostFromDomNode(Choqok::Account* theAccount,
QDomNode node, Choqok::Post* post)
{
Choqok::Post* repeatedPost = 0;
while ( !node.isNull() ) {
QDomElement elm = node.toElement();
if ( elm.tagName() == "created_at" )
post->creationDateTime = dateFromString ( elm.text() );
else if ( elm.tagName() == "text" )
post->content = elm.text();
else if ( elm.tagName() == "id" )
post->postId = elm.text();
else if ( elm.tagName() == "in_reply_to_status_id" )
post->replyToPostId = elm.text();
else if ( elm.tagName() == "in_reply_to_user_id" )
post->replyToUserId = elm.text();
else if ( elm.tagName() == "in_reply_to_screen_name" )
post->replyToUserName = elm.text();
else if ( elm.tagName() == "source" )
post->source = elm.text();
else if ( elm.tagName() == "favorited" )
post->isFavorited = ( elm.text() == "true" ) ? true : false;
else if ( elm.tagName() == "statusnet:conversation_id" )
post->conversationId = elm.text();
else if ( elm.tagName() == "user" ) {
QDomNode node3 = node.firstChild();
while ( !node3.isNull() ) {
QDomElement elm3 = node3.toElement();
if ( elm3.tagName() == "screen_name" ) {
post->author.userName = elm3.text();
} else if ( elm3.tagName() == "profile_image_url" ) {
post->author.profileImageUrl = elm3.text();
} else if ( elm3.tagName() == "id" ) {
post->author.userId = elm3.text();
} else if ( elm3.tagName() == "name" ) {
post->author.realName = elm3.text();
} else if ( elm3.tagName() == QString ( "description" ) ) {
post->author.description = elm3.text();
} else if ( elm3.tagName() == "statusnet:profile_url" ) {
post->author.homePageUrl = elm3.text();
} else if ( elm3.tagName() == "protected" ) {
post->author.isProtected = elm3.text().contains("true") ? true : false;
}
node3 = node3.nextSibling();
}
} else if ( elm.tagName() == "retweeted_status" )
repeatedPost = readPostFromDomNode( theAccount, elm.firstChild(), new Choqok::Post);
node = node.nextSibling();
}
if(repeatedPost){
setRepeatedOfInfo(post,repeatedPost);
delete repeatedPost;
}
post->link = postUrl(theAccount, post->author.userName, post->postId);
post->isRead = post->isFavorited || (post->repeatedFromUsername.compare(theAccount->username(), Qt::CaseInsensitive) == 0);
return post;
}*/
/*QList<Choqok::Post*> TwitterApiMicroBlog::readTimelineFromXml ( Choqok::Account* theAccount,
const QByteArray &buffer )
{
QDomDocument document;
QList<Choqok::Post*> postList;
document.setContent ( buffer );
QDomElement root = document.documentElement();
if ( root.tagName() != "statuses" ) {
// QString err = i18n( "Data returned from server is corrupted." );
kDebug() << "there's no statuses tag in XML\t the XML is: \n" << buffer;
QString err = checkXmlForError(buffer);
if(!err.isEmpty())
Q_EMIT error(theAccount, ServerError, err);
return postList;
}
QDomNode node = root.firstChild();
while ( !node.isNull() ) {
postList.prepend( readPostFromDomElement ( theAccount, node.toElement(), new Choqok::Post ) );
node = node.nextSibling();
}
return postList;
}*/
/*Choqok::Post * TwitterApiMicroBlog::readDMessageFromXml (Choqok::Account *theAccount, const QByteArray &buffer )
{
QDomDocument document;
document.setContent ( buffer );
QDomElement root = document.documentElement();
if ( !root.isNull() ) {
return readDMessageFromDomElement ( theAccount, root.toElement() );
} else {
Choqok::Post *post = new Choqok::Post;
post->isError = true;
QString err = checkXmlForError(buffer);
if(!err.isEmpty())
Q_EMIT error(theAccount, ServerError, err);
return post;
}
}*/
/*Choqok::Post * TwitterApiMicroBlog::readDMessageFromDomElement ( Choqok::Account* theAccount,
const QDomElement& root )
{
Choqok::Post *msg = new Choqok::Post;
if ( root.tagName() != "direct_message" ) {
kDebug() << "there's no direct_message tag in XML, Error!!\t"
<<"Tag is: "<<root.tagName();
msg->isError = true;
return msg;
}
QDomNode node2 = root.firstChild();
msg->isPrivate = true;
QString senderId, recipientId, timeStr, senderScreenName, recipientScreenName, senderProfileImageUrl,
senderName, senderDescription, recipientProfileImageUrl, recipientName, recipientDescription;
while ( !node2.isNull() ) {
QDomElement elm = node2.toElement();
if ( elm.tagName() == "created_at" )
timeStr = elm.text();
else if ( elm.tagName() == "text" )
msg->content = elm.text();
else if ( elm.tagName() == "id" )
msg->postId = elm.text();
else if ( elm.tagName() == "sender_id" )
senderId = elm.text();
else if ( elm.tagName() == "recipient_id" )
recipientId = elm.text();
else if ( elm.tagName() == "sender_screen_name" )
senderScreenName = elm.text();
else if ( elm.tagName() == "recipient_screen_name" )
recipientScreenName = elm.text();
else if ( elm.tagName() == "sender" ) {
QDomNode node3 = node2.firstChild();
while ( !node3.isNull() ) {
QDomElement elm3 = node3.toElement();
if ( elm3.tagName() == "profile_image_url" ) {
senderProfileImageUrl = elm3.text();
} else if ( elm3.tagName() == "name" ) {
senderName = elm3.text();
} else if ( elm3.tagName() == "description" ) {
senderDescription = elm3.text();
}
node3 = node3.nextSibling();
}
} else
if ( elm.tagName() == "recipient" ) {
QDomNode node3 = node2.firstChild();
while ( !node3.isNull() ) {
QDomElement elm3 = node3.toElement();
if ( elm3.tagName() == "profile_image_url" ) {
recipientProfileImageUrl = elm3.text();
} else if ( elm3.tagName() == "name" ) {
recipientName = elm3.text();
} else if ( elm3.tagName() == "description" ) {
recipientDescription = elm3.text();
}
node3 = node3.nextSibling();
}
}
node2 = node2.nextSibling();
}
msg->creationDateTime = dateFromString ( timeStr );
if ( senderScreenName.compare( theAccount->username(), Qt::CaseInsensitive) == 0 ) {
msg->author.description = recipientDescription;
msg->author.userName = recipientScreenName;
msg->author.profileImageUrl = recipientProfileImageUrl;
msg->author.realName = recipientName;
msg->author.userId = recipientId;
msg->replyToUserId = recipientId;
msg->replyToUserName = recipientScreenName;
msg->isRead = true;
} else {
msg->author.description = senderDescription;
msg->author.userName = senderScreenName;
msg->author.profileImageUrl = senderProfileImageUrl;
msg->author.realName = senderName;
msg->author.userId = senderId;
msg->replyToUserId = recipientId;
msg->replyToUserName = recipientScreenName;
}
return msg;
}*/
/*QList<Choqok::Post*> TwitterApiMicroBlog::readDMessagesFromXml (Choqok::Account *theAccount,
const QByteArray &buffer )
{
QDomDocument document;
QList<Choqok::Post*> postList;
document.setContent ( buffer );
QDomElement root = document.documentElement();
if ( root.tagName() != "direct-messages" ) {
// QString err = i18n( "Data returned from server is corrupted." );
kDebug() << "there's no statuses tag in XML\t the XML is: \n" << buffer.data();
QString err = checkXmlForError(buffer);
if(!err.isEmpty())
Q_EMIT error(theAccount, ServerError, err);
return postList;
}
QDomNode node = root.firstChild();
while ( !node.isNull() ) {
postList.prepend( readDMessageFromDomElement ( theAccount, node.toElement() ) );
node = node.nextSibling();
}
return postList;
}*/
/*QStringList TwitterApiMicroBlog::readUsersScreenNameFromXml( Choqok::Account* theAccount, const QByteArray& buffer )
{
kDebug();
QStringList list;
QDomDocument document;
document.setContent( buffer );
QDomElement root = document.documentElement();
if ( root.tagName() != "users_list" ) {
QString err = checkXmlForError(buffer);
if(!err.isEmpty()){
emit error(theAccount, ServerError, err, Critical);
} else {
err = i18n( "Retrieving the friends list failed. The data returned from the server is corrupted." );
kDebug() << "there's no users tag in XML\t the XML is: \n" << buffer;
emit error(theAccount, ParsingError, err, Critical);
list<<QString(' ');
}
return list;
}
QDomNode section = root.firstChild();
QDomNode node = section.firstChild();
while ( !section.isNull() ) {
if ( section.toElement().tagName() == "users" ) {
while ( !node.isNull() ) {
if ( node.toElement().tagName() != "user" ) {
kDebug() << "there's no user tag in XML!\n"<<buffer;
return list;
}
QDomNode node2 = node.firstChild();
while ( !node2.isNull() ) {
if ( node2.toElement().tagName() == "screen_name" ) {
list.append( node2.toElement().text() );
break;
}
node2 = node2.nextSibling();
}
node = node.nextSibling();
}
} else if ( section.toElement().tagName() == "next_cursor" ) {
d->friendsCursor = section.toElement().text();
}
section = section.nextSibling();
}
return list;
}*/
void TwitterApiMicroBlog::setRepeatedOfInfo(Choqok::Post* post, Choqok::Post* repeatedPost)
{
if( Choqok::AppearanceSettings::showRetweetsInChoqokWay() ) {
......@@ -1203,7 +914,7 @@ void TwitterApiMicroBlog::createFriendship( Choqok::Account *theAccount, const Q
kDebug();
TwitterApiAccount* account = qobject_cast<TwitterApiAccount*>(theAccount);
KUrl url = account->apiUrl();
url.addPath( "/friendships/create/"+ username +".xml" );
url.addPath( "/friendships/create/"+ username +".json" );
kDebug()<<url;
KIO::StoredTransferJob *job = KIO::storedHttpPost( QByteArray(), url, KIO::HideProgressInfo) ;
......@@ -1261,7 +972,7 @@ void TwitterApiMicroBlog::destroyFriendship( Choqok::Account *theAccount, const
kDebug();
TwitterApiAccount* account = qobject_cast<TwitterApiAccount*>(theAccount);
KUrl url = account->apiUrl();
url.addPath( "/friendships/destroy/" + username + ".xml" );
url.addPath( "/friendships/destroy/" + username + ".json" );
kDebug()<<url;
KIO::StoredTransferJob *job = KIO::storedHttpPost(QByteArray(), url, KIO::HideProgressInfo) ;
......@@ -1319,7 +1030,7 @@ void TwitterApiMicroBlog::blockUser( Choqok::Account *theAccount, const QString&
kDebug();
TwitterApiAccount* account = qobject_cast<TwitterApiAccount*>(theAccount);
KUrl url = account->apiUrl();
url.addPath( "/blocks/create/"+ username +".xml" );
url.addPath( "/blocks/create/"+ username +".json" );
KIO::StoredTransferJob *job = KIO::storedHttpPost(QByteArray(), url, KIO::HideProgressInfo) ;
if ( !job ) {
......@@ -1361,70 +1072,6 @@ void TwitterApiMicroBlog::slotBlockUser(KJob* job)
//TODO Check for failor!
}
/*Choqok::User* TwitterApiMicroBlog::readUserInfoFromXml(const QByteArray& buffer)
{
QDomDocument doc;
doc.setContent(buffer);
QDomElement root = doc.documentElement();
if ( root.tagName() != "user" ) {
kDebug()<<"There's no user tag in returned document from server! Data is:\n\t"<<buffer;
return 0;
}
QDomNode node = root.firstChild();
Choqok::User *user = new Choqok::User;
QString timeStr;
while( !node.isNull() ){
QDomElement elm = node.toElement();
if(elm.tagName() == "name"){
user->realName = elm.text();
} else if(elm.tagName() == "screen_name"){
user->userName = elm.text();
} else if(elm.tagName() == "location"){
user->location = elm.text();
} else if(elm.tagName() == "description"){
user->description = elm.text();
} else if(elm.tagName() == "profile_image_url"){
user->profileImageUrl = elm.text();
} else if(elm.tagName() == "url") {
user->homePageUrl = elm.text();
} else if(elm.tagName() == "followers_count") {
user->followersCount = elm.text().toUInt();
} else if( elm.tagName() == "protected" ){
if(elm.text() == "true"){
user->isProtected = true;
}
}
node = node.nextSibling();
}
return user;
}*/
/*QString TwitterApiMicroBlog::checkXmlForError(const QByteArray& buffer)
{
QDomDocument doc;
doc.setContent(buffer);
QDomElement root = doc.documentElement();
if( root.tagName() == "hash" ){
QDomNode node = root.firstChild();
QString errorMessage;
QString request;
while( !node.isNull() ){
QDomElement elm = node.toElement();
if(elm.tagName() == "error"){
errorMessage = elm.text();
} else if(elm.tagName() == "request"){
request = elm.text();
}
node = node.nextSibling();
}
kError()<<"Error at request "<<request<<" : "<<errorMessage;
return errorMessage;
} else {
return QString();
}
}*/
///===================================================================
QJson::Parser* TwitterApiMicroBlog::jsonParser()
......
......@@ -209,25 +209,6 @@ protected:
void setRepeatedOfInfo(Choqok::Post* post, Choqok::Post* repeatedPost);
///==============================================
/// XML:
///==============================================
//virtual Choqok::Post * readPostFromDomElement( Choqok::Account* theAccount,
// const QDomElement& root, Choqok::Post* post );
//virtual Choqok::Post *readPostFromDomNode(Choqok::Account* theAccount,
// QDomNode node, Choqok::Post* post);
//virtual Choqok::Post * readPostFromXml( Choqok::Account* theAccount,
// const QByteArray& buffer, Choqok::Post* post );
//virtual QList<Choqok::Post*> readTimelineFromXml( Choqok::Account* theAccount, const QByteArray& buffer );
//virtual Choqok::Post * readDMessageFromXml (Choqok::Account *theAccount, const QByteArray &buffer );
//virtual Choqok::Post * readDMessageFromDomElement (Choqok::Account *theAccount, const QDomElement& root );
//virtual QList<Choqok::Post*> readDMessagesFromXml (Choqok::Account *theAccount, const QByteArray &buffer );
//virtual QStringList readUsersScreenNameFromXml( Choqok::Account *theAccount, const QByteArray & buffer );
//virtual Choqok::User *readUserInfoFromXml( const QByteArray &buffer );
/**
Checks xml returned from server for error, and return error string, Or an empty string if nothing found!
*/
//virtual QString checkXmlForError(const QByteArray &buffer);
///===============================================
/// JSON:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment