/* * Copyright (C) 2016 Morgan McMillian * * 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 . */ #ifndef PNUT_H_ #define PNUT_H_ #include #include #include 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); 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(); 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); Q_INVOKABLE void logout(); public slots: void onRequestReady(QByteArray data); void onAuthorizedRequestReady(QByteArray data, int id); void onAuthorizationReceived(QString token, QString verifier); Q_SIGNALS: void authorizationRequired(); void authorizationReceived(); void streamReceived(QVariantList stream, Pnut::RequestType rtype); 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); 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 req_map; QMap rtype_map; bool authInProgress; void getRequest(QUrl url, KQOAuthParameters parameters, int id); void postRequest(QUrl url, KQOAuthParameters parameters, int id, QByteArray data); void putRequest(QUrl url, KQOAuthParameters parameters, int id); void deleteRequest(QUrl url, KQOAuthParameters parameters, int id); }; #endif /* PNUT_H_ */