aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/{{base}}.cpp.mustache
blob: 6cbd1b6553a08a11856d3eebbc1a99a67439595b (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
{{>preamble}}
#include "{{filenameBase}}.h"
{{^models}}
#include "converters.h"{{/models}}
{{#operations}}
{{#producesNonJson?}}
#include <QtNetwork/QNetworkReply>
{{/producesNonJson?}}
#include <QtCore/QStringBuilder>
{{/operations}}
using namespace Quotient;
{{#models.model}}
    {{#in?}}
void JsonObjectConverter<{{qualifiedName}}>::dumpTo(QJsonObject& jo, const {{qualifiedName}}& pod)
{
{{#propertyMap
}}    fillJson(jo, pod.{{nameCamelCase}});
{{/propertyMap}}{{#parents
}}    fillJson<{{name}}>(jo, pod);
{{/parents}}{{#vars
}}    addParam<{{^required?}}IfNotEmpty{{/required?}}>(jo, QStringLiteral("{{baseName}}"), pod.{{nameCamelCase}});
{{/vars}}
}
    {{/in?}}{{#out?}}
void JsonObjectConverter<{{qualifiedName}}>::fillFrom({{>maybeCrefJsonObject}} jo, {{qualifiedName}}& result)
{
{{#parents
}}    fillFromJson<{{qualifiedName}}>(jo, result);
{{/parents}}{{#vars
}}    fromJson(jo.{{>takeOrValue}}("{{baseName}}"_ls), result.{{nameCamelCase}});
{{/vars}}{{#propertyMap
}}    fromJson(jo, result.{{nameCamelCase}});
{{/propertyMap}}
}
    {{/out?}}
{{/models.model}}
{{#operations}}
static const auto basePath = QStringLiteral("{{basePathWithoutHost}}");
    {{#operation}}{{#models}}
// Converters
namespace Quotient
{
        {{#model}}
template <> struct JsonObjectConverter<{{qualifiedName}}>
{
            {{#in?
}}    static void dumpTo(QJsonObject& jo, const {{qualifiedName}}& pod)
    {
{{#propertyMap
}}        fillJson(jo, pod.{{nameCamelCase}});
{{/propertyMap}}{{#parents
}}        fillJson<{{name}}>(jo, pod);
{{/parents}}{{#vars
}}        addParam<{{^required?}}IfNotEmpty{{/required?}}>(jo, QStringLiteral("{{baseName}}"), pod.{{nameCamelCase}});
{{/vars}}
    }
            {{/in?}}{{#out?
}}    static void fillFrom({{>maybeCrefJsonObject}} jo, {{qualifiedName}}& result)
    {
{{#parents
}}        fillFromJson<{{qualifiedName}}{{!of the parent!}}>(jo, result);
{{/parents}}{{#vars
}}        fromJson(jo.{{>takeOrValue}}("{{baseName}}"_ls), result.{{nameCamelCase}});
{{/vars}}{{#propertyMap
}}        fromJson(jo, result.{{nameCamelCase}});
{{/propertyMap}}
    }
            {{/out?}}
};
        {{/model}}
} // namespace QMatrixClient
    {{/models}}
    {{#responses}}{{#normalResponse?}}{{#allProperties?}}
class {{camelCaseOperationId}}Job::Private
{
    public:{{#allProperties}}
        {{>maybeOmittableType}} {{paramName}};{{/allProperties}}
};
    {{/allProperties?}}{{/normalResponse?}}{{/responses}}
    {{#queryParams?}}
BaseJob::Query queryTo{{camelCaseOperationId}}({{#queryParams}}{{>joinedParamDef}}{{/queryParams}})
{
    BaseJob::Query _q;{{#queryParams}}
    addParam<{{^required?}}IfNotEmpty{{/required?}}>(_q, QStringLiteral("{{baseName}}"), {{paramName}});{{/queryParams}}
    return _q;
}
    {{/queryParams?}}
    {{^bodyParams}}
QUrl {{camelCaseOperationId}}Job::makeRequestUrl(QUrl baseUrl{{#allParams?}}, {{#allParams}}{{>joinedParamDef}}{{/allParams}}{{/allParams?}})
{
    return BaseJob::makeRequestUrl(std::move(baseUrl),
            basePath{{#pathParts}} % {{_}}{{/pathParts}}{{#queryParams?}},
            queryTo{{camelCaseOperationId}}({{>passQueryParams}}){{/queryParams?}});
}
    {{/bodyParams}}
static const auto {{camelCaseOperationId}}JobName = QStringLiteral("{{camelCaseOperationId}}Job");

{{camelCaseOperationId}}Job::{{camelCaseOperationId}}Job({{#allParams}}{{>joinedParamDef}}{{/allParams}})
    : BaseJob(HttpVerb::{{#_cap}}{{#_tolower}}{{httpMethod}}{{/_tolower}}{{/_cap}}, {{camelCaseOperationId}}JobName,
        basePath{{#pathParts}} % {{_}}{{/pathParts}}{{#queryParams?}},
        queryTo{{camelCaseOperationId}}({{>passQueryParams}}){{/queryParams?}}{{#skipAuth}}{{#queryParams?}},
        {}{{/queryParams?}}, false{{/skipAuth}}){{#responses}}{{#normalResponse?}}{{#allProperties?}}
    , d(new Private){{/allProperties?}}{{/normalResponse?}}{{/responses}}
{
{{#headerParams?}}{{#headerParams
}}    setRequestHeader("{{baseName}}", {{paramName}}.toLatin1());{{/headerParams}}
{{/headerParams?}}{{#bodyParams?
}}{{#inlineBody
}}    setRequestData(Data({{#consumesNonJson?}}{{nameCamelCase}}{{/consumesNonJson?
                        }}{{^consumesNonJson?}}toJson({{nameCamelCase}}){{/consumesNonJson?}}));
{{/inlineBody}}{{^inlineBody
}}    QJsonObject _data;{{#bodyParams}}
    addParam<{{^required?}}IfNotEmpty{{/required?}}>(_data, QStringLiteral("{{baseName}}"), {{paramName}});{{/bodyParams}}
    setRequestData(_data);
{{/inlineBody}}{{/bodyParams?
}}{{#producesNonJson?
}}    setExpectedContentTypes({ {{#produces}}"{{_}}"{{>cjoin}}{{/produces}} });
{{/producesNonJson?}}
}
    {{#responses}}{{#normalResponse?}}{{#allProperties?}}
{{camelCaseOperationId}}Job::~{{camelCaseOperationId}}Job() = default;
        {{#allProperties}}
{{>qualifiedMaybeCrefType}} {{camelCaseOperationId}}Job::{{paramName}}(){{^moveOnly}} const{{/moveOnly}}
{
    return {{#moveOnly}}std::move({{/moveOnly}}d->{{paramName}}{{#moveOnly}}){{/moveOnly}};
}
        {{/allProperties}}
        {{#producesNonJson?}}
BaseJob::Status {{camelCaseOperationId}}Job::parseReply(QNetworkReply* reply)
{
    {{#headers}}d->{{paramName}} = reply->rawHeader("{{baseName}}");{{! We don't check for required headers yet }}
    {{/headers}}{{#properties}}d->{{paramName}} = reply;{{/properties}}
    return Success;
}
        {{/producesNonJson?}}{{^producesNonJson?}}
BaseJob::Status {{camelCaseOperationId}}Job::parseJson(const QJsonDocument& data)
{
{{#inlineResponse
}}    fromJson(data, d->{{paramName}});
{{/inlineResponse}}{{^inlineResponse
}}    auto json = data.object();
{{#    properties}}{{#required?
}}    if (!json.contains("{{baseName}}"_ls))
        return { IncorrectResponse,
            "The key '{{baseName}}' not found in the response" };
{{/required?
}}    fromJson(json.value("{{baseName}}"_ls), d->{{paramName}});
{{/    properties}}
{{/inlineResponse
}}    return Success;
}
        {{/producesNonJson?}}
    {{/allProperties?}}{{/normalResponse?}}{{/responses}}
{{/operation}}{{/operations}}
span> Private; QScopedPointer<Private> d; }; /// Retrieve metadata about a specific protocol that the homeserver supports. /// /// Fetches the metadata from the homeserver about a particular third party protocol. class GetProtocolMetadataJob : public BaseJob { public: /*! Retrieve metadata about a specific protocol that the homeserver supports. * \param protocol * The name of the protocol. */ explicit GetProtocolMetadataJob(const QString& protocol); /*! Construct a URL without creating a full-fledged job object * * This function can be used when a URL for * GetProtocolMetadataJob is necessary but the job * itself isn't. */ static QUrl makeRequestUrl(QUrl baseUrl, const QString& protocol); ~GetProtocolMetadataJob() override; // Result properties /// The protocol was found and metadata returned. const ThirdPartyProtocol& data() const; protected: Status parseJson(const QJsonDocument& data) override; private: class Private; QScopedPointer<Private> d; }; /// Retrieve Matrix-side portals rooms leading to a third party location. /// /// Requesting this endpoint with a valid protocol name results in a list /// of successful mapping results in a JSON array. Each result contains /// objects to represent the Matrix room or rooms that represent a portal /// to this third party network. Each has the Matrix room alias string, /// an identifier for the particular third party network protocol, and an /// object containing the network-specific fields that comprise this /// identifier. It should attempt to canonicalise the identifier as much /// as reasonably possible given the network type. class QueryLocationByProtocolJob : public BaseJob { public: /*! Retrieve Matrix-side portals rooms leading to a third party location. * \param protocol * The protocol used to communicate to the third party network. * \param searchFields * One or more custom fields to help identify the third party * location. */ explicit QueryLocationByProtocolJob(const QString& protocol, const QString& searchFields = {}); /*! Construct a URL without creating a full-fledged job object * * This function can be used when a URL for * QueryLocationByProtocolJob is necessary but the job * itself isn't. */ static QUrl makeRequestUrl(QUrl baseUrl, const QString& protocol, const QString& searchFields = {}); ~QueryLocationByProtocolJob() override; // Result properties /// At least one portal room was found. const QVector<ThirdPartyLocation>& data() const; protected: Status parseJson(const QJsonDocument& data) override; private: class Private; QScopedPointer<Private> d; }; /// Retrieve the Matrix User ID of a corresponding third party user. /// /// Retrieve a Matrix User ID linked to a user on the third party service, given /// a set of user parameters. class QueryUserByProtocolJob : public BaseJob { public: /*! Retrieve the Matrix User ID of a corresponding third party user. * \param protocol * The name of the protocol. * \param fields * One or more custom fields that are passed to the AS to help identify the user. */ explicit QueryUserByProtocolJob(const QString& protocol, const QString& fields = {}); /*! Construct a URL without creating a full-fledged job object * * This function can be used when a URL for * QueryUserByProtocolJob is necessary but the job * itself isn't. */ static QUrl makeRequestUrl(QUrl baseUrl, const QString& protocol, const QString& fields = {}); ~QueryUserByProtocolJob() override; // Result properties /// The Matrix User IDs found with the given parameters. const QVector<ThirdPartyUser>& data() const; protected: Status parseJson(const QJsonDocument& data) override; private: class Private; QScopedPointer<Private> d; }; /// Reverse-lookup third party locations given a Matrix room alias. /// /// Retrieve an array of third party network locations from a Matrix room /// alias. class QueryLocationByAliasJob : public BaseJob { public: /*! Reverse-lookup third party locations given a Matrix room alias. * \param alias * The Matrix room alias to look up. */ explicit QueryLocationByAliasJob(const QString& alias); /*! Construct a URL without creating a full-fledged job object * * This function can be used when a URL for * QueryLocationByAliasJob is necessary but the job * itself isn't. */ static QUrl makeRequestUrl(QUrl baseUrl, const QString& alias); ~QueryLocationByAliasJob() override; // Result properties /// All found third party locations. const QVector<ThirdPartyLocation>& data() const; protected: Status parseJson(const QJsonDocument& data) override; private: class Private; QScopedPointer<Private> d; }; /// Reverse-lookup third party users given a Matrix User ID. /// /// Retrieve an array of third party users from a Matrix User ID. class QueryUserByIDJob : public BaseJob { public: /*! Reverse-lookup third party users given a Matrix User ID. * \param userid * The Matrix User ID to look up. */ explicit QueryUserByIDJob(const QString& userid); /*! Construct a URL without creating a full-fledged job object * * This function can be used when a URL for * QueryUserByIDJob is necessary but the job * itself isn't. */ static QUrl makeRequestUrl(QUrl baseUrl, const QString& userid); ~QueryUserByIDJob() override; // Result properties /// An array of third party users. const QVector<ThirdPartyUser>& data() const; protected: Status parseJson(const QJsonDocument& data) override; private: class Private; QScopedPointer<Private> d; }; } // namespace QMatrixClient