added post stuff
This commit is contained in:
parent
7dbf05e2e1
commit
6146758f59
4 changed files with 29 additions and 17 deletions
2
post.cpp
2
post.cpp
|
@ -7,7 +7,7 @@ Post::Post(QObject *parent) : QObject(parent),
|
|||
|
||||
}
|
||||
|
||||
Post::Post(QJsonDocument post, QObject *parent) : QObject(parent),
|
||||
Post::Post(QJsonObject post, QObject *parent) : QObject(parent),
|
||||
mStarred(false)
|
||||
{
|
||||
qDebug() << post;
|
||||
|
|
4
post.h
4
post.h
|
@ -4,7 +4,7 @@
|
|||
#include <QObject>
|
||||
#include <QUrl>
|
||||
#include <QDate>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
class Post : public QObject
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ class Post : public QObject
|
|||
|
||||
public:
|
||||
Post(QObject *parent = 0);
|
||||
Post(QJsonDocument post, QObject *parent = 0);
|
||||
Post(QJsonObject post, QObject *parent = 0);
|
||||
~Post();
|
||||
QString title() const { return mTitle; }
|
||||
QString author() const { return mAuthor; }
|
||||
|
|
|
@ -3,17 +3,26 @@
|
|||
#include <QJsonObject>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QJsonArray>
|
||||
|
||||
TinyTinyRSS::TinyTinyRSS(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
mNetworkManager = new QNetworkAccessManager(this);
|
||||
mPosts = QList<Post*>();
|
||||
}
|
||||
|
||||
TinyTinyRSS::~TinyTinyRSS()
|
||||
{
|
||||
mPosts.empty();
|
||||
delete mNetworkManager;
|
||||
}
|
||||
|
||||
void TinyTinyRSS::initialize(const QString serverUrl, const QString sessionId)
|
||||
{
|
||||
mServerUrl = serverUrl;
|
||||
mSessionId = sessionId;
|
||||
reload();
|
||||
}
|
||||
|
||||
void TinyTinyRSS::reload()
|
||||
|
@ -28,11 +37,6 @@ void TinyTinyRSS::reload()
|
|||
doOperation("getHeadlines", opts);
|
||||
}
|
||||
|
||||
TinyTinyRSS::~TinyTinyRSS()
|
||||
{
|
||||
delete mNetworkManager;
|
||||
}
|
||||
|
||||
void TinyTinyRSS::doOperation(QString operation, QVariantMap opts)
|
||||
{
|
||||
QVariantMap options;
|
||||
|
@ -49,9 +53,9 @@ void TinyTinyRSS::doOperation(QString operation, QVariantMap opts)
|
|||
QJsonDocument json = QJsonDocument(jsonobj);
|
||||
|
||||
QNetworkRequest request(mServerUrl);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
|
||||
QNetworkReply *reply = mNetworkManager->post(request, json.toBinaryData());
|
||||
QNetworkReply *reply = mNetworkManager->post(request, json.toJson());
|
||||
connect(reply, SIGNAL(finished()), this, SLOT(reply()));
|
||||
}
|
||||
|
||||
|
@ -61,9 +65,18 @@ void TinyTinyRSS::reply()
|
|||
|
||||
if (reply) {
|
||||
if (reply->error() == QNetworkReply::NoError) {
|
||||
//QJsonDocument json = QJsonDocument::fromBinaryData(reply->readAll());
|
||||
//mSessionId = json.toVariant().toMap().value("session_id");
|
||||
//emit sessionIdChanged(mSessionId);
|
||||
QString jsonString = QString(reply->readAll());
|
||||
QJsonDocument json = QJsonDocument::fromJson(jsonString.toUtf8());
|
||||
|
||||
QJsonArray posts = json.object().value("content").toArray();
|
||||
for(int i = 0; posts.count(); i++)
|
||||
{
|
||||
QJsonObject postJson = posts.at(i).toObject();
|
||||
Post *post = new Post(postJson, this);
|
||||
mPosts.append(post);
|
||||
}
|
||||
|
||||
emit postsChanged(mPosts);
|
||||
} else {
|
||||
int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
//do some error management
|
||||
|
|
|
@ -39,10 +39,9 @@ void TinyTinyRSSLogin::reply()
|
|||
|
||||
if (reply) {
|
||||
if (reply->error() == QNetworkReply::NoError) {
|
||||
QJsonDocument jdoc = QJsonDocument::fromBinaryData(reply->readAll());
|
||||
qDebug() << jdoc;
|
||||
//mSessionId = json.toVariant().toMap().value("session_id").toString();
|
||||
//qDebug() << "sessionId: " << mSessionId;
|
||||
QString jsonString = QString(reply->readAll());
|
||||
QJsonDocument json = QJsonDocument::fromJson(jsonString.toUtf8());
|
||||
mSessionId = json.object().value("content").toObject().value("session_id").toString();
|
||||
emit sessionIdChanged(mSessionId);
|
||||
} else {
|
||||
int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue