-
Notifications
You must be signed in to change notification settings - Fork 1
/
rest.h
111 lines (82 loc) · 2.61 KB
/
rest.h
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
#ifndef REST_HPP
#define REST_HPP
#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QUrlQuery>
#include <QUrl>
#include <QHttpMultiPart>
#include <QFile>
#include <QEventLoop>
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonArray>
#include <QByteArray>
#include <QDebug>
class Rest : public QObject
{
Q_OBJECT
Q_PROPERTY(bool estatusRespuesta READ getEstatusRespuesta WRITE setEstatusRespuesta NOTIFY cambioEstatusRespuesta)
Q_PROPERTY(QString respuesta READ getRespuesta WRITE setRespuesta NOTIFY cambioRespuesta)
Q_PROPERTY(int contador READ getContador WRITE setContador NOTIFY cambioContador)
private:
//**** ATTRIBUTES *******
QEventLoop eventos;
QNetworkAccessManager* manejadorConexion;
QNetworkRequest peticion;
QNetworkReply* respuestaBruta;
QString respuesta;
QString llave;
QUrl url;
QUrlQuery valorPeticion;
QJsonObject error;
QJsonDocument documentoJson;
QJsonObject objectoJson;
QJsonArray arregloJson;
QHttpMultiPart* multiparte;
int contador;
bool estatusRespuesta;
//***** END ATTRIBUTES *****
public:
//***** METHODS ********
explicit Rest(QObject *parent = 0);
Q_INVOKABLE void iniciar(QString url);
Q_INVOKABLE void iniciarCabecera(QString campo, QString valor);
Q_INVOKABLE void post (QByteArray data);
Q_INVOKABLE void get ();
Q_INVOKABLE void put ();
Q_INVOKABLE bool validarRespuesta();
Q_INVOKABLE void agregarAUrl(QString valor);
//***** GETERS
Q_INVOKABLE QString getMensajeError();
Q_INVOKABLE QJsonObject getObjetoJson();
Q_INVOKABLE QJsonArray getCadenaJson();
bool getEstatusRespuesta();
//***** END GETTERS
//***** SETERS
Q_INVOKABLE void setEstatusRespuesta(bool estatus);
//***** END SETTERS
~Rest();
//***** END METHODS ***********
QString getRespuesta() const;
void setRespuesta(const QString &value);
int getContador() const;
void setContador(int value);
Q_INVOKABLE QUrl getUrl() const;
Q_INVOKABLE void setUrl(const QString &value);
Q_INVOKABLE QJsonObject getError() const;
void setError(const QJsonObject &value);
Q_INVOKABLE void post();
Q_INVOKABLE void postArchivo();
Q_INVOKABLE void iniciarCabeceraString(QString campo, QString valor);
Q_INVOKABLE bool crearCabeceraMultiparte(QString url);
signals:
//void sslErrors(QNetworkReply*,QList<QSslError>);
void cambioEstatusRespuesta();
void cambioRespuesta();
void cambioContador();
public slots:
void respuestaRecibida();
};
#endif // REST_H