aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/wellknown.cpp
blob: d42534a031082a6740724b40993be7388a445675 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/******************************************************************************
 * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
 */

#include "wellknown.h"

#include "converters.h"

#include <QtCore/QStringBuilder>

using namespace QMatrixClient;

static const auto basePath = QStringLiteral("/.well-known");

class GetWellknownJob::Private
{
    public:
        HomeserverInformation homeserver;
        Omittable<IdentityServerInformation> identityServer;
};

QUrl GetWellknownJob::makeRequestUrl(QUrl baseUrl)
{
    return BaseJob::makeRequestUrl(std::move(baseUrl),
            basePath % "/matrix/client");
}

static const auto GetWellknownJobName = QStringLiteral("GetWellknownJob");

GetWellknownJob::GetWellknownJob()
    : BaseJob(HttpVerb::Get, GetWellknownJobName,
        basePath % "/matrix/client", false)
    , d(new Private)
{
}

GetWellknownJob::~GetWellknownJob() = default;

const HomeserverInformation& GetWellknownJob::homeserver() const
{
    return d->homeserver;
}

const Omittable<IdentityServerInformation>& GetWellknownJob::identityServer() const
{
    return d->identityServer;
}

BaseJob::Status GetWellknownJob::parseJson(const QJsonDocument& data)
{
    auto json = data.object();
    if (!json.contains("m.homeserver"_ls))
        return { JsonParseError,
            "The key 'm.homeserver' not found in the response" };
    d->homeserver = fromJson<HomeserverInformation>(json.value("m.homeserver"_ls));
    d->identityServer = fromJson<IdentityServerInformation>(json.value("m.identity_server"_ls));
    return Success;
}