lolautoaccept/include/restclient.h

55 lines
1.0 KiB
C++

#pragma once
#include <curl/curl.h>
#include <QObject>
#include <QJsonDocument>
#include <QString>
#ifdef Q_OS_WIN
#undef DELETE
#endif
class RestClient : public QObject {
Q_OBJECT
public:
RestClient(const QString& base);
RestClient(const RestClient&) = delete;
virtual ~RestClient();
enum class Method {
GET,
POST,
PUT,
PATCH,
DELETE
};
struct WebException {
CURLcode curlresponse = CURLE_OK;
WebException(CURLcode c = CURLE_OK);
};
protected:
QByteArray requestRaw(const QString& url, Method m = Method::GET, const QString& data = {});
QJsonDocument request(const QString& url, Method m = Method::GET, const QString& data = {});
void enableDebugging(bool enabled = true);
QString escape(const QString& in) const;
QString baseurl;
CURL* curl = nullptr; // the curl (does curling)
QString basicauth; // basic auth code (user:pw) or empty string to disable
#ifdef WIN32
bool disableCertCheck = true;
#else
bool disableCertCheck = false;
#endif
};
const char* toString(RestClient::Method);