aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/filter.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-06-08 12:47:59 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-06-08 12:47:59 +0900
commita2024608abf4912b9720829ba0b0c20bbb4a5916 (patch)
tree8aa07460cf6f73520a0c14db0259a4a24ddb3067 /lib/csapi/filter.cpp
parentb0fedde2361cb9c58b99f1fffb1085315d5fb981 (diff)
downloadlibquotient-a2024608abf4912b9720829ba0b0c20bbb4a5916.tar.gz
libquotient-a2024608abf4912b9720829ba0b0c20bbb4a5916.zip
csapi: added sync filter definitions and jobs
Diffstat (limited to 'lib/csapi/filter.cpp')
-rw-r--r--lib/csapi/filter.cpp78
1 files changed, 78 insertions, 0 deletions
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 <QtCore/QStringBuilder>
+
+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<QString>(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<SyncFilter>(json.value("data"));
+ return Success;
+}
+