-
Notifications
You must be signed in to change notification settings - Fork 0
/
postdata.cpp
76 lines (56 loc) · 1.35 KB
/
postdata.cpp
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
#include <QUrl>
#include "postdata.h"
PostData::PostData() {}
PostData::PostData(const QString &id, const QString &secret)
{
JsonObject o;
o["device"] = JsonObject();
o["device"]["id"] = id;
o["device"]["secret"] = secret;
o["client"] = JsonObject();
o["client"]["card"];
o["client"]["pin"];
o["action"] = JsonObject();
o["action"]["type"];
o["action"]["modifier"];
o["param"] = JsonObject();
setValue(o);
}
PostData::PostData(const JsonObject &object) : Json(object) {}
void PostData::setClient(const QString &card, const Json &pin)
{
PostData &self = *this;
clear();
self["client"]["card"] = card;
self["client"]["pin"] = pin;
}
void PostData::setAction(const QString &type, const Json &modifier)
{
PostData &self = *this;
clearAction();
self["action"]["type"] = type;
self["action"]["modifier"] = modifier;
}
void PostData::setParam(const QString &name, const Json &value)
{
PostData &self = *this;
self["param"][name] = value;
}
void PostData::clearAction()
{
PostData &self = *this;
self["action"]["type"].setValue();
self["action"]["modifier"].setValue();
self["param"] = JsonObject();
}
void PostData::clear()
{
PostData &self = *this;
clearAction();
self["client"]["card"].setValue();
self["client"]["pin"].setValue();
}
QByteArray PostData::content()
{
return "request=" + QUrl::toPercentEncoding(encode());
}