diff --git a/src/rocketchatrestapi-qt5/restapiabstractjob.cpp b/src/rocketchatrestapi-qt5/restapiabstractjob.cpp index 337e5b5d..986116b0 100644 --- a/src/rocketchatrestapi-qt5/restapiabstractjob.cpp +++ b/src/rocketchatrestapi-qt5/restapiabstractjob.cpp @@ -1,170 +1,177 @@ /* Copyright (c) 2018-2019 Montel Laurent This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "restapiabstractjob.h" #include "rocketchatqtrestapi_debug.h" #include "abstractlogger.h" #include using namespace RocketChatRestApi; RestApiAbstractJob::RestApiAbstractJob(QObject *parent) : QObject(parent) { } QNetworkAccessManager *RestApiAbstractJob::networkAccessManager() const { return mNetworkAccessManager; } void RestApiAbstractJob::setNetworkAccessManager(QNetworkAccessManager *networkAccessManager) { mNetworkAccessManager = networkAccessManager; } RocketChatRestApi::RestApiMethod *RestApiAbstractJob::restApiMethod() const { return mRestApiMethod; } void RestApiAbstractJob::setRestApiMethod(RocketChatRestApi::RestApiMethod *restApiMethod) { mRestApiMethod = restApiMethod; } QString RestApiAbstractJob::authToken() const { return mAuthToken; } void RestApiAbstractJob::setAuthToken(const QString &authToken) { mAuthToken = authToken; } QString RestApiAbstractJob::userId() const { return mUserId; } void RestApiAbstractJob::setUserId(const QString &userId) { mUserId = userId; } bool RestApiAbstractJob::hasAuthenticationValue() const { return !mAuthToken.isEmpty() && !mUserId.isEmpty(); } bool RestApiAbstractJob::hasQueryParameterSupport() const { return false; } bool RestApiAbstractJob::canStart() const { if (!mNetworkAccessManager) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Network manager not defined"; return false; } if (!mRestApiMethod) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "RestaApiMethod not defined"; return false; } if (requireHttpAuthentication() && !hasAuthenticationValue()) { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Auth settings is empty. It's a bug"; return false; } return true; } void RestApiAbstractJob::addAuthRawHeader(QNetworkRequest &request) const { request.setRawHeader(QByteArrayLiteral("X-Auth-Token"), mAuthToken.toLocal8Bit()); request.setRawHeader(QByteArrayLiteral("X-User-Id"), mUserId.toLocal8Bit()); } QueryParameters RestApiAbstractJob::queryParameters() const { return mQueryParameters; } void RestApiAbstractJob::setQueryParameters(const QueryParameters &queryParameters) { mQueryParameters = queryParameters; } +void RestApiAbstractJob::addQueryParameter(QUrlQuery &urlQuery) +{ + if (hasQueryParameterSupport()) { + //TODO + } +} + RocketChatRestApi::AbstractLogger *RestApiAbstractJob::restApiLogger() const { return mRestApiLogger; } void RestApiAbstractJob::setRestApiLogger(RocketChatRestApi::AbstractLogger *ruqolaLogger) { mRestApiLogger = ruqolaLogger; } void RestApiAbstractJob::addLoggerInfo(const QByteArray &str) { if (mRestApiLogger) { mRestApiLogger->dataSent("RESTAPI: " + str); } else { qCDebug(ROCKETCHATQTRESTAPI_LOG) << "RESTAPI: " << str; } } void RestApiAbstractJob::addLoggerWarning(const QByteArray &str) { if (mRestApiLogger) { mRestApiLogger->dataSent("WARNING RESTAPI: " + str); } else { qCWarning(ROCKETCHATQTRESTAPI_LOG) << "RESTAPI: " << str; } } QueryParameters::QueryParameters() { } int QueryParameters::offset() const { return mOffset; } void QueryParameters::setOffset(int offset) { mOffset = offset; } int QueryParameters::count() const { return mCount; } void QueryParameters::setCount(int count) { mCount = count; } bool QueryParameters::isValid() const { return (mCount >= 0) || (mOffset >= 0); } diff --git a/src/rocketchatrestapi-qt5/restapiabstractjob.h b/src/rocketchatrestapi-qt5/restapiabstractjob.h index 7ecd5f7e..fb1ab7d9 100644 --- a/src/rocketchatrestapi-qt5/restapiabstractjob.h +++ b/src/rocketchatrestapi-qt5/restapiabstractjob.h @@ -1,98 +1,100 @@ /* Copyright (c) 2018-2019 Montel Laurent This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef RESTAPIABSTRACTJOB_H #define RESTAPIABSTRACTJOB_H #include #include #include "librestapi_private_export.h" class QNetworkAccessManager; namespace RocketChatRestApi { class RestApiMethod; class AbstractLogger; class LIBROCKETCHATRESTAPI_QT5_TESTS_EXPORT QueryParameters { public: QueryParameters(); Q_REQUIRED_RESULT int offset() const; void setOffset(int offset); Q_REQUIRED_RESULT int count() const; void setCount(int count); bool isValid() const; private: int mOffset = -1; int mCount = -1; }; class LIBROCKETCHATRESTAPI_QT5_TESTS_EXPORT RestApiAbstractJob : public QObject { Q_OBJECT public: explicit RestApiAbstractJob(QObject *parent = nullptr); Q_REQUIRED_RESULT QNetworkAccessManager *networkAccessManager() const; void setNetworkAccessManager(QNetworkAccessManager *networkAccessManager); Q_REQUIRED_RESULT RocketChatRestApi::RestApiMethod *restApiMethod() const; void setRestApiMethod(RocketChatRestApi::RestApiMethod *restApiMethod); Q_REQUIRED_RESULT QString authToken() const; void setAuthToken(const QString &authToken); Q_REQUIRED_RESULT QString userId() const; void setUserId(const QString &userId); Q_REQUIRED_RESULT bool hasAuthenticationValue() const; virtual bool start() = 0; virtual bool requireHttpAuthentication() const = 0; virtual bool hasQueryParameterSupport() const; RocketChatRestApi::AbstractLogger *restApiLogger() const; void setRestApiLogger(RocketChatRestApi::AbstractLogger *restApiLogger); void addLoggerInfo(const QByteArray &str); void addLoggerWarning(const QByteArray &str); Q_REQUIRED_RESULT virtual bool canStart() const; virtual QNetworkRequest request() const = 0; Q_REQUIRED_RESULT QueryParameters queryParameters() const; void setQueryParameters(const QueryParameters &queryParameters); + void addQueryParameter(QUrlQuery &urlQuery); + protected: Q_DISABLE_COPY(RestApiAbstractJob) void addAuthRawHeader(QNetworkRequest &request) const; QueryParameters mQueryParameters; QString mAuthToken; QString mUserId; QNetworkAccessManager *mNetworkAccessManager = nullptr; RocketChatRestApi::RestApiMethod *mRestApiMethod = nullptr; RocketChatRestApi::AbstractLogger *mRestApiLogger = nullptr; }; } #endif // RESTAPIABSTRACTJOB_H