2016-09-22 23:21:20 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Morgan McMillian <gilag@monkeystew.com>
|
|
|
|
*
|
|
|
|
* This file is apart of the Goober application, a client for pnut.io
|
|
|
|
*
|
|
|
|
* 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 3 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PNUT_H_
|
|
|
|
#define PNUT_H_
|
|
|
|
|
|
|
|
#include <kqoauthrequest.h>
|
|
|
|
#include <kqoauthmanager.h>
|
|
|
|
#include <QSettings>
|
|
|
|
|
|
|
|
class KQOauthManager;
|
|
|
|
class KQOauthRequest;
|
|
|
|
class Pnut: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
Q_PROPERTY(int sinceId READ sinceId WRITE setSinceId)
|
|
|
|
Q_PROPERTY(int beforeId READ beforeId WRITE setBeforeId)
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum StatusCode {
|
|
|
|
OK = 200,
|
|
|
|
CREATED = 201,
|
|
|
|
NO_CONTENT = 204,
|
|
|
|
FOUND = 302,
|
|
|
|
BAD_REQUEST = 400,
|
|
|
|
UNAUTHORIZED = 401,
|
|
|
|
FORBIDDEN = 403,
|
|
|
|
NOT_FOUND = 404,
|
|
|
|
METHOD_NOT_ALLOWED = 405,
|
|
|
|
TOO_MANY_REQUESTS = 429,
|
|
|
|
INTERNAL_SERVER_ERROR = 500,
|
|
|
|
INSUFFICIENT_STORAGE = 507
|
|
|
|
};
|
|
|
|
|
|
|
|
enum RequestType {
|
|
|
|
STREAM_NEWER = 0,
|
|
|
|
STREAM_OLDER = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
Q_ENUMS(RequestType)
|
|
|
|
|
|
|
|
Pnut();
|
|
|
|
virtual ~Pnut();
|
|
|
|
|
|
|
|
int sinceId() const;
|
|
|
|
void setSinceId(const int &id);
|
|
|
|
int beforeId() const;
|
|
|
|
void setBeforeId(const int &id);
|
|
|
|
|
|
|
|
Q_INVOKABLE void authorize();
|
|
|
|
Q_INVOKABLE void getStream(QString endpoint, Pnut::RequestType rtype);
|
|
|
|
Q_INVOKABLE void sendPost(QString text);
|
|
|
|
Q_INVOKABLE void sendReply(QString text, int pid);
|
2016-09-23 19:33:16 +00:00
|
|
|
Q_INVOKABLE void getUser(QString uid);
|
2016-10-21 13:09:34 +00:00
|
|
|
Q_INVOKABLE void followUser(QString uid);
|
|
|
|
Q_INVOKABLE void unfollowUser(QString uid);
|
2016-10-21 15:16:10 +00:00
|
|
|
Q_INVOKABLE void blockUser(QString uid);
|
|
|
|
Q_INVOKABLE void unblockUser(QString uid);
|
|
|
|
Q_INVOKABLE void muteUser(QString uid);
|
|
|
|
Q_INVOKABLE void unmuteUser(QString uid);
|
2016-09-23 19:33:16 +00:00
|
|
|
Q_INVOKABLE void getUserInfo();
|
2016-09-24 15:13:45 +00:00
|
|
|
Q_INVOKABLE void getThread(QString pid);
|
|
|
|
Q_INVOKABLE void setBookmark(QString pid);
|
|
|
|
Q_INVOKABLE void deleteBookmark(QString pid);
|
2016-10-01 13:40:48 +00:00
|
|
|
Q_INVOKABLE void repost(QString pid);
|
|
|
|
Q_INVOKABLE void deleteRepost(QString pid);
|
2016-10-01 18:18:40 +00:00
|
|
|
Q_INVOKABLE void logout();
|
2016-09-22 23:21:20 +00:00
|
|
|
|
|
|
|
public slots:
|
2016-09-23 20:43:12 +00:00
|
|
|
void onRequestReady(QByteArray data);
|
2016-09-22 23:21:20 +00:00
|
|
|
void onAuthorizedRequestReady(QByteArray data, int id);
|
|
|
|
void onAuthorizationReceived(QString token, QString verifier);
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
2016-10-01 18:18:40 +00:00
|
|
|
void authorizationRequired();
|
2016-09-22 23:21:20 +00:00
|
|
|
void authorizationReceived();
|
|
|
|
void streamReceived(QVariantList stream, Pnut::RequestType rtype);
|
2016-09-24 15:13:45 +00:00
|
|
|
void threadReceived(QVariantList thread);
|
2016-10-21 15:16:10 +00:00
|
|
|
void followSuccess(QVariantMap user);
|
|
|
|
void unfollowSuccess(QVariantMap user);
|
|
|
|
void blockSuccess(QVariantMap user);
|
|
|
|
void unblockSuccess(QVariantMap user);
|
|
|
|
void muteSuccess(QVariantMap user);
|
|
|
|
void unmuteSuccess(QVariantMap user);
|
2016-09-22 23:21:20 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static const QString PNUT_API_ROOT;
|
|
|
|
static const QString PNUT_AUTH_URL;
|
|
|
|
static const QString PNUT_USERS_URL;
|
|
|
|
|
|
|
|
QSettings *m_appSettings;
|
|
|
|
KQOAuthManager *oauthManager;
|
|
|
|
KQOAuthRequest *oauthRequest;
|
|
|
|
|
|
|
|
int before_id;
|
|
|
|
int since_id;
|
|
|
|
int req_id;
|
|
|
|
QMap<int,QString> req_map;
|
|
|
|
QMap<int,Pnut::RequestType> rtype_map;
|
2016-09-23 20:43:12 +00:00
|
|
|
bool authInProgress;
|
2016-09-22 23:21:20 +00:00
|
|
|
|
|
|
|
void getRequest(QUrl url, KQOAuthParameters parameters, int id);
|
|
|
|
void postRequest(QUrl url, KQOAuthParameters parameters, int id, QByteArray data);
|
2016-09-24 15:13:45 +00:00
|
|
|
void putRequest(QUrl url, KQOAuthParameters parameters, int id);
|
|
|
|
void deleteRequest(QUrl url, KQOAuthParameters parameters, int id);
|
2016-09-22 23:21:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* PNUT_H_ */
|