From ddf10847d496dd65b00bc2026412958acd09790d Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 3 Jun 2018 19:50:54 +0900 Subject: csapi: jobs to setup push-rules --- lib/csapi/definitions/push_condition.cpp | 34 +++++ lib/csapi/definitions/push_condition.h | 30 +++++ lib/csapi/definitions/push_rule.cpp | 40 ++++++ lib/csapi/definitions/push_rule.h | 37 ++++++ lib/csapi/definitions/push_ruleset.cpp | 37 ++++++ lib/csapi/definitions/push_ruleset.h | 34 +++++ lib/csapi/pushrules.cpp | 210 +++++++++++++++++++++++++++++++ lib/csapi/pushrules.h | 154 +++++++++++++++++++++++ 8 files changed, 576 insertions(+) create mode 100644 lib/csapi/definitions/push_condition.cpp create mode 100644 lib/csapi/definitions/push_condition.h create mode 100644 lib/csapi/definitions/push_rule.cpp create mode 100644 lib/csapi/definitions/push_rule.h create mode 100644 lib/csapi/definitions/push_ruleset.cpp create mode 100644 lib/csapi/definitions/push_ruleset.h create mode 100644 lib/csapi/pushrules.cpp create mode 100644 lib/csapi/pushrules.h diff --git a/lib/csapi/definitions/push_condition.cpp b/lib/csapi/definitions/push_condition.cpp new file mode 100644 index 00000000..149419f4 --- /dev/null +++ b/lib/csapi/definitions/push_condition.cpp @@ -0,0 +1,34 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "push_condition.h" + +using namespace QMatrixClient; + +QJsonObject QMatrixClient::toJson(const PushCondition& pod) +{ + QJsonObject _json; + addToJson<>(_json, "kind", pod.kind); + addToJson(_json, "key", pod.key); + addToJson(_json, "pattern", pod.pattern); + addToJson(_json, "is", pod.is); + return _json; +} + +PushCondition FromJson::operator()(const QJsonValue& jv) +{ + const auto& _json = jv.toObject(); + PushCondition result; + result.kind = + fromJson(_json.value("kind")); + result.key = + fromJson(_json.value("key")); + result.pattern = + fromJson(_json.value("pattern")); + result.is = + fromJson(_json.value("is")); + + return result; +} + diff --git a/lib/csapi/definitions/push_condition.h b/lib/csapi/definitions/push_condition.h new file mode 100644 index 00000000..5744b9b8 --- /dev/null +++ b/lib/csapi/definitions/push_condition.h @@ -0,0 +1,30 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + + + +#include "converters.h" + +namespace QMatrixClient +{ + // Data structures + + struct PushCondition + { + QString kind; + QString key; + QString pattern; + QString is; + }; + + QJsonObject toJson(const PushCondition& pod); + + template <> struct FromJson + { + PushCondition operator()(const QJsonValue& jv); + }; + +} // namespace QMatrixClient diff --git a/lib/csapi/definitions/push_rule.cpp b/lib/csapi/definitions/push_rule.cpp new file mode 100644 index 00000000..3a44a385 --- /dev/null +++ b/lib/csapi/definitions/push_rule.cpp @@ -0,0 +1,40 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "push_rule.h" + +using namespace QMatrixClient; + +QJsonObject QMatrixClient::toJson(const PushRule& pod) +{ + QJsonObject _json; + addToJson<>(_json, "actions", pod.actions); + addToJson<>(_json, "default", pod.isDefault); + addToJson<>(_json, "enabled", pod.enabled); + addToJson<>(_json, "rule_id", pod.ruleId); + addToJson(_json, "conditions", pod.conditions); + addToJson(_json, "pattern", pod.pattern); + return _json; +} + +PushRule FromJson::operator()(const QJsonValue& jv) +{ + const auto& _json = jv.toObject(); + PushRule result; + result.actions = + fromJson>(_json.value("actions")); + result.isDefault = + fromJson(_json.value("default")); + result.enabled = + fromJson(_json.value("enabled")); + result.ruleId = + fromJson(_json.value("rule_id")); + result.conditions = + fromJson>(_json.value("conditions")); + result.pattern = + fromJson(_json.value("pattern")); + + return result; +} + diff --git a/lib/csapi/definitions/push_rule.h b/lib/csapi/definitions/push_rule.h new file mode 100644 index 00000000..853210d0 --- /dev/null +++ b/lib/csapi/definitions/push_rule.h @@ -0,0 +1,37 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + + +#include "lib/csapi/definitions/push_condition.h" +#include "converters.h" +#include +#include +#include + +#include "converters.h" + +namespace QMatrixClient +{ + // Data structures + + struct PushRule + { + QVector actions; + bool isDefault; + bool enabled; + QString ruleId; + QVector conditions; + QString pattern; + }; + + QJsonObject toJson(const PushRule& pod); + + template <> struct FromJson + { + PushRule operator()(const QJsonValue& jv); + }; + +} // namespace QMatrixClient diff --git a/lib/csapi/definitions/push_ruleset.cpp b/lib/csapi/definitions/push_ruleset.cpp new file mode 100644 index 00000000..98d79248 --- /dev/null +++ b/lib/csapi/definitions/push_ruleset.cpp @@ -0,0 +1,37 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "push_ruleset.h" + +using namespace QMatrixClient; + +QJsonObject QMatrixClient::toJson(const PushRuleset& pod) +{ + QJsonObject _json; + addToJson(_json, "content", pod.content); + addToJson(_json, "override", pod.override); + addToJson(_json, "room", pod.room); + addToJson(_json, "sender", pod.sender); + addToJson(_json, "underride", pod.underride); + return _json; +} + +PushRuleset FromJson::operator()(const QJsonValue& jv) +{ + const auto& _json = jv.toObject(); + PushRuleset result; + result.content = + fromJson>(_json.value("content")); + result.override = + fromJson>(_json.value("override")); + result.room = + fromJson>(_json.value("room")); + result.sender = + fromJson>(_json.value("sender")); + result.underride = + fromJson>(_json.value("underride")); + + return result; +} + diff --git a/lib/csapi/definitions/push_ruleset.h b/lib/csapi/definitions/push_ruleset.h new file mode 100644 index 00000000..96199a11 --- /dev/null +++ b/lib/csapi/definitions/push_ruleset.h @@ -0,0 +1,34 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + + +#include +#include "converters.h" +#include "lib/csapi/definitions/push_rule.h" + +#include "converters.h" + +namespace QMatrixClient +{ + // Data structures + + struct PushRuleset + { + QVector content; + QVector override; + QVector room; + QVector sender; + QVector underride; + }; + + QJsonObject toJson(const PushRuleset& pod); + + template <> struct FromJson + { + PushRuleset operator()(const QJsonValue& jv); + }; + +} // namespace QMatrixClient diff --git a/lib/csapi/pushrules.cpp b/lib/csapi/pushrules.cpp new file mode 100644 index 00000000..eca46247 --- /dev/null +++ b/lib/csapi/pushrules.cpp @@ -0,0 +1,210 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "pushrules.h" + +#include "converters.h" + +#include + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +class GetPushRulesJob::Private +{ + public: + PushRuleset global; +}; + +QUrl GetPushRulesJob::makeRequestUrl(QUrl baseUrl) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/pushrules"); +} + +GetPushRulesJob::GetPushRulesJob() + : BaseJob(HttpVerb::Get, "GetPushRulesJob", + basePath % "/pushrules") + , d(new Private) +{ +} + +GetPushRulesJob::~GetPushRulesJob() = default; + +const PushRuleset& GetPushRulesJob::global() const +{ + return d->global; +} + +BaseJob::Status GetPushRulesJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + if (!json.contains("global")) + return { JsonParseError, + "The key 'global' not found in the response" }; + d->global = fromJson(json.value("global")); + return Success; +} + +class GetPushRuleJob::Private +{ + public: + PushRule data; +}; + +QUrl GetPushRuleJob::makeRequestUrl(QUrl baseUrl, const QString& scope, const QString& kind, const QString& ruleId) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId); +} + +GetPushRuleJob::GetPushRuleJob(const QString& scope, const QString& kind, const QString& ruleId) + : BaseJob(HttpVerb::Get, "GetPushRuleJob", + basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId) + , d(new Private) +{ +} + +GetPushRuleJob::~GetPushRuleJob() = default; + +const PushRule& GetPushRuleJob::data() const +{ + return d->data; +} + +BaseJob::Status GetPushRuleJob::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; +} + +QUrl DeletePushRuleJob::makeRequestUrl(QUrl baseUrl, const QString& scope, const QString& kind, const QString& ruleId) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId); +} + +DeletePushRuleJob::DeletePushRuleJob(const QString& scope, const QString& kind, const QString& ruleId) + : BaseJob(HttpVerb::Delete, "DeletePushRuleJob", + basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId) +{ +} + +BaseJob::Query queryToSetPushRule(const QString& before, const QString& after) +{ + BaseJob::Query _q; + if (!before.isEmpty()) + _q.addQueryItem("before", before); + if (!after.isEmpty()) + _q.addQueryItem("after", after); + return _q; +} + +SetPushRuleJob::SetPushRuleJob(const QString& scope, const QString& kind, const QString& ruleId, const QStringList& actions, const QString& before, const QString& after, const QVector& conditions, const QString& pattern) + : BaseJob(HttpVerb::Put, "SetPushRuleJob", + basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId, + queryToSetPushRule(before, after)) +{ + QJsonObject _data; + addToJson<>(_data, "actions", actions); + addToJson(_data, "conditions", conditions); + addToJson(_data, "pattern", pattern); + setRequestData(_data); +} + +class IsPushRuleEnabledJob::Private +{ + public: + bool enabled; +}; + +QUrl IsPushRuleEnabledJob::makeRequestUrl(QUrl baseUrl, const QString& scope, const QString& kind, const QString& ruleId) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/enabled"); +} + +IsPushRuleEnabledJob::IsPushRuleEnabledJob(const QString& scope, const QString& kind, const QString& ruleId) + : BaseJob(HttpVerb::Get, "IsPushRuleEnabledJob", + basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/enabled") + , d(new Private) +{ +} + +IsPushRuleEnabledJob::~IsPushRuleEnabledJob() = default; + +bool IsPushRuleEnabledJob::enabled() const +{ + return d->enabled; +} + +BaseJob::Status IsPushRuleEnabledJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + if (!json.contains("enabled")) + return { JsonParseError, + "The key 'enabled' not found in the response" }; + d->enabled = fromJson(json.value("enabled")); + return Success; +} + +SetPushRuleEnabledJob::SetPushRuleEnabledJob(const QString& scope, const QString& kind, const QString& ruleId, bool enabled) + : BaseJob(HttpVerb::Put, "SetPushRuleEnabledJob", + basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/enabled") +{ + QJsonObject _data; + addToJson<>(_data, "enabled", enabled); + setRequestData(_data); +} + +class GetPushRuleActionsJob::Private +{ + public: + QStringList actions; +}; + +QUrl GetPushRuleActionsJob::makeRequestUrl(QUrl baseUrl, const QString& scope, const QString& kind, const QString& ruleId) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/actions"); +} + +GetPushRuleActionsJob::GetPushRuleActionsJob(const QString& scope, const QString& kind, const QString& ruleId) + : BaseJob(HttpVerb::Get, "GetPushRuleActionsJob", + basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/actions") + , d(new Private) +{ +} + +GetPushRuleActionsJob::~GetPushRuleActionsJob() = default; + +const QStringList& GetPushRuleActionsJob::actions() const +{ + return d->actions; +} + +BaseJob::Status GetPushRuleActionsJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + if (!json.contains("actions")) + return { JsonParseError, + "The key 'actions' not found in the response" }; + d->actions = fromJson(json.value("actions")); + return Success; +} + +SetPushRuleActionsJob::SetPushRuleActionsJob(const QString& scope, const QString& kind, const QString& ruleId, const QStringList& actions) + : BaseJob(HttpVerb::Put, "SetPushRuleActionsJob", + basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/actions") +{ + QJsonObject _data; + addToJson<>(_data, "actions", actions); + setRequestData(_data); +} + diff --git a/lib/csapi/pushrules.h b/lib/csapi/pushrules.h new file mode 100644 index 00000000..a01049af --- /dev/null +++ b/lib/csapi/pushrules.h @@ -0,0 +1,154 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include "jobs/basejob.h" + +#include "lib/csapi/definitions/push_ruleset.h" +#include +#include "converters.h" +#include "lib/csapi/definitions/push_rule.h" +#include "lib/csapi/definitions/push_condition.h" + +namespace QMatrixClient +{ + // Operations + + class GetPushRulesJob : public BaseJob + { + public: + explicit GetPushRulesJob(); + + /** Construct a URL out of baseUrl and usual parameters passed to + * GetPushRulesJob. This function can be used when + * a URL for GetPushRulesJob is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl); + + ~GetPushRulesJob() override; + + // Result properties + + const PushRuleset& global() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer d; + }; + + class GetPushRuleJob : public BaseJob + { + public: + explicit GetPushRuleJob(const QString& scope, const QString& kind, const QString& ruleId); + + /** Construct a URL out of baseUrl and usual parameters passed to + * GetPushRuleJob. This function can be used when + * a URL for GetPushRuleJob is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& scope, const QString& kind, const QString& ruleId); + + ~GetPushRuleJob() override; + + // Result properties + + const PushRule& data() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer d; + }; + + class DeletePushRuleJob : public BaseJob + { + public: + explicit DeletePushRuleJob(const QString& scope, const QString& kind, const QString& ruleId); + + /** Construct a URL out of baseUrl and usual parameters passed to + * DeletePushRuleJob. This function can be used when + * a URL for DeletePushRuleJob is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& scope, const QString& kind, const QString& ruleId); + + }; + + class SetPushRuleJob : public BaseJob + { + public: + explicit SetPushRuleJob(const QString& scope, const QString& kind, const QString& ruleId, const QStringList& actions, const QString& before = {}, const QString& after = {}, const QVector& conditions = {}, const QString& pattern = {}); + }; + + class IsPushRuleEnabledJob : public BaseJob + { + public: + explicit IsPushRuleEnabledJob(const QString& scope, const QString& kind, const QString& ruleId); + + /** Construct a URL out of baseUrl and usual parameters passed to + * IsPushRuleEnabledJob. This function can be used when + * a URL for IsPushRuleEnabledJob is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& scope, const QString& kind, const QString& ruleId); + + ~IsPushRuleEnabledJob() override; + + // Result properties + + bool enabled() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer d; + }; + + class SetPushRuleEnabledJob : public BaseJob + { + public: + explicit SetPushRuleEnabledJob(const QString& scope, const QString& kind, const QString& ruleId, bool enabled); + }; + + class GetPushRuleActionsJob : public BaseJob + { + public: + explicit GetPushRuleActionsJob(const QString& scope, const QString& kind, const QString& ruleId); + + /** Construct a URL out of baseUrl and usual parameters passed to + * GetPushRuleActionsJob. This function can be used when + * a URL for GetPushRuleActionsJob is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& scope, const QString& kind, const QString& ruleId); + + ~GetPushRuleActionsJob() override; + + // Result properties + + const QStringList& actions() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer d; + }; + + class SetPushRuleActionsJob : public BaseJob + { + public: + explicit SetPushRuleActionsJob(const QString& scope, const QString& kind, const QString& ruleId, const QStringList& actions); + }; +} // namespace QMatrixClient -- cgit v1.2.3