aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/pushrules.h
blob: 90d2ce79aeddc93545846f5f970d4b723325b1ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/******************************************************************************
 * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
 */

#pragma once

#include "csapi/definitions/push_condition.h"
#include "csapi/definitions/push_rule.h"
#include "csapi/definitions/push_ruleset.h"

#include "jobs/basejob.h"

namespace Quotient {

/*! \brief Retrieve all push rulesets.
 *
 * Retrieve all push rulesets for this user. Clients can "drill-down" on
 * the rulesets by suffixing a `scope` to this path e.g.
 * `/pushrules/global/`. This will return a subset of this data under the
 * specified key e.g. the `global` key.
 */
class GetPushRulesJob : public BaseJob {
public:
    /// Retrieve all push rulesets.
    explicit GetPushRulesJob();

    /*! \brief Construct a URL without creating a full-fledged job object
     *
     * This function can be used when a URL for GetPushRulesJob
     * is necessary but the job itself isn't.
     */
    static QUrl makeRequestUrl(QUrl baseUrl);

    // Result properties

    /// The global ruleset.
    PushRuleset global() const
    {
        return loadFromJson<PushRuleset>("global"_ls);
    }
};

/*! \brief Retrieve a push rule.
 *
 * Retrieve a single specified push rule.
 */
class GetPushRuleJob : public BaseJob {
public:
    /*! \brief Retrieve a push rule.
     *
     * \param scope
     *   `global` to specify global rules.
     *
     * \param kind
     *   The kind of rule
     *
     * \param ruleId
     *   The identifier for the rule.
     */
    explicit GetPushRuleJob(const QString& scope, const QString& kind,
                            const QString& ruleId);

    /*! \brief Construct a URL without creating a full-fledged job object
     *
     * 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);

    // Result properties

    /// The specific push rule. This will also include keys specific to the
    /// rule itself such as the rule's `actions` and `conditions` if set.
    PushRule pushRule() const
    {
        return fromJson<PushRule>(jsonData());
    }
};

/*! \brief Delete a push rule.
 *
 * This endpoint removes the push rule defined in the path.
 */
class DeletePushRuleJob : public BaseJob {
public:
    /*! \brief Delete a push rule.
     *
     * \param scope
     *   `global` to specify global rules.
     *
     * \param kind
     *   The kind of rule
     *
     * \param ruleId
     *   The identifier for the rule.
     */
    explicit DeletePushRuleJob(const QString& scope, const QString& kind,
                               const QString& ruleId);

    /*! \brief Construct a URL without creating a full-fledged job object
     *
     * 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);
};

/*! \brief Add or change a push rule.
 *
 * This endpoint allows the creation, modification and deletion of pushers
 * for this user ID. The behaviour of this endpoint varies depending on the
 * values in the JSON body.
 *
 * When creating push rules, they MUST be enabled by default.
 */
class SetPushRuleJob : public BaseJob {
public:
    /*! \brief Add or change a push rule.
     *
     * \param scope
     *   `global` to specify global rules.
     *
     * \param kind
     *   The kind of rule
     *
     * \param ruleId
     *   The identifier for the rule.
     *
     * \param actions
     *   The action(s) to perform when the conditions for this rule are met.
     *
     * \param before
     *   Use 'before' with a `rule_id` as its value to make the new rule the
     *   next-most important rule with respect to the given user defined rule.
     *   It is not possible to add a rule relative to a predefined server rule.
     *
     * \param after
     *   This makes the new rule the next-less important rule relative to the
     *   given user defined rule. It is not possible to add a rule relative
     *   to a predefined server rule.
     *
     * \param conditions
     *   The conditions that must hold true for an event in order for a
     *   rule to be applied to an event. A rule with no conditions
     *   always matches. Only applicable to `underride` and `override` rules.
     *
     * \param pattern
     *   Only applicable to `content` rules. The glob-style pattern to match
     * against.
     */
    explicit SetPushRuleJob(const QString& scope, const QString& kind,
                            const QString& ruleId,
                            const QVector<QVariant>& actions,
                            const QString& before = {},
                            const QString& after = {},
                            const QVector<PushCondition>& conditions = {},
                            const QString& pattern = {});
};

/*! \brief Get whether a push rule is enabled
 *
 * This endpoint gets whether the specified push rule is enabled.
 */
class IsPushRuleEnabledJob : public BaseJob {
public:
    /*! \brief Get whether a push rule is enabled
     *
     * \param scope
     *   Either `global` or `device/<profile_tag>` to specify global
     *   rules or device rules for the given `profile_tag`.
     *
     * \param kind
     *   The kind of rule
     *
     * \param ruleId
     *   The identifier for the rule.
     */
    explicit IsPushRuleEnabledJob(const QString& scope, const QString& kind,
                                  const QString& ruleId);

    /*! \brief Construct a URL without creating a full-fledged job object
     *
     * 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);

    // Result properties

    /// Whether the push rule is enabled or not.
    bool enabled() const
    {
        return loadFromJson<bool>("enabled"_ls);
    }
};

/*! \brief Enable or disable a push rule.
 *
 * This endpoint allows clients to enable or disable the specified push rule.
 */
class SetPushRuleEnabledJob : public BaseJob {
public:
    /*! \brief Enable or disable a push rule.
     *
     * \param scope
     *   `global` to specify global rules.
     *
     * \param kind
     *   The kind of rule
     *
     * \param ruleId
     *   The identifier for the rule.
     *
     * \param enabled
     *   Whether the push rule is enabled or not.
     */
    explicit SetPushRuleEnabledJob(const QString& scope, const QString& kind,
                                   const QString& ruleId, bool enabled);
};

/*! \brief The actions for a push rule
 *
 * This endpoint get the actions for the specified push rule.
 */
class GetPushRuleActionsJob : public BaseJob {
public:
    /*! \brief The actions for a push rule
     *
     * \param scope
     *   Either `global` or `device/<profile_tag>` to specify global
     *   rules or device rules for the given `profile_tag`.
     *
     * \param kind
     *   The kind of rule
     *
     * \param ruleId
     *   The identifier for the rule.
     */
    explicit GetPushRuleActionsJob(const QString& scope, const QString& kind,
                                   const QString& ruleId);

    /*! \brief Construct a URL without creating a full-fledged job object
     *
     * 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);

    // Result properties

    /// The action(s) to perform for this rule.
    QVector<QVariant> actions() const
    {
        return loadFromJson<QVector<QVariant>>("actions"_ls);
    }
};

/*! \brief Set the actions for a push rule.
 *
 * This endpoint allows clients to change the actions of a push rule.
 * This can be used to change the actions of builtin rules.
 */
class SetPushRuleActionsJob : public BaseJob {
public:
    /*! \brief Set the actions for a push rule.
     *
     * \param scope
     *   `global` to specify global rules.
     *
     * \param kind
     *   The kind of rule
     *
     * \param ruleId
     *   The identifier for the rule.
     *
     * \param actions
     *   The action(s) to perform for this rule.
     */
    explicit SetPushRuleActionsJob(const QString& scope, const QString& kind,
                                   const QString& ruleId,
                                   const QVector<QVariant>& actions);
};

} // namespace Quotient