lolautoaccept/include/restclient.h

44 lines
947 B
C
Raw Normal View History

2022-06-27 20:45:01 +02:00
#pragma once
#include <string>
#include <QJsonDocument>
#include <curl/curl.h>
class RestClient {
public:
RestClient(const std::string& 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,
2022-08-24 16:12:03 +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:
2022-07-02 12:36:38 +02:00
QByteArray requestRaw(const std::string& url, Method m = Method::GET, const std::string& data = {});
QJsonDocument request(const std::string& url, Method m = Method::GET, const std::string& data = {});
void enableDebugging(bool enabled = true);
2022-07-09 01:01:51 +02:00
std::string escape(const std::string& in) const;
2022-06-27 20:45:01 +02:00
std::string baseurl;
CURL* curl = nullptr; // the curl (does curling)
std::string 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
};