lolautoaccept/include/restclient.h

55 lines
1.0 KiB
C
Raw Normal View History

2022-06-27 20:45:01 +02:00
#pragma once
#include <curl/curl.h>
#include <QObject>
#include <QJsonDocument>
#include <QString>
2023-05-04 20:13:07 +02:00
#ifdef Q_OS_WIN
#undef DELETE
#endif
class RestClient : public QObject {
Q_OBJECT
2022-06-27 20:45:01 +02:00
public:
2023-05-31 22:22:23 +02:00
RestClient(const QString& base);
2022-07-09 01:01:51 +02:00
RestClient(const RestClient&) = delete;
2022-06-27 20:45:01 +02:00
virtual ~RestClient();
2022-06-27 23:18:27 +02:00
enum class Method {
GET,
POST,
PUT,
2022-07-02 12:36:38 +02:00
PATCH,
2023-04-30 16:20:13 +02:00
DELETE
2022-06-27 23:18:27 +02:00
};
2022-07-29 00:05:22 +02:00
struct WebException {
CURLcode curlresponse = CURLE_OK;
WebException(CURLcode c = CURLE_OK);
};
2022-06-27 20:45:01 +02:00
protected:
2023-05-31 22:22:23 +02:00
QByteArray requestRaw(const QString& url, Method m = Method::GET, const QString& data = {});
QJsonDocument request(const QString& url, Method m = Method::GET, const QString& data = {});
2022-07-02 12:36:38 +02:00
void enableDebugging(bool enabled = true);
2023-05-31 22:22:23 +02:00
QString escape(const QString& in) const;
2022-06-27 20:45:01 +02:00
2023-05-31 22:22:23 +02:00
QString baseurl;
2022-06-27 20:45:01 +02:00
CURL* curl = nullptr; // the curl (does curling)
2023-05-31 22:22:23 +02:00
QString basicauth; // basic auth code (user:pw) or empty string to disable
#ifdef WIN32
bool disableCertCheck = true;
#else
bool disableCertCheck = false;
#endif
2022-06-27 20:45:01 +02:00
};
2023-06-12 20:19:37 +02:00
const char* toString(RestClient::Method);