blob: c95f7f4ef8c8c66ee97ceedec0380fa720e2d0c6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "library.h"
#include "request.h"
#include <utils/qtcassert.h>
namespace CompilerExplorer::Api {
QFuture<Libraries> libraries(const Config &config, const QString &languageId)
{
QTC_ASSERT(!languageId.isEmpty(),
return QtFuture::makeExceptionalFuture<Libraries>(
std::make_exception_ptr(std::runtime_error("Language ID is empty."))));
const QUrl url = config.url({"api/libraries", languageId});
return jsonRequest<Libraries>(config.networkManager, url, [](const QJsonDocument &doc) {
const QJsonArray libraries = doc.array();
Libraries result;
for (const auto &library : libraries) {
QJsonObject obj = library.toObject();
Library l;
l.id = obj["id"].toString();
l.name = obj["name"].toString();
l.url = QUrl::fromUserInput(obj["url"].toString());
const QJsonArray versions = obj["versions"].toArray();
for (const auto &version : versions) {
l.versions.append({
version.toObject()["version"].toString(),
version.toObject()["id"].toString(),
});
}
result.append(l);
}
return result;
});
}
} // namespace CompilerExplorer::Api
|