File indexing completed on 2024-12-22 04:45:18

0001 /*
0002    SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "listcommandsjob.h"
0008 #include "restapimethod.h"
0009 #include "rocketchatqtrestapi_debug.h"
0010 #include <QJsonDocument>
0011 #include <QJsonObject>
0012 #include <QNetworkReply>
0013 using namespace RocketChatRestApi;
0014 ListCommandsJob::ListCommandsJob(QObject *parent)
0015     : RestApiAbstractJob(parent)
0016 {
0017 }
0018 
0019 ListCommandsJob::~ListCommandsJob() = default;
0020 
0021 bool ListCommandsJob::requireHttpAuthentication() const
0022 {
0023     return true;
0024 }
0025 
0026 bool ListCommandsJob::start()
0027 {
0028     if (!canStart()) {
0029         qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start owninfo job";
0030         deleteLater();
0031         return false;
0032     }
0033     submitGetRequest();
0034 
0035     addStartRestApiInfo(QByteArrayLiteral("ListCommandsJob: Ask info about me"));
0036     return true;
0037 }
0038 
0039 void ListCommandsJob::onGetRequestResponse(const QString &replyErrorString, const QJsonDocument &replyJson)
0040 {
0041     const QJsonObject replyObject = replyJson.object();
0042     if (replyObject[QLatin1String("success")].toBool()) {
0043         addLoggerInfo(QByteArrayLiteral("ListCommandsJob: success: ") + replyJson.toJson(QJsonDocument::Indented));
0044         Q_EMIT listCommandsDone(replyObject);
0045     } else {
0046         emitFailedMessage(replyErrorString, replyObject);
0047         addLoggerWarning(QByteArrayLiteral("ListCommandsJob: problem: ") + replyJson.toJson(QJsonDocument::Indented));
0048     }
0049 }
0050 
0051 QNetworkRequest ListCommandsJob::request() const
0052 {
0053     const QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::CommandsList);
0054     QNetworkRequest request(url);
0055     addAuthRawHeader(request);
0056     addRequestAttribute(request, false);
0057 
0058     return request;
0059 }
0060 
0061 #include "moc_listcommandsjob.cpp"