From a2024608abf4912b9720829ba0b0c20bbb4a5916 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 8 Jun 2018 12:47:59 +0900 Subject: csapi: added sync filter definitions and jobs --- lib/csapi/filter.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 lib/csapi/filter.cpp (limited to 'lib/csapi/filter.cpp') diff --git a/lib/csapi/filter.cpp b/lib/csapi/filter.cpp new file mode 100644 index 00000000..a1546923 --- /dev/null +++ b/lib/csapi/filter.cpp @@ -0,0 +1,78 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "filter.h" + +#include "converters.h" + +#include + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +class DefineFilterJob::Private +{ + public: + QString filterId; +}; + +DefineFilterJob::DefineFilterJob(const QString& userId, const SyncFilter& filter) + : BaseJob(HttpVerb::Post, "DefineFilterJob", + basePath % "/user/" % userId % "/filter") + , d(new Private) +{ + setRequestData(Data(toJson(filter))); +} + +DefineFilterJob::~DefineFilterJob() = default; + +const QString& DefineFilterJob::filterId() const +{ + return d->filterId; +} + +BaseJob::Status DefineFilterJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + d->filterId = fromJson(json.value("filter_id")); + return Success; +} + +class GetFilterJob::Private +{ + public: + SyncFilter data; +}; + +QUrl GetFilterJob::makeRequestUrl(QUrl baseUrl, const QString& userId, const QString& filterId) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/user/" % userId % "/filter/" % filterId); +} + +GetFilterJob::GetFilterJob(const QString& userId, const QString& filterId) + : BaseJob(HttpVerb::Get, "GetFilterJob", + basePath % "/user/" % userId % "/filter/" % filterId) + , d(new Private) +{ +} + +GetFilterJob::~GetFilterJob() = default; + +const SyncFilter& GetFilterJob::data() const +{ + return d->data; +} + +BaseJob::Status GetFilterJob::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(json.value("data")); + return Success; +} + -- cgit v1.2.3