comunicmessages/data/apirequest.h
2018-11-28 21:33:27 +01:00

89 lines
1.9 KiB
C++

/**
* This object contains information about a single
* object.
*
* @author Pierre HUBERT
*/
#ifndef APIREQUEST_H
#define APIREQUEST_H
#include <QObject>
#include <QJsonDocument>
#include "apirequestparameter.h"
class QNetworkReply;
class APIRequest : public QObject
{
Q_OBJECT
public:
explicit APIRequest(QObject *parent = nullptr);
~APIRequest();
//Get and set URI target
QString URI() const;
void setURI(const QString &URI);
/**
* Add a string parameter to the request
*
* @param name The name of the field to add
* @param value The value of the argument to add
*/
void addString(QString name, QString value);
/**
* Add an integer parameter to the request
*
* @param name The name of the field to add
* @param value The value of the argument to add
*/
void addInt(QString name, int value);
/**
* Add a boolean parameter to the request
*
* @param name The name of the field to add
* @param value The value of the argument to add
*/
void addBool(QString name, bool value);
/**
* Get the entire list of arguments of the request
*
* @return The list of arguments
*/
QList<APIRequestParameter> arguments() const;
//Get and set network reply associated with the request
QNetworkReply *networkReply() const;
void setNetworkReply(QNetworkReply *networkReply);
signals:
/**
* Signal emitted when an error occurred
*
* @param code The code of the error
*/
void error(int code);
/**
* Signal emitted once we have got the response for our request
*
* @param document JSON Response
*/
void success(const QJsonDocument &document);
public slots:
private:
QString mURI;
QList<APIRequestParameter> mArguments;
QNetworkReply *mNetworkReply = nullptr;
};
#endif // APIREQUEST_H