diff options
Diffstat (limited to 'lib/csapi/administrative_contact.cpp')
-rw-r--r-- | lib/csapi/administrative_contact.cpp | 174 |
1 files changed, 55 insertions, 119 deletions
diff --git a/lib/csapi/administrative_contact.cpp b/lib/csapi/administrative_contact.cpp index 36d93e73..fa4f475a 100644 --- a/lib/csapi/administrative_contact.cpp +++ b/lib/csapi/administrative_contact.cpp @@ -4,164 +4,100 @@ #include "administrative_contact.h" -#include "converters.h" - #include <QtCore/QStringBuilder> using namespace Quotient; -static const auto basePath = QStringLiteral("/_matrix/client/r0"); - -// Converters -namespace Quotient { - -template <> -struct JsonObjectConverter<GetAccount3PIDsJob::ThirdPartyIdentifier> { - static void fillFrom(const QJsonObject& jo, - GetAccount3PIDsJob::ThirdPartyIdentifier& result) - { - fromJson(jo.value("medium"_ls), result.medium); - fromJson(jo.value("address"_ls), result.address); - fromJson(jo.value("validated_at"_ls), result.validatedAt); - fromJson(jo.value("added_at"_ls), result.addedAt); - } -}; - -} // namespace Quotient - -class GetAccount3PIDsJob::Private { -public: - QVector<ThirdPartyIdentifier> threepids; -}; - QUrl GetAccount3PIDsJob::makeRequestUrl(QUrl baseUrl) { return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/account/3pid"); + QStringLiteral("/_matrix/client/r0") + % "/account/3pid"); } GetAccount3PIDsJob::GetAccount3PIDsJob() : BaseJob(HttpVerb::Get, QStringLiteral("GetAccount3PIDsJob"), - basePath % "/account/3pid") - , d(new Private) + QStringLiteral("/_matrix/client/r0") % "/account/3pid") {} -GetAccount3PIDsJob::~GetAccount3PIDsJob() = default; - -const QVector<GetAccount3PIDsJob::ThirdPartyIdentifier>& -GetAccount3PIDsJob::threepids() const +Post3PIDsJob::Post3PIDsJob(const ThreePidCredentials& threePidCreds) + : BaseJob(HttpVerb::Post, QStringLiteral("Post3PIDsJob"), + QStringLiteral("/_matrix/client/r0") % "/account/3pid") { - return d->threepids; + QJsonObject _data; + addParam<>(_data, QStringLiteral("three_pid_creds"), threePidCreds); + setRequestData(std::move(_data)); } -BaseJob::Status GetAccount3PIDsJob::parseJson(const QJsonDocument& data) +Add3PIDJob::Add3PIDJob(const QString& clientSecret, const QString& sid, + const Omittable<AuthenticationData>& auth) + : BaseJob(HttpVerb::Post, QStringLiteral("Add3PIDJob"), + QStringLiteral("/_matrix/client/r0") % "/account/3pid/add") { - auto json = data.object(); - fromJson(json.value("threepids"_ls), d->threepids); - - return Success; + QJsonObject _data; + addParam<IfNotEmpty>(_data, QStringLiteral("auth"), auth); + addParam<>(_data, QStringLiteral("client_secret"), clientSecret); + addParam<>(_data, QStringLiteral("sid"), sid); + setRequestData(std::move(_data)); } -// Converters -namespace Quotient { - -template <> -struct JsonObjectConverter<Post3PIDsJob::ThreePidCredentials> { - static void dumpTo(QJsonObject& jo, - const Post3PIDsJob::ThreePidCredentials& pod) - { - addParam<>(jo, QStringLiteral("client_secret"), pod.clientSecret); - addParam<>(jo, QStringLiteral("id_server"), pod.idServer); - addParam<>(jo, QStringLiteral("sid"), pod.sid); - } -}; - -} // namespace Quotient - -Post3PIDsJob::Post3PIDsJob(const ThreePidCredentials& threePidCreds, - Omittable<bool> bind) - : BaseJob(HttpVerb::Post, QStringLiteral("Post3PIDsJob"), - basePath % "/account/3pid") +Bind3PIDJob::Bind3PIDJob(const QString& clientSecret, const QString& idServer, + const QString& idAccessToken, const QString& sid) + : BaseJob(HttpVerb::Post, QStringLiteral("Bind3PIDJob"), + QStringLiteral("/_matrix/client/r0") % "/account/3pid/bind") { QJsonObject _data; - addParam<>(_data, QStringLiteral("three_pid_creds"), threePidCreds); - addParam<IfNotEmpty>(_data, QStringLiteral("bind"), bind); - setRequestData(_data); + addParam<>(_data, QStringLiteral("client_secret"), clientSecret); + addParam<>(_data, QStringLiteral("id_server"), idServer); + addParam<>(_data, QStringLiteral("id_access_token"), idAccessToken); + addParam<>(_data, QStringLiteral("sid"), sid); + setRequestData(std::move(_data)); } Delete3pidFromAccountJob::Delete3pidFromAccountJob(const QString& medium, - const QString& address) + const QString& address, + const QString& idServer) : BaseJob(HttpVerb::Post, QStringLiteral("Delete3pidFromAccountJob"), - basePath % "/account/3pid/delete") + QStringLiteral("/_matrix/client/r0") % "/account/3pid/delete") { QJsonObject _data; + addParam<IfNotEmpty>(_data, QStringLiteral("id_server"), idServer); addParam<>(_data, QStringLiteral("medium"), medium); addParam<>(_data, QStringLiteral("address"), address); - setRequestData(_data); + setRequestData(std::move(_data)); + addExpectedKey("id_server_unbind_result"); } -class RequestTokenTo3PIDEmailJob::Private { -public: - Sid data; -}; - -RequestTokenTo3PIDEmailJob::RequestTokenTo3PIDEmailJob( - const QString& clientSecret, const QString& email, int sendAttempt, - const QString& idServer, const QString& nextLink) - : BaseJob(HttpVerb::Post, QStringLiteral("RequestTokenTo3PIDEmailJob"), - basePath % "/account/3pid/email/requestToken", false) - , d(new Private) +Unbind3pidFromAccountJob::Unbind3pidFromAccountJob(const QString& medium, + const QString& address, + const QString& idServer) + : BaseJob(HttpVerb::Post, QStringLiteral("Unbind3pidFromAccountJob"), + QStringLiteral("/_matrix/client/r0") % "/account/3pid/unbind") { QJsonObject _data; - addParam<>(_data, QStringLiteral("client_secret"), clientSecret); - addParam<>(_data, QStringLiteral("email"), email); - addParam<>(_data, QStringLiteral("send_attempt"), sendAttempt); - addParam<IfNotEmpty>(_data, QStringLiteral("next_link"), nextLink); - addParam<>(_data, QStringLiteral("id_server"), idServer); - setRequestData(_data); + addParam<IfNotEmpty>(_data, QStringLiteral("id_server"), idServer); + addParam<>(_data, QStringLiteral("medium"), medium); + addParam<>(_data, QStringLiteral("address"), address); + setRequestData(std::move(_data)); + addExpectedKey("id_server_unbind_result"); } -RequestTokenTo3PIDEmailJob::~RequestTokenTo3PIDEmailJob() = default; - -const Sid& RequestTokenTo3PIDEmailJob::data() const { return d->data; } - -BaseJob::Status RequestTokenTo3PIDEmailJob::parseJson(const QJsonDocument& data) +RequestTokenTo3PIDEmailJob::RequestTokenTo3PIDEmailJob( + const EmailValidationData& body) + : BaseJob(HttpVerb::Post, QStringLiteral("RequestTokenTo3PIDEmailJob"), + QStringLiteral("/_matrix/client/r0") + % "/account/3pid/email/requestToken", + false) { - fromJson(data, d->data); - - return Success; + setRequestData(Data(toJson(body))); } -class RequestTokenTo3PIDMSISDNJob::Private { -public: - Sid data; -}; - RequestTokenTo3PIDMSISDNJob::RequestTokenTo3PIDMSISDNJob( - const QString& clientSecret, const QString& country, - const QString& phoneNumber, int sendAttempt, const QString& idServer, - const QString& nextLink) + const MsisdnValidationData& body) : BaseJob(HttpVerb::Post, QStringLiteral("RequestTokenTo3PIDMSISDNJob"), - basePath % "/account/3pid/msisdn/requestToken", false) - , d(new Private) -{ - QJsonObject _data; - addParam<>(_data, QStringLiteral("client_secret"), clientSecret); - addParam<>(_data, QStringLiteral("country"), country); - addParam<>(_data, QStringLiteral("phone_number"), phoneNumber); - addParam<>(_data, QStringLiteral("send_attempt"), sendAttempt); - addParam<IfNotEmpty>(_data, QStringLiteral("next_link"), nextLink); - addParam<>(_data, QStringLiteral("id_server"), idServer); - setRequestData(_data); -} - -RequestTokenTo3PIDMSISDNJob::~RequestTokenTo3PIDMSISDNJob() = default; - -const Sid& RequestTokenTo3PIDMSISDNJob::data() const { return d->data; } - -BaseJob::Status RequestTokenTo3PIDMSISDNJob::parseJson(const QJsonDocument& data) + QStringLiteral("/_matrix/client/r0") + % "/account/3pid/msisdn/requestToken", + false) { - fromJson(data, d->data); - - return Success; + setRequestData(Data(toJson(body))); } |