libkazv
users.hpp
Go to the documentation of this file.
1 /******************************************************************************
2  * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
3  */
4 
5 #pragma once
6 
7 #include "basejob.hpp"
8 
9 
10 namespace Kazv::Api {
11 
26 public:
27  // Inner data structures
28 
39  struct User
40  {
42  std::string userId;
44  std::optional<std::string> displayName;
46  std::optional<std::string> avatarUrl;
47 
48  };
49 
50 
51 
52 class JobResponse : public Response
53 {
54 
55 public:
57  bool success() const;
58 
59  // Result properties
60 
61 
62 
63 
65 immer::array<User> results() const;
66 
67 
69 bool limited() const;
70 
71 };
72  static constexpr auto needsAuth() {
73  return true
74  ;
75  }
76 
77 
78 // Construction/destruction
79 
88  explicit SearchUserDirectoryJob(std::string serverUrl
89  , std::string _accessToken
90  ,
91  std::string searchTerm , std::optional<int> limit = std::nullopt
92  );
93 
94 
96  );
97 
98  static BaseJob::Body buildBody(std::string searchTerm, std::optional<int> limit);
99 
100 
101 
102 
103 
106  };
108  }
109  namespace nlohmann
110  {
111  using namespace Kazv;
112  using namespace Kazv::Api;
113  template<>
114  struct adl_serializer<SearchUserDirectoryJob::User> {
115 
116  static void to_json(json& jo, const SearchUserDirectoryJob::User &pod)
117  {
118  if (! jo.is_object()) { jo = json::object(); }
119 
120 
121  jo["user_id"s] = pod.userId;
122 
123 
124  addToJsonIfNeeded(jo, "display_name"s, pod.displayName);
125 
126  addToJsonIfNeeded(jo, "avatar_url"s, pod.avatarUrl);
127  }
128 
129  static void from_json(const json &jo, SearchUserDirectoryJob::User& result)
130  {
131 
132  if (jo.contains("user_id"s)) {
133  result.userId = jo.at("user_id"s);
134  }
135  if (jo.contains("display_name"s)) {
136  result.displayName = jo.at("display_name"s);
137  }
138  if (jo.contains("avatar_url"s)) {
139  result.avatarUrl = jo.at("avatar_url"s);
140  }
141 
142  }
143 
144 };
145  }
146 
147  namespace Kazv::Api
148  {
149 
150 } // namespace Kazv::Api
bool limited() const
Indicates if the result list has been truncated by the limit.
Definition: users.cpp:101
JobResponse(Response r)
Definition: users.cpp:75
immer::array< User > results() const
Ordered by rank and then whether or not profile info is available.
Definition: users.cpp:90
bool success() const
Definition: users.cpp:78
Searches the user directory.
Definition: users.hpp:25
static BaseJob::Query buildQuery()
Definition: users.cpp:13
SearchUserDirectoryJob(std::string serverUrl, std::string _accessToken, std::string searchTerm, std::optional< int > limit=std::nullopt)
Searches the user directory.
Definition: users.cpp:41
static constexpr auto needsAuth()
Definition: users.hpp:72
static BaseJob::Body buildBody(std::string searchTerm, std::optional< int > limit)
Definition: users.cpp:21
SearchUserDirectoryJob withData(JsonWrap j) &&
Definition: users.cpp:61
Definition: basejob.hpp:91
Definition: basejob.hpp:77
::Kazv::Body Body
Definition: basejob.hpp:100
Definition: jsonwrap.hpp:23
Definition: location.hpp:10
Definition: location.hpp:10
void addToJsonIfNeeded(json &j, std::string name, T &&arg)
Definition: types.hpp:80
nlohmann::json json
Definition: jsonwrap.hpp:20
Definition: location.hpp:27
Performs a search for users.
Definition: users.hpp:40
std::optional< std::string > avatarUrl
The avatar url, as an MXC, if one exists.
Definition: users.hpp:46
std::optional< std::string > displayName
The display name of the user, if one exists.
Definition: users.hpp:44
std::string userId
The user's matrix user ID.
Definition: users.hpp:42
Definition: basejob.hpp:50
static void to_json(json &jo, const SearchUserDirectoryJob::User &pod)
Definition: users.hpp:116
static void from_json(const json &jo, SearchUserDirectoryJob::User &result)
Definition: users.hpp:129