aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/admin.h
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2020-06-09 08:52:25 +0200
committerGitHub <noreply@github.com>2020-06-09 08:52:25 +0200
commit370d9b3e46332d38df8798cda208c534c58be808 (patch)
treef3db0cd7463468ff52c74446acd608356f8b8ab6 /lib/csapi/admin.h
parente1f5d0aa2c33e6da6c3a609c8bc7e0b5867e748d (diff)
parent10d9ac4673e374a9ac17ff492591136520337c4c (diff)
downloadlibquotient-370d9b3e46332d38df8798cda208c534c58be808.tar.gz
libquotient-370d9b3e46332d38df8798cda208c534c58be808.zip
Merge pull request #405 from quotient-im/kitsune-basejob-store-json-response
Store JSON response in BaseJob + tweaks to the generated code
Diffstat (limited to 'lib/csapi/admin.h')
-rw-r--r--lib/csapi/admin.h48
1 files changed, 32 insertions, 16 deletions
diff --git a/lib/csapi/admin.h b/lib/csapi/admin.h
index 75ae1eb0..6ad7d08d 100644
--- a/lib/csapi/admin.h
+++ b/lib/csapi/admin.h
@@ -4,17 +4,10 @@
#pragma once
-#include "converters.h"
-
#include "jobs/basejob.h"
-#include <QtCore/QHash>
-#include <QtCore/QVector>
-
namespace Quotient {
-// Operations
-
/*! \brief Gets information about a particular user.
*
* Gets information about a particular user.
@@ -66,6 +59,7 @@ public:
/*! \brief Gets information about a particular user.
*
+ *
* \param userId
* The user to look up.
*/
@@ -77,22 +71,44 @@ public:
* is necessary but the job itself isn't.
*/
static QUrl makeRequestUrl(QUrl baseUrl, const QString& userId);
- ~GetWhoIsJob() override;
// Result properties
/// The Matrix user ID of the user.
- const QString& userId() const;
+ QString userId() const { return loadFromJson<QString>("user_id"_ls); }
- /// Each key is an identitfier for one of the user's devices.
- const QHash<QString, DeviceInfo>& devices() const;
+ /// Each key is an identifier for one of the user's devices.
+ QHash<QString, DeviceInfo> devices() const
+ {
+ return loadFromJson<QHash<QString, DeviceInfo>>("devices"_ls);
+ }
+};
+
+template <>
+struct JsonObjectConverter<GetWhoIsJob::ConnectionInfo> {
+ static void fillFrom(const QJsonObject& jo,
+ GetWhoIsJob::ConnectionInfo& result)
+ {
+ fromJson(jo.value("ip"_ls), result.ip);
+ fromJson(jo.value("last_seen"_ls), result.lastSeen);
+ fromJson(jo.value("user_agent"_ls), result.userAgent);
+ }
+};
-protected:
- Status parseJson(const QJsonDocument& data) override;
+template <>
+struct JsonObjectConverter<GetWhoIsJob::SessionInfo> {
+ static void fillFrom(const QJsonObject& jo, GetWhoIsJob::SessionInfo& result)
+ {
+ fromJson(jo.value("connections"_ls), result.connections);
+ }
+};
-private:
- class Private;
- QScopedPointer<Private> d;
+template <>
+struct JsonObjectConverter<GetWhoIsJob::DeviceInfo> {
+ static void fillFrom(const QJsonObject& jo, GetWhoIsJob::DeviceInfo& result)
+ {
+ fromJson(jo.value("sessions"_ls), result.sessions);
+ }
};
} // namespace Quotient