File indexing completed on 2024-05-12 16:59:03

0001 /*
0002     SPDX-FileCopyrightText: 2019-2021 Harald Sitter <sitter@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "productclient.h"
0008 
0009 #include <QMetaMethod>
0010 #include <QMetaObject>
0011 #include <QMetaType>
0012 #include <QSharedPointer>
0013 
0014 namespace Bugzilla
0015 {
0016 Product::Ptr ProductClient::get(KJob *kjob)
0017 {
0018     auto job = qobject_cast<APIJob *>(kjob);
0019 
0020     const QJsonArray productsArray = job->object().value(QLatin1String("products")).toArray();
0021     if (productsArray.isEmpty()) {
0022         throw Bugzilla::RuntimeException(QStringLiteral("Failed to resolve bugzilla product"));
0023     }
0024     Q_ASSERT(productsArray.size() == 1);
0025 
0026     auto obj = productsArray.at(0).toObject().toVariantHash();
0027 
0028     return Product::Ptr(new Product(obj, m_connection));
0029 }
0030 
0031 KJob *ProductClient::get(const QString &idOrName)
0032 {
0033     return m_connection.get(QStringLiteral("/product/%1").arg(idOrName));
0034 }
0035 
0036 } // namespace Bugzilla