aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/device_management.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/csapi/device_management.cpp')
-rw-r--r--lib/csapi/device_management.cpp120
1 files changed, 32 insertions, 88 deletions
diff --git a/lib/csapi/device_management.cpp b/lib/csapi/device_management.cpp
index 861e1994..6f2badee 100644
--- a/lib/csapi/device_management.cpp
+++ b/lib/csapi/device_management.cpp
@@ -4,114 +4,58 @@
#include "device_management.h"
-#include "converters.h"
-
-#include <QtCore/QStringBuilder>
-
-using namespace QMatrixClient;
-
-static const auto basePath = QStringLiteral("/_matrix/client/r0");
-
-class GetDevicesJob::Private
-{
- public:
- QVector<Device> devices;
-};
+using namespace Quotient;
QUrl GetDevicesJob::makeRequestUrl(QUrl baseUrl)
{
return BaseJob::makeRequestUrl(std::move(baseUrl),
- basePath % "/devices");
+ makePath("/_matrix/client/v3", "/devices"));
}
-static const auto GetDevicesJobName = QStringLiteral("GetDevicesJob");
-
GetDevicesJob::GetDevicesJob()
- : BaseJob(HttpVerb::Get, GetDevicesJobName,
- basePath % "/devices")
- , d(new Private)
-{
-}
-
-GetDevicesJob::~GetDevicesJob() = default;
-
-const QVector<Device>& GetDevicesJob::devices() const
-{
- return d->devices;
-}
-
-BaseJob::Status GetDevicesJob::parseJson(const QJsonDocument& data)
-{
- auto json = data.object();
- d->devices = fromJson<QVector<Device>>(json.value("devices"_ls));
- return Success;
-}
-
-class GetDeviceJob::Private
-{
- public:
- Device data;
-};
+ : BaseJob(HttpVerb::Get, QStringLiteral("GetDevicesJob"),
+ makePath("/_matrix/client/v3", "/devices"))
+{}
QUrl GetDeviceJob::makeRequestUrl(QUrl baseUrl, const QString& deviceId)
{
return BaseJob::makeRequestUrl(std::move(baseUrl),
- basePath % "/devices/" % deviceId);
+ makePath("/_matrix/client/v3", "/devices/",
+ deviceId));
}
-static const auto GetDeviceJobName = QStringLiteral("GetDeviceJob");
-
GetDeviceJob::GetDeviceJob(const QString& deviceId)
- : BaseJob(HttpVerb::Get, GetDeviceJobName,
- basePath % "/devices/" % deviceId)
- , d(new Private)
-{
-}
+ : BaseJob(HttpVerb::Get, QStringLiteral("GetDeviceJob"),
+ makePath("/_matrix/client/v3", "/devices/", deviceId))
+{}
-GetDeviceJob::~GetDeviceJob() = default;
-
-const Device& GetDeviceJob::data() const
+UpdateDeviceJob::UpdateDeviceJob(const QString& deviceId,
+ const QString& displayName)
+ : BaseJob(HttpVerb::Put, QStringLiteral("UpdateDeviceJob"),
+ makePath("/_matrix/client/v3", "/devices/", deviceId))
{
- return d->data;
+ QJsonObject _dataJson;
+ addParam<IfNotEmpty>(_dataJson, QStringLiteral("display_name"), displayName);
+ setRequestData({ _dataJson });
}
-BaseJob::Status GetDeviceJob::parseJson(const QJsonDocument& data)
+DeleteDeviceJob::DeleteDeviceJob(const QString& deviceId,
+ const Omittable<AuthenticationData>& auth)
+ : BaseJob(HttpVerb::Delete, QStringLiteral("DeleteDeviceJob"),
+ makePath("/_matrix/client/v3", "/devices/", deviceId))
{
- d->data = fromJson<Device>(data);
- return Success;
+ QJsonObject _dataJson;
+ addParam<IfNotEmpty>(_dataJson, QStringLiteral("auth"), auth);
+ setRequestData({ _dataJson });
}
-static const auto UpdateDeviceJobName = QStringLiteral("UpdateDeviceJob");
-
-UpdateDeviceJob::UpdateDeviceJob(const QString& deviceId, const QString& displayName)
- : BaseJob(HttpVerb::Put, UpdateDeviceJobName,
- basePath % "/devices/" % deviceId)
+DeleteDevicesJob::DeleteDevicesJob(const QStringList& devices,
+ const Omittable<AuthenticationData>& auth)
+ : BaseJob(HttpVerb::Post, QStringLiteral("DeleteDevicesJob"),
+ makePath("/_matrix/client/v3", "/delete_devices"))
{
- QJsonObject _data;
- addParam<IfNotEmpty>(_data, QStringLiteral("display_name"), displayName);
- setRequestData(_data);
+ QJsonObject _dataJson;
+ addParam<>(_dataJson, QStringLiteral("devices"), devices);
+ addParam<IfNotEmpty>(_dataJson, QStringLiteral("auth"), auth);
+ setRequestData({ _dataJson });
}
-
-static const auto DeleteDeviceJobName = QStringLiteral("DeleteDeviceJob");
-
-DeleteDeviceJob::DeleteDeviceJob(const QString& deviceId, const Omittable<AuthenticationData>& auth)
- : BaseJob(HttpVerb::Delete, DeleteDeviceJobName,
- basePath % "/devices/" % deviceId)
-{
- QJsonObject _data;
- addParam<IfNotEmpty>(_data, QStringLiteral("auth"), auth);
- setRequestData(_data);
-}
-
-static const auto DeleteDevicesJobName = QStringLiteral("DeleteDevicesJob");
-
-DeleteDevicesJob::DeleteDevicesJob(const QStringList& devices, const Omittable<AuthenticationData>& auth)
- : BaseJob(HttpVerb::Post, DeleteDevicesJobName,
- basePath % "/delete_devices")
-{
- QJsonObject _data;
- addParam<>(_data, QStringLiteral("devices"), devices);
- addParam<IfNotEmpty>(_data, QStringLiteral("auth"), auth);
- setRequestData(_data);
-}
-