From 941cfdf8b591bf14002f28e99e06c200dc5bcc84 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 28 Jul 2018 18:57:29 +0900 Subject: csapi/third_party_lookup.*: Properly pass a variadic (aka exploded) parameters Most of the actual change was in the API definition files (thanks to @anoadragon453), plus a converter from a QJsonObject map to the URL query string. --- lib/converters.h | 6 ++++++ lib/csapi/third_party_lookup.cpp | 8 ++++---- lib/csapi/third_party_lookup.h | 5 +++-- 3 files changed, 13 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/converters.h b/lib/converters.h index 1a8f3cfa..1e828393 100644 --- a/lib/converters.h +++ b/lib/converters.h @@ -331,6 +331,12 @@ namespace QMatrixClient q.addQueryItem(k, v); } + inline void addTo(QUrlQuery& q, const QString&, const QJsonObject& vals) + { + for (auto it = vals.begin(); it != vals.end(); ++it) + q.addQueryItem(it.key(), it.value().toString()); + } + // This one is for types that don't have isEmpty() template struct AddNode diff --git a/lib/csapi/third_party_lookup.cpp b/lib/csapi/third_party_lookup.cpp index 4396738c..45ccb7c3 100644 --- a/lib/csapi/third_party_lookup.cpp +++ b/lib/csapi/third_party_lookup.cpp @@ -142,14 +142,14 @@ class QueryUserByProtocolJob::Private QVector data; }; -BaseJob::Query queryToQueryUserByProtocol(const QString& fields) +BaseJob::Query queryToQueryUserByProtocol(const QJsonObject& fields) { BaseJob::Query _q; - addParam(_q, QStringLiteral("fields..."), fields); + addParam(_q, QStringLiteral("fields"), fields); return _q; } -QUrl QueryUserByProtocolJob::makeRequestUrl(QUrl baseUrl, const QString& protocol, const QString& fields) +QUrl QueryUserByProtocolJob::makeRequestUrl(QUrl baseUrl, const QString& protocol, const QJsonObject& fields) { return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/thirdparty/user/" % protocol, @@ -158,7 +158,7 @@ QUrl QueryUserByProtocolJob::makeRequestUrl(QUrl baseUrl, const QString& protoco static const auto QueryUserByProtocolJobName = QStringLiteral("QueryUserByProtocolJob"); -QueryUserByProtocolJob::QueryUserByProtocolJob(const QString& protocol, const QString& fields) +QueryUserByProtocolJob::QueryUserByProtocolJob(const QString& protocol, const QJsonObject& fields) : BaseJob(HttpVerb::Get, QueryUserByProtocolJobName, basePath % "/thirdparty/user/" % protocol, queryToQueryUserByProtocol(fields), diff --git a/lib/csapi/third_party_lookup.h b/lib/csapi/third_party_lookup.h index 03d607a8..a431b87a 100644 --- a/lib/csapi/third_party_lookup.h +++ b/lib/csapi/third_party_lookup.h @@ -7,6 +7,7 @@ #include "jobs/basejob.h" #include "csapi/../application-service/definitions/user.h" +#include #include "csapi/../application-service/definitions/location.h" #include #include @@ -143,7 +144,7 @@ namespace QMatrixClient * \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 = {}); + explicit QueryUserByProtocolJob(const QString& protocol, const QJsonObject& fields = {}); /*! Construct a URL without creating a full-fledged job object * @@ -151,7 +152,7 @@ namespace QMatrixClient * QueryUserByProtocolJob is necessary but the job * itself isn't. */ - static QUrl makeRequestUrl(QUrl baseUrl, const QString& protocol, const QString& fields = {}); + static QUrl makeRequestUrl(QUrl baseUrl, const QString& protocol, const QJsonObject& fields = {}); ~QueryUserByProtocolJob() override; -- cgit v1.2.3