/* * 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); public slots: void onAuthorizedRequestReady(QByteArray data, int id); void onAuthorizationReceived(QString token, QString verifier); Q_SIGNALS: void authorizationReceived(); void streamReceived(QVariantList stream, Pnut::RequestType rtype); 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; void getRequest(QUrl url, KQOAuthParameters parameters, int id); void postRequest(QUrl url, KQOAuthParameters parameters, int id, QByteArray data); }; #endif /* PNUT_H_ */