Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added class for fetching favorites.

  • Loading branch information...
commit 3058e9f5a59c2bf0f4192cac85d4bc25e0c26d9b 1 parent 68fc51e
@minimoog authored
Showing with 138 additions and 2 deletions.
  1. +83 −0 src/qtweetfavorites.cpp
  2. +51 −0 src/qtweetfavorites.h
  3. +4 −2 src/src.pro
View
83 src/qtweetfavorites.cpp
@@ -0,0 +1,83 @@
+/* Copyright (c) 2010, Antonie Jovanoski
+ *
+ * All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Contact e-mail: Antonie Jovanoski <minimoog77_at_gmail.com>
+ */
+
+#include <QNetworkRequest>
+#include <QNetworkReply>
+#include "qtweetfavorites.h"
+#include "qtweetstatus.h"
+
+QTweetFavorites::QTweetFavorites(QObject *parent) :
+ QTweetNetBase(parent)
+{
+}
+
+QTweetFavorites::QTweetFavorites(OAuthTwitter *oauthTwitter, QObject *parent) :
+ QTweetNetBase(oauthTwitter, parent)
+{
+}
+
+/*!
+ \param id The ID or screen name of the user for whom to request a list of favorite statuses. 0 for authenticated user
+ \param page Specifies the page of results to retrieve.
+ \param includeEntities When set to true, each tweet will include a node called "entities,".
+ */
+void QTweetFavorites::fetch(qint64 id, int page, bool includeEntities)
+{
+ Q_ASSERT(oauthTwitter() != 0);
+
+ QUrl url;
+
+ if (id) {
+ url.setUrl(QString("http://api.twitter.com/1/favorites/%1.json").arg(id));
+ } else {
+ url.setUrl("http://api.twitter.com/1/favorites.json");
+ }
+
+ if (page)
+ url.addQueryItem("page", QString::number(page));
+
+ if (includeEntities)
+ url.addQueryItem("include_entities", "true");
+
+ QNetworkRequest req(url);
+
+ QByteArray oauthHeader = oauthTwitter()->generateAuthorizationHeader(url, OAuth::GET);
+ req.setRawHeader(AUTH_HEADER, oauthHeader);
+
+ QNetworkReply *reply = oauthTwitter()->networkAccessManager()->get(req);
+ connect(reply, SIGNAL(finished()), this, SLOT(reply()));
+ connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(error()));
+}
+
+void QTweetFavorites::parsingJsonFinished(const QVariant &json, bool ok, const QString &errorMsg)
+{
+ if (ok) {
+ QList<QTweetStatus> statuses = variantToStatusList(json);
+
+ emit parsedFavorites(statuses);
+ } else {
+ qDebug() << "QTweetFavorites JSON parser error: " << errorMsg;
+ }
+}
+
+void QTweetFavorites::error()
+{
+ // ### TODO
+}
View
51 src/qtweetfavorites.h
@@ -0,0 +1,51 @@
+/* Copyright (c) 2010, Antonie Jovanoski
+ *
+ * All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Contact e-mail: Antonie Jovanoski <minimoog77_at_gmail.com>
+ */
+
+#ifndef QTWEETFAVORITES_H
+#define QTWEETFAVORITES_H
+
+#include "qtweetnetbase.h"
+
+/*!
+ Fetches favorite statuses for the authenticating user or
+ user specified by the ID parameter
+ */
+class QTWEETLIBSHARED_EXPORT QTweetFavorites : public QTweetNetBase
+{
+ Q_OBJECT
+public:
+ QTweetFavorites(QObject *parent = 0);
+ QTweetFavorites(OAuthTwitter *oauthTwitter, QObject *parent = 0);
+ void fetch(qint64 id = 0,
+ int page = 0,
+ bool includeEntities = false);
+
+signals:
+ /*! Emits list of favorited statuses */
+ void parsedFavorites(const QList<QTweetStatus>& favorites);
+
+protected slots:
+ void parsingJsonFinished(const QVariant &json, bool ok, const QString &errorMsg);
+
+private slots:
+ void error();
+};
+
+#endif // QTWEETFAVORITES_H
View
6 src/src.pro
@@ -64,7 +64,8 @@ HEADERS += \
qtweetfriendsid.h \
qtweetfollowersid.h \
qtweetaccountverifycredentials.h \
- qtweetaccountratelimitstatus.h
+ qtweetaccountratelimitstatus.h \
+ qtweetfavorites.h
SOURCES += \
oauth.cpp \
@@ -116,4 +117,5 @@ SOURCES += \
qtweetfriendsid.cpp \
qtweetfollowersid.cpp \
qtweetaccountverifycredentials.cpp \
- qtweetaccountratelimitstatus.cpp
+ qtweetaccountratelimitstatus.cpp \
+ qtweetfavorites.cpp
Please sign in to comment.
Something went wrong with that request. Please try again.