From 3dd6b5e6cc50aafce74b21b5a0bf4b26a9fcf6ee Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 2 Jul 2018 17:58:34 +0900 Subject: Use QStringLiteral() and operator"" _ls() in network jobs --- lib/csapi/registration.cpp | 64 +++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 26 deletions(-) (limited to 'lib/csapi/registration.cpp') diff --git a/lib/csapi/registration.cpp b/lib/csapi/registration.cpp index 4345635a..4991829c 100644 --- a/lib/csapi/registration.cpp +++ b/lib/csapi/registration.cpp @@ -24,24 +24,26 @@ class RegisterJob::Private BaseJob::Query queryToRegister(const QString& kind) { BaseJob::Query _q; - addParam(_q, "kind", kind); + addParam(_q, QStringLiteral("kind"), kind); return _q; } +static const auto RegisterJobName = QStringLiteral("RegisterJob"); + RegisterJob::RegisterJob(const QString& kind, const QJsonObject& auth, bool bindEmail, const QString& username, const QString& password, const QString& deviceId, const QString& initialDeviceDisplayName) - : BaseJob(HttpVerb::Post, "RegisterJob", + : BaseJob(HttpVerb::Post, RegisterJobName, basePath % "/register", queryToRegister(kind), {}, false) , d(new Private) { QJsonObject _data; - addParam(_data, "auth", auth); - addParam(_data, "bind_email", bindEmail); - addParam(_data, "username", username); - addParam(_data, "password", password); - addParam(_data, "device_id", deviceId); - addParam(_data, "initial_device_display_name", initialDeviceDisplayName); + addParam(_data, QStringLiteral("auth"), auth); + addParam(_data, QStringLiteral("bind_email"), bindEmail); + addParam(_data, QStringLiteral("username"), username); + addParam(_data, QStringLiteral("password"), password); + addParam(_data, QStringLiteral("device_id"), deviceId); + addParam(_data, QStringLiteral("initial_device_display_name"), initialDeviceDisplayName); setRequestData(_data); } @@ -70,32 +72,36 @@ const QString& RegisterJob::deviceId() const BaseJob::Status RegisterJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->userId = fromJson(json.value("user_id")); - d->accessToken = fromJson(json.value("access_token")); - d->homeServer = fromJson(json.value("home_server")); - d->deviceId = fromJson(json.value("device_id")); + d->userId = fromJson(json.value("user_id"_ls)); + d->accessToken = fromJson(json.value("access_token"_ls)); + d->homeServer = fromJson(json.value("home_server"_ls)); + d->deviceId = fromJson(json.value("device_id"_ls)); return Success; } +static const auto RequestTokenToRegisterJobName = QStringLiteral("RequestTokenToRegisterJob"); + RequestTokenToRegisterJob::RequestTokenToRegisterJob(const QString& clientSecret, const QString& email, int sendAttempt, const QString& idServer) - : BaseJob(HttpVerb::Post, "RequestTokenToRegisterJob", + : BaseJob(HttpVerb::Post, RequestTokenToRegisterJobName, basePath % "/register/email/requestToken", false) { QJsonObject _data; - addParam(_data, "id_server", idServer); - addParam<>(_data, "client_secret", clientSecret); - addParam<>(_data, "email", email); - addParam<>(_data, "send_attempt", sendAttempt); + addParam(_data, QStringLiteral("id_server"), idServer); + addParam<>(_data, QStringLiteral("client_secret"), clientSecret); + addParam<>(_data, QStringLiteral("email"), email); + addParam<>(_data, QStringLiteral("send_attempt"), sendAttempt); setRequestData(_data); } +static const auto ChangePasswordJobName = QStringLiteral("ChangePasswordJob"); + ChangePasswordJob::ChangePasswordJob(const QString& newPassword, const QJsonObject& auth) - : BaseJob(HttpVerb::Post, "ChangePasswordJob", + : BaseJob(HttpVerb::Post, ChangePasswordJobName, basePath % "/account/password") { QJsonObject _data; - addParam<>(_data, "new_password", newPassword); - addParam(_data, "auth", auth); + addParam<>(_data, QStringLiteral("new_password"), newPassword); + addParam(_data, QStringLiteral("auth"), auth); setRequestData(_data); } @@ -105,18 +111,22 @@ QUrl RequestTokenToResetPasswordJob::makeRequestUrl(QUrl baseUrl) basePath % "/account/password/email/requestToken"); } +static const auto RequestTokenToResetPasswordJobName = QStringLiteral("RequestTokenToResetPasswordJob"); + RequestTokenToResetPasswordJob::RequestTokenToResetPasswordJob() - : BaseJob(HttpVerb::Post, "RequestTokenToResetPasswordJob", + : BaseJob(HttpVerb::Post, RequestTokenToResetPasswordJobName, basePath % "/account/password/email/requestToken", false) { } +static const auto DeactivateAccountJobName = QStringLiteral("DeactivateAccountJob"); + DeactivateAccountJob::DeactivateAccountJob(const QJsonObject& auth) - : BaseJob(HttpVerb::Post, "DeactivateAccountJob", + : BaseJob(HttpVerb::Post, DeactivateAccountJobName, basePath % "/account/deactivate") { QJsonObject _data; - addParam(_data, "auth", auth); + addParam(_data, QStringLiteral("auth"), auth); setRequestData(_data); } @@ -129,7 +139,7 @@ class CheckUsernameAvailabilityJob::Private BaseJob::Query queryToCheckUsernameAvailability(const QString& username) { BaseJob::Query _q; - addParam<>(_q, "username", username); + addParam<>(_q, QStringLiteral("username"), username); return _q; } @@ -140,8 +150,10 @@ QUrl CheckUsernameAvailabilityJob::makeRequestUrl(QUrl baseUrl, const QString& u queryToCheckUsernameAvailability(username)); } +static const auto CheckUsernameAvailabilityJobName = QStringLiteral("CheckUsernameAvailabilityJob"); + CheckUsernameAvailabilityJob::CheckUsernameAvailabilityJob(const QString& username) - : BaseJob(HttpVerb::Get, "CheckUsernameAvailabilityJob", + : BaseJob(HttpVerb::Get, CheckUsernameAvailabilityJobName, basePath % "/register/available", queryToCheckUsernameAvailability(username), {}, false) @@ -159,7 +171,7 @@ bool CheckUsernameAvailabilityJob::available() const BaseJob::Status CheckUsernameAvailabilityJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->available = fromJson(json.value("available")); + d->available = fromJson(json.value("available"_ls)); return Success; } -- cgit v1.2.3