diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-05-04 23:04:04 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-05-04 23:04:04 +0900 |
commit | 49022915fde72b83d9f18944c268110b01fa3469 (patch) | |
tree | 1b465b553a2e341486cd6051530a63faba17288e /lib/csapi/pusher.cpp | |
parent | f70ec41accd6da9f223bc41b446ad1d2d77de3f4 (diff) | |
download | libquotient-49022915fde72b83d9f18944c268110b01fa3469.tar.gz libquotient-49022915fde72b83d9f18944c268110b01fa3469.zip |
New home for the generated code - lib/csapi
Diffstat (limited to 'lib/csapi/pusher.cpp')
-rw-r--r-- | lib/csapi/pusher.cpp | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/lib/csapi/pusher.cpp b/lib/csapi/pusher.cpp new file mode 100644 index 00000000..dea7cf8b --- /dev/null +++ b/lib/csapi/pusher.cpp @@ -0,0 +1,121 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "pusher.h" + +#include <QtCore/QStringBuilder> + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +namespace QMatrixClient +{ + // Converters + + template <> struct FromJson<GetPushersJob::PusherData> + { + GetPushersJob::PusherData operator()(const QJsonValue& jv) + { + const auto& o = jv.toObject(); + GetPushersJob::PusherData result; + result.url = + fromJson<QString>(o.value("url")); + + return result; + } + }; + + template <> struct FromJson<GetPushersJob::Pusher> + { + GetPushersJob::Pusher operator()(const QJsonValue& jv) + { + const auto& o = jv.toObject(); + GetPushersJob::Pusher result; + result.pushkey = + fromJson<QString>(o.value("pushkey")); + result.kind = + fromJson<QString>(o.value("kind")); + result.appId = + fromJson<QString>(o.value("app_id")); + result.appDisplayName = + fromJson<QString>(o.value("app_display_name")); + result.deviceDisplayName = + fromJson<QString>(o.value("device_display_name")); + result.profileTag = + fromJson<QString>(o.value("profile_tag")); + result.lang = + fromJson<QString>(o.value("lang")); + result.data = + fromJson<GetPushersJob::PusherData>(o.value("data")); + + return result; + } + }; +} // namespace QMatrixClient + +class GetPushersJob::Private +{ + public: + QVector<Pusher> pushers; +}; + +QUrl GetPushersJob::makeRequestUrl(QUrl baseUrl) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/pushers"); +} + +GetPushersJob::GetPushersJob() + : BaseJob(HttpVerb::Get, "GetPushersJob", + basePath % "/pushers") + , d(new Private) +{ +} + +GetPushersJob::~GetPushersJob() = default; + +const QVector<GetPushersJob::Pusher>& GetPushersJob::pushers() const +{ + return d->pushers; +} + +BaseJob::Status GetPushersJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + d->pushers = fromJson<QVector<Pusher>>(json.value("pushers")); + return Success; +} + +namespace QMatrixClient +{ + // Converters + + QJsonObject toJson(const PostPusherJob::PusherData& pod) + { + QJsonObject o; + o.insert("url", toJson(pod.url)); + + return o; + } +} // namespace QMatrixClient + +PostPusherJob::PostPusherJob(const QString& pushkey, const QString& kind, const QString& appId, const QString& appDisplayName, const QString& deviceDisplayName, const QString& lang, const PusherData& data, const QString& profileTag, bool append) + : BaseJob(HttpVerb::Post, "PostPusherJob", + basePath % "/pushers/set") +{ + QJsonObject _data; + _data.insert("pushkey", toJson(pushkey)); + _data.insert("kind", toJson(kind)); + _data.insert("app_id", toJson(appId)); + _data.insert("app_display_name", toJson(appDisplayName)); + _data.insert("device_display_name", toJson(deviceDisplayName)); + if (!profileTag.isEmpty()) + _data.insert("profile_tag", toJson(profileTag)); + _data.insert("lang", toJson(lang)); + _data.insert("data", toJson(data)); + _data.insert("append", toJson(append)); + setRequestData(_data); +} + |