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

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