This repository has been archived on 2023-11-19. You can view files and clone it, but cannot push or open issues or pull requests.
goober-bb10/src/Pnut.h

130 lines
4 KiB
C
Raw Normal View History

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);
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);
Q_INVOKABLE void blockUser(QString uid);
Q_INVOKABLE void unblockUser(QString uid);
Q_INVOKABLE void muteUser(QString uid);
Q_INVOKABLE void unmuteUser(QString uid);
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);
Q_INVOKABLE void repost(QString pid);
Q_INVOKABLE void deleteRepost(QString pid);
2016-10-01 18:18:40 +00:00
Q_INVOKABLE void logout();
Q_INVOKABLE void deletePost(QString pid);
2016-10-30 17:53:58 +00:00
Q_INVOKABLE void getPost(QString pid);
2016-09-22 23:21:20 +00:00
public slots:
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);
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-10-30 17:53:58 +00:00
void postReceived(QVariantMap post);
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;
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_ */