lolautoaccept/include/restclient.h

44 lines
947 B
C++

#pragma once
#include <string>
#include <QJsonDocument>
#include <curl/curl.h>
class RestClient {
public:
RestClient(const std::string& 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 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);
std::string escape(const std::string& in) const;
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
};