diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-06-08 17:03:41 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-06-08 17:03:41 +0900 |
commit | b28e2d697842f58e2994ead62635b31f48162cdc (patch) | |
tree | 79e4ea713835e19d591c4c4b32d2997139a1ef01 /lib/csapi/device_management.cpp | |
parent | 318e094e19bc8ecfe89031e4c62a8cd14d307157 (diff) | |
download | libquotient-b28e2d697842f58e2994ead62635b31f48162cdc.tar.gz libquotient-b28e2d697842f58e2994ead62635b31f48162cdc.zip |
csapi: add jobs for device management
Same as for account management jobs, auth objects are modeled as generic
QJsonObjects for now.
Diffstat (limited to 'lib/csapi/device_management.cpp')
-rw-r--r-- | lib/csapi/device_management.cpp | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/lib/csapi/device_management.cpp b/lib/csapi/device_management.cpp new file mode 100644 index 00000000..2248a0b4 --- /dev/null +++ b/lib/csapi/device_management.cpp @@ -0,0 +1,111 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#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; +}; + +QUrl GetDevicesJob::makeRequestUrl(QUrl baseUrl) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/devices"); +} + +GetDevicesJob::GetDevicesJob() + : BaseJob(HttpVerb::Get, "GetDevicesJob", + 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")); + return Success; +} + +class GetDeviceJob::Private +{ + public: + Device data; +}; + +QUrl GetDeviceJob::makeRequestUrl(QUrl baseUrl, const QString& deviceId) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/devices/" % deviceId); +} + +GetDeviceJob::GetDeviceJob(const QString& deviceId) + : BaseJob(HttpVerb::Get, "GetDeviceJob", + basePath % "/devices/" % deviceId) + , d(new Private) +{ +} + +GetDeviceJob::~GetDeviceJob() = default; + +const Device& GetDeviceJob::data() const +{ + return d->data; +} + +BaseJob::Status GetDeviceJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + if (!json.contains("data")) + return { JsonParseError, + "The key 'data' not found in the response" }; + d->data = fromJson<Device>(json.value("data")); + return Success; +} + +UpdateDeviceJob::UpdateDeviceJob(const QString& deviceId, const QString& displayName) + : BaseJob(HttpVerb::Put, "UpdateDeviceJob", + basePath % "/devices/" % deviceId) +{ + QJsonObject _data; + addToJson<IfNotEmpty>(_data, "display_name", displayName); + setRequestData(_data); +} + +DeleteDeviceJob::DeleteDeviceJob(const QString& deviceId, const QJsonObject& auth) + : BaseJob(HttpVerb::Delete, "DeleteDeviceJob", + basePath % "/devices/" % deviceId) +{ + QJsonObject _data; + addToJson<IfNotEmpty>(_data, "auth", auth); + setRequestData(_data); +} + +DeleteDevicesJob::DeleteDevicesJob(const QStringList& devices, const QJsonObject& auth) + : BaseJob(HttpVerb::Post, "DeleteDevicesJob", + basePath % "/delete_devices") +{ + QJsonObject _data; + addToJson<>(_data, "devices", devices); + addToJson<IfNotEmpty>(_data, "auth", auth); + setRequestData(_data); +} + |