File indexing completed on 2024-06-02 05:07:14

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 "listoauthappsjob.h"
0008 #include "restapimethod.h"
0009 #include "rocketchatqtrestapi_debug.h"
0010 #include <QJsonDocument>
0011 #include <QJsonObject>
0012 #include <QNetworkReply>
0013 using namespace RocketChatRestApi;
0014 ListOauthAppsJob::ListOauthAppsJob(QObject *parent)
0015     : RestApiAbstractJob(parent)
0016 {
0017 }
0018 
0019 ListOauthAppsJob::~ListOauthAppsJob() = default;
0020 
0021 bool ListOauthAppsJob::requireHttpAuthentication() const
0022 {
0023     return true;
0024 }
0025 
0026 bool ListOauthAppsJob::start()
0027 {
0028     if (!canStart()) {
0029         qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start ListOauthAppsJob";
0030         deleteLater();
0031         return false;
0032     }
0033     submitGetRequest();
0034 
0035     addStartRestApiInfo(QByteArrayLiteral("ListOauthAppsJob: Ask settings oauth"));
0036     return true;
0037 }
0038 
0039 void ListOauthAppsJob::onGetRequestResponse(const QString &replyErrorString, const QJsonDocument &replyJson)
0040 {
0041     const QJsonObject replyObject = replyJson.object();
0042 
0043     if (replyObject[QLatin1String("success")].toBool()) {
0044         addLoggerInfo(QByteArrayLiteral("ListOauthAppsJob: success: ") + replyJson.toJson(QJsonDocument::Indented));
0045         Q_EMIT listOauthDone(replyObject);
0046     } else {
0047         emitFailedMessage(replyErrorString, replyObject);
0048         addLoggerWarning(QByteArrayLiteral("ListOauthAppsJob: Problem: ") + replyJson.toJson(QJsonDocument::Indented));
0049     }
0050 }
0051 
0052 QNetworkRequest ListOauthAppsJob::request() const
0053 {
0054     const QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::OauthAppsList);
0055     QNetworkRequest request(url);
0056     addAuthRawHeader(request);
0057     addRequestAttribute(request, false);
0058 
0059     return request;
0060 }
0061 
0062 #include "moc_listoauthappsjob.cpp"